com.vwp.io
Class ByteArrayReader

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

public class ByteArrayReader
extends 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)
           
 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 IOException
Read a single byteacter.

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

readLine

public String readLine()
                throws IOException
Reads all bytes until the next \n

Throws:
IOException - If an I/O error occurs

read

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

read

public int read(byte[] b,
                int off,
                int len)
         throws 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:
IOException - If an I/O error occurs

skip

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

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

ready

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

Overrides:
ready in class Reader
Throws:
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 Reader

mark

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

Overrides:
mark in class 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:
IOException - If an I/O error occurs

reset

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

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

close

public void close()
Close the stream.

Specified by:
close in interface Closeable
Specified by:
close in class Reader