org.jwall.web.audit.io
Class BinaryReader

java.lang.Object
  extended by org.jwall.web.audit.io.BinaryReader

public class BinaryReader
extends java.lang.Object

A reader which reads bytes from an input-stream and also supports reading a whole line returned as string.
NOTE: This class might not be portable!

Author:
Christian Bockermann <chris@jwall.org>

Constructor Summary
BinaryReader(java.io.InputStream in)
          This method creates a new instance of the BinaryReader class that is connected to the given InputStream.
BinaryReader(java.io.InputStream in, java.io.OutputStream out)
          This creates a BinaryReader which simultanously writes the input to the given output-stream.
 
Method Summary
 void close()
          Closes the underlying input-stream and marks this reader as closed.
 long getPosision()
          This method returns the offset from the beginning of the stream.
 boolean isClosed()
          Wether this reader has been closed or not.
 byte[] readByteLine()
          Returns an array of bytes from the current position of the read-head to the next occurence of a LF-byte, but at most 8192 bytes.
 byte[] readBytes(int k)
          This method reads k bytes from the input stream an returns them as an array.
 java.lang.String readline()
          This reads bytes of the stream until a newline (0x13) is reached.
 boolean ready()
          The reader is ready if it is not closed and data is available from the underlying input-stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryReader

public BinaryReader(java.io.InputStream in)
This method creates a new instance of the BinaryReader class that is connected to the given InputStream.

Parameters:
in - The input stream that is to be read from.

BinaryReader

public BinaryReader(java.io.InputStream in,
                    java.io.OutputStream out)
This creates a BinaryReader which simultanously writes the input to the given output-stream. It is inteded to debug binary-streams.

Method Detail

readline

public java.lang.String readline()
                          throws java.io.IOException
This reads bytes of the stream until a newline (0x13) is reached. A string presenting these bytes is returned.

Returns:
The next string, read from the underlying stream, including the newline.
Throws:
java.io.IOException

readByteLine

public byte[] readByteLine()
                    throws java.io.IOException
Returns an array of bytes from the current position of the read-head to the next occurence of a LF-byte, but at most 8192 bytes. This method also advances the read-head.

Returns:
An array of bytes.
Throws:
java.io.IOException

readBytes

public byte[] readBytes(int k)
                 throws java.io.IOException
This method reads k bytes from the input stream an returns them as an array.

Parameters:
k - The number of bytes to read.
Returns:
An array of size k, holding bytes.
Throws:
java.io.IOException

ready

public boolean ready()
              throws java.io.IOException
The reader is ready if it is not closed and data is available from the underlying input-stream.

Returns:
true, if the reader is not closed and data is available.
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes the underlying input-stream and marks this reader as closed.

Throws:
java.io.IOException

isClosed

public boolean isClosed()
Wether this reader has been closed or not.

Returns:
true, if the reader has been closed.

getPosision

public long getPosision()
This method returns the offset from the beginning of the stream.

Returns:
The offset from the beginning of the stream.