package dslog; import java.io.BufferedInputStream; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; class PdplogReader implements Closeable { /*============================================================*\ || Primitive IO || \*============================================================*/ private final InputStream reader; public PdplogReader(InputStream reader) throws IOException { if (!reader.markSupported()) { reader = new BufferedInputStream(reader); } this.reader = reader; } 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 UnsupportedVersionException("PDPLOG (TODO)", 0); case 1: // ????-2015 throw new UnsupportedVersionException("PDPLOG (TODO)", 1); default: throw new UnsupportedVersionException("PDPLOG", version(), 1); } } public void close() throws IOException { reader.close(); } }