summaryrefslogtreecommitdiff
path: root/dslog/Main.java
blob: b6c6a0199d4c483991967a1d9fb124b03a22f940 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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 Main {
	public static void dslog2csv(String[] args) throws IOException {
		for (String filename : args) {
			System.out.println("Filename: "+filename);
			DslogReader file = new DslogReader(Files.newInputStream(Paths.get(filename)));
			System.out.println("Format Version: "+file.version);
			System.out.println("Start Time: "+file.startTime);
			CsvWriter.Dslog2CSV(file, System.out);
		}
	}

	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)->{
				System.out.println(v);
			});
		}
	}
}