com.vwp.io
Class ByteArrayReader

java.lang.Object
  extended by java.io.Reader
      extended by com.vwp.io.ByteArrayReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable

public class ByteArrayReader
extends java.io.Reader


Constructor Summary
ByteArrayReader(byte[] buf)
          Create an ByteArrayReader from the specified array of bytes.
ByteArrayReader(byte[] buf, int offset, int length)
          Create an ByteArrayReader from the specified array of bytes.
 
Method Summary
 void close()
          Close the stream.
 void mark(int readAheadLimit)
          Mark the present position in the stream.
 boolean markSupported()
          Tell whether this stream supports the mark() operation, which it does.
 int read()
          Read a single byteacter.
 int read(byte[] b, int off, int len)
          Read byteacters into a portion of an array.
 int read(char[] b, int off, int len)
           
 java.lang.String readLine()
          Reads all bytes until the next \n
 boolean ready()
          Tell whether this stream is ready to be read.
 void reset()
          Reset the stream to the most recent mark, or to the beginning if it has never been marked.
 long skip(long n)
          Skip bytes.
 
Methods inherited from class java.io.Reader
read, read
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArrayReader

public ByteArrayReader(byte[] buf)
Create an ByteArrayReader from the specified array of bytes.

Parameters:
buf - Input buffer (not copied)

ByteArrayReader

public ByteArrayReader(byte[] buf,
                       int offset,
                       int length)
Create an ByteArrayReader from the specified array of bytes.

Parameters:
buf - Input buffer (not copied)
offset - Offset of the first byte to read
length - Number of bytes to read
Method Detail

read

public int read()
         throws java.io.IOException
Read a single byteacter.

Overrides:
read in class java.io.Reader
Throws:
java.io.IOException - If an I/O error occurs

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Reads all bytes until the next \n

Throws:
java.io.IOException - If an I/O error occurs

read

public int read(char[] b,
                int off,
                int len)
Specified by:
read in class java.io.Reader

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Read byteacters into a portion of an array.

Parameters:
b - Destination buffer
off - Offset at which to start storing byteacters
len - Maximum number of byteacters to read
Returns:
The actual number of byteacters read, or -1 if the end of the stream has been reached
Throws:
java.io.IOException - If an I/O error occurs

skip

public long skip(long n)
          throws java.io.IOException
Skip bytes.

Overrides:
skip in class java.io.Reader
Parameters:
n - The number of byteacters to skip
Returns:
The number of byteacters actually skipped
Throws:
java.io.IOException - If an I/O error occurs

ready

public boolean ready()
              throws java.io.IOException
Tell whether this stream is ready to be read. Bytearray readers are always ready to be read.

Overrides:
ready in class java.io.Reader
Throws:
java.io.IOException - If an I/O error occurs

markSupported

public boolean markSupported()
Tell whether this stream supports the mark() operation, which it does.

Overrides:
markSupported in class java.io.Reader

mark

public void mark(int readAheadLimit)
          throws java.io.IOException
Mark the present position in the stream. Subsequent calls to reset() will reposition the stream to this point.

Overrides:
mark in class java.io.Reader
Parameters:
readAheadLimit - Limit on the number of byteacters that may be read while still preserving the mark. Because the stream's input comes from a bytearray, there is no actual limit and this argument is ignored.
Throws:
java.io.IOException - If an I/O error occurs

reset

public void reset()
           throws java.io.IOException
Reset the stream to the most recent mark, or to the beginning if it has never been marked.

Overrides:
reset in class java.io.Reader
Throws:
java.io.IOException - If an I/O error occurs

close

public void close()
Close the stream.

Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Reader