diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-03-12 04:05:42 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-03-12 04:05:42 -0400 |
commit | a6db0254bf9bc3f4ed1058c20cf294b66d455be4 (patch) | |
tree | dbdd79b3cf4b1fa9ab315b93a8f353d38bcfe92f /dslog/DseventsReader.java |
initial commit
Diffstat (limited to 'dslog/DseventsReader.java')
-rw-r--r-- | dslog/DseventsReader.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/dslog/DseventsReader.java b/dslog/DseventsReader.java new file mode 100644 index 0000000..c3c7dc5 --- /dev/null +++ b/dslog/DseventsReader.java @@ -0,0 +1,56 @@ +package dslog; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.UnsupportedOperationException; +import java.time.Duration; +import java.time.Instant; +import java.util.stream.IntStream; + +class DseventsReader { + 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("DSEVENTS version 0 not implemented yet"); + 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("DSEVENTS version 0 not implemented yet"); + 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(); + } +} |