diff options
Diffstat (limited to 'dslog')
-rw-r--r-- | dslog/Logdir.java | 77 | ||||
-rw-r--r-- | dslog/Main.java | 63 |
2 files changed, 78 insertions, 62 deletions
diff --git a/dslog/Logdir.java b/dslog/Logdir.java new file mode 100644 index 0000000..90661bb --- /dev/null +++ b/dslog/Logdir.java @@ -0,0 +1,77 @@ +package dslog; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.SortedMap; +import java.util.Map; +import java.util.TreeMap; + +class Logdir { + public static class LogSet { + public String name; + public String dslog = "␕"; + public String dsevents = "␕"; + public String pdplog = "␕"; + + public String toString() { + return name+" "+dslog+"/"+dsevents+"/"+pdplog; + } + } + + private static LogSet getSet(Map<String, LogSet> sets, String name) { + LogSet set; + synchronized (sets) { + set = sets.get(name); + if (set == null) { + set = new LogSet(); + set.name = name; + sets.put(name, set); + } + } + return set; + } + public static SortedMap<String, LogSet> opendir(String dirname) throws IOException { + SortedMap<String, LogSet> logsets = new TreeMap<String, LogSet>(); + List<Exception> errs = new ArrayList<Exception>(); + Files.list(Paths.get(dirname)).parallel().forEach(filepath->{ + try { + String filename = filepath.getFileName().toString(); + if (filename.endsWith(".dslog")) { + String setname = filename.substring(0, filename.lastIndexOf('.')); + try (DslogReader dslog = new DslogReader(Files.newInputStream(filepath))) { + getSet(logsets, setname).dslog = ""+dslog.version; + } catch (Exception e) { + getSet(logsets, setname).pdplog = "☠"; + throw e; + } + } else if (filename.endsWith(".dsevents")) { + String setname = filename.substring(0, filename.lastIndexOf('.')); + try (DseventsReader dsevents = new DseventsReader(Files.newInputStream(filepath))) { + getSet(logsets, setname).dsevents = ""+dsevents.version; + } catch (Exception e) { + getSet(logsets, setname).pdplog = "☠"; + throw e; + } + } else if (filename.endsWith(".pdplog")) { + String setname = filename.substring(0, filename.lastIndexOf('.')); + try (PdplogReader pdplog = new PdplogReader(Files.newInputStream(filepath))) { + getSet(logsets, setname).pdplog = ""+pdplog.version; + } catch (Exception e) { + getSet(logsets, setname).pdplog = "☠"; + throw e; + } + } + } catch (Exception e) { + e = new IOException("Could not read file: "+filepath.toString(), e); + synchronized (errs) { + errs.add(e); + } + e.printStackTrace(); + } + }); + return logsets; + } +} diff --git a/dslog/Main.java b/dslog/Main.java index b6c6a01..0c95c50 100644 --- a/dslog/Main.java +++ b/dslog/Main.java @@ -20,71 +20,10 @@ class Main { } } - public static class LogSet { - public String name; - public String dslog = "␕"; - public String dsevents = "␕"; - public String pdplog = "␕"; - - public String toString() { - return name+" "+dslog+"/"+dsevents+"/"+pdplog; - } - } - - private static LogSet getSet(Map<String, LogSet> sets, String name) { - LogSet set; - synchronized (sets) { - set = sets.get(name); - if (set == null) { - set = new LogSet(); - set.name = name; - sets.put(name, set); - } - } - return set; - } public static void main(String[] args) throws IOException { for (String dirname : args) { - SortedMap<String, LogSet> logsets = new TreeMap<String, LogSet>(); - List<Exception> errs = new ArrayList<Exception>(); - Files.list(Paths.get(dirname)).parallel().forEach(filepath->{ - try { - String filename = filepath.getFileName().toString(); - if (filename.endsWith(".dslog")) { - String setname = filename.substring(0, filename.lastIndexOf('.')); - try (DslogReader dslog = new DslogReader(Files.newInputStream(filepath))) { - getSet(logsets, setname).dslog = ""+dslog.version; - } catch (Exception e) { - getSet(logsets, setname).pdplog = "☠"; - throw e; - } - } else if (filename.endsWith(".dsevents")) { - String setname = filename.substring(0, filename.lastIndexOf('.')); - try (DseventsReader dsevents = new DseventsReader(Files.newInputStream(filepath))) { - getSet(logsets, setname).dsevents = ""+dsevents.version; - } catch (Exception e) { - getSet(logsets, setname).pdplog = "☠"; - throw e; - } - } else if (filename.endsWith(".pdplog")) { - String setname = filename.substring(0, filename.lastIndexOf('.')); - try (PdplogReader pdplog = new PdplogReader(Files.newInputStream(filepath))) { - getSet(logsets, setname).pdplog = ""+pdplog.version; - } catch (Exception e) { - getSet(logsets, setname).pdplog = "☠"; - throw e; - } - } - } catch (Exception e) { - e = new IOException("Could not read file: "+filepath.toString(), e); - synchronized (errs) { - errs.add(e); - } - e.printStackTrace(); - } - }); - logsets.forEach((k,v)->{ + Logdir.opendir(dirname).forEach((k,v)->{ System.out.println(v); }); } |