summaryrefslogtreecommitdiff
path: root/dslog/DseventsReader.java
blob: 1f7afa7128d8b88f089a4d60465cd94727a44db7 (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
package dslog;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.lang.UnsupportedOperationException;
import java.time.Instant;

class DseventsReader implements Closeable {
	private final InputStream reader;

	public final int version;
	public final Instant startTime;

	public DseventsReader(InputStream reader) throws IOException {
		this.reader = reader;
		this.version = Read.i32(reader);
		switch (this.version) {
		case 0:
			throw new UnsupportedOperationException("TODO: DSEVENTS v0 support");
		case 1:
		case 2:
		case 3: // 2016-now
			this.startTime = Read.LVTimestamp(reader);
			break;
		default:
			throw new UnsupportedOperationException("DSEVENTS file version ("+this.version+") newer than log reader (3)");
		}
	}

	public static class Event {
		public Instant time;
		public String message;
	}

	public Event readEvent() throws IOException{
		switch (version) {
		case 0:
			throw new UnsupportedOperationException("TODO: DSEVENTS v0 support");
		case 1:
		case 2:
		case 3:
			return new Event() {{
				time = Read.LVTimestamp(reader);
				message = Read.LVString(reader);
			}};
		default:
			throw new UnsupportedOperationException("DSEVENTS file version newer than log reader");
		}
	}

	public void close() throws IOException {
		reader.close();
	}
}