diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-03-13 18:16:25 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-03-13 18:16:25 -0400 |
commit | 2c9c848ae275705ce315b6061cd06640834c9d9d (patch) | |
tree | c2a0a1b1a45fe1e88cbfc2fafd1ba01ededcb987 /dslog/PdplogReader.java | |
parent | cf1ea6c1a28ec7bc4cc7b8cd0da8ad5f1011ac7c (diff) |
lazy-parse the version and startTime
Diffstat (limited to 'dslog/PdplogReader.java')
-rw-r--r-- | dslog/PdplogReader.java | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/dslog/PdplogReader.java b/dslog/PdplogReader.java index 3df9c2b..2618101 100644 --- a/dslog/PdplogReader.java +++ b/dslog/PdplogReader.java @@ -1,25 +1,54 @@ package dslog; +import java.io.BufferedInputStream; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; -import java.lang.UnsupportedOperationException; class PdplogReader implements Closeable { - private final InputStream reader; - public final int version; + /*============================================================*\ + || Primitive IO || + \*============================================================*/ + private final InputStream reader; public PdplogReader(InputStream reader) throws IOException { + if (!reader.markSupported()) { + reader = new BufferedInputStream(reader); + } this.reader = reader; - this.version = Read.i32(reader); - switch (this.version) { + } + + private boolean atEOF() throws IOException { + reader.mark(2); + boolean eof = (reader.read() < 0); + reader.reset(); + return eof; + } + + + /*============================================================* \ + || Parsing || + \*============================================================*/ + + private int m_version; + private boolean m_haveVersion = false; + public int version() throws IOException { + if (!m_haveVersion) { + m_version = Read.i32(reader); + m_haveVersion = true; + } + return m_version; + } + + public void read() throws IOException { + switch (version()) { case 0: // ????-???? - throw new UnsupportedOperationException("TODO: PDPLOG v0 support"); + throw new UnsupportedVersionException("PDPLOG (TODO)", 0); case 1: // ????-2015 - throw new UnsupportedOperationException("TODO: PDPLOG v1 support"); + throw new UnsupportedVersionException("PDPLOG (TODO)", 1); default: - throw new UnsupportedOperationException("Unrecognized PDPLOG version: "+this.version); + throw new UnsupportedVersionException("PDPLOG", version(), 1); } } |