summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-03-13 12:58:54 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-03-13 12:58:54 -0400
commitcf1ea6c1a28ec7bc4cc7b8cd0da8ad5f1011ac7c (patch)
treed98a3692ed9d88bb976699ddda2afdde44cef84e
parent36d2be6a79d9ed63f6a1e834d2e733ad2b2a6ddd (diff)
split
-rw-r--r--dslog/Logdir.java77
-rw-r--r--dslog/Main.java63
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);
});
}