diff options
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); } } |