uk.me.parabola.io
Class StructuredInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by uk.me.parabola.io.StructuredInputStream
All Implemented Interfaces:
java.io.Closeable

public class StructuredInputStream
extends java.io.InputStream

An input stream used to make reading little endian integers and strings from the tdb file.

Author:
Steve Ratcliffe

Constructor Summary
StructuredInputStream(java.io.InputStream in)
           
 
Method Summary
 int read()
          Implementation of read that delegates to the underlying stream.
 int read2()
          Read a 2 byte little endian integer.
 int read4()
          Read a 4 byte integer quantity.
 java.lang.String readString()
          Read a nul terminated string from the input stream.
 boolean testEof()
          Test if we are at the end of the file by marking the position and trying to read the next byte.
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StructuredInputStream

public StructuredInputStream(java.io.InputStream in)
Method Detail

read

public int read()
         throws java.io.IOException
Implementation of read that delegates to the underlying stream. It however also keeps track of the end of file status.

Specified by:
read in class java.io.InputStream
Returns:
The next byte, or -1 on eof.
Throws:
java.io.IOException - For problems reading.

read2

public int read2()
          throws java.io.IOException
Read a 2 byte little endian integer.

Returns:
The integer.
Throws:
java.io.IOException - If the stream could not be read.

read4

public int read4()
          throws java.io.IOException
Read a 4 byte integer quantity. As always this is little endian.

Returns:
The integer.
Throws:
java.io.IOException - If the stream could not be read.

readString

public java.lang.String readString()
                            throws java.io.IOException
Read a nul terminated string from the input stream.

Returns:
A string, without the null terminator.
Throws:
java.io.IOException - If the stream cannot be read.

testEof

public boolean testEof()
Test if we are at the end of the file by marking the position and trying to read the next byte. If not at the end then the stream position is reset and all is as before.

Returns:
True if we are at the end of the stream.