org.blinkenbyte.io
Class ByteArrayBuffer.ByteArrayBufferInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.blinkenbyte.io.ByteArrayBuffer.ByteArrayBufferInputStream
All Implemented Interfaces:
java.io.Closeable
Enclosing class:
ByteArrayBuffer

public static class ByteArrayBuffer.ByteArrayBufferInputStream
extends java.io.InputStream

Class that can extends InputStream and can read directly from the internal buffers of the host ByteArrayBuffer. This prevents unnecessary duplication of data, and a way of using the buffer as a device that can be read and written from.


Field Summary
protected  ByteArrayBuffer bab
          The ByteArrayBufffer this InputStream reads from.
protected  int markPtr
          The mark pointer.
protected  int markReadLimit
          The mark read limit.
protected  int readPtr
          The read pointer used by this input stream.
protected  boolean sharedPointer
          Whether this input stream should share a pointer with the host ByteArrayBuffer.
protected  int SUB_BUFFER_LOG
          Copy of SUB_BUFFER_LOG from the host ByteArrayBuffer.
protected  int SUB_BUFFER_MASK
          Copy of SUB_BUFFER_MASK from the host ByteArrayBuffer.
protected  int SUB_BUFFER_SIZE
          Copy of SUB_BUFFER_SIZE from the host ByteArrayBuffer.
 
Constructor Summary
ByteArrayBuffer.ByteArrayBufferInputStream(ByteArrayBuffer _bab)
          Constructs a new ByteArrayBufferInputStream from an existing ByteArrayBuffer
ByteArrayBuffer.ByteArrayBufferInputStream(ByteArrayBuffer _bab, boolean _sharedPointer)
          Constructs a new ByteArrayBufferInputStream from an existing ByteArrayBuffer and specifies whether they should share a read/write pointer.
 
Method Summary
 int available()
          Returns the number of bytes available to be read.
 void close()
          Closes this stream (nulls the reference to the ByteArrayBuffer).
 void mark(int readLimit)
          Sets the limit for mark().
 boolean markSupported()
          Returns true.
 int read()
          Reads a single byte.
 int read(byte[] b)
          Reads up to b.length bytes into b.
 int read(byte[] b, int offset, int len)
          Reads up to offset bytes into array b starting at b[offset].
 void reset()
          Resets the read pointer back to the mark.
 int seek(int newReadPtr)
          Seeks the pointer to newReadPtr.
 long skip(long n)
          Advances the pointer n bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bab

protected ByteArrayBuffer bab
The ByteArrayBufffer this InputStream reads from.


readPtr

protected int readPtr
The read pointer used by this input stream.


markPtr

protected int markPtr
The mark pointer.


markReadLimit

protected int markReadLimit
The mark read limit.


SUB_BUFFER_LOG

protected int SUB_BUFFER_LOG
Copy of SUB_BUFFER_LOG from the host ByteArrayBuffer.


SUB_BUFFER_SIZE

protected int SUB_BUFFER_SIZE
Copy of SUB_BUFFER_SIZE from the host ByteArrayBuffer.


SUB_BUFFER_MASK

protected int SUB_BUFFER_MASK
Copy of SUB_BUFFER_MASK from the host ByteArrayBuffer.


sharedPointer

protected boolean sharedPointer
Whether this input stream should share a pointer with the host ByteArrayBuffer.

Constructor Detail

ByteArrayBuffer.ByteArrayBufferInputStream

public ByteArrayBuffer.ByteArrayBufferInputStream(ByteArrayBuffer _bab)
Constructs a new ByteArrayBufferInputStream from an existing ByteArrayBuffer


ByteArrayBuffer.ByteArrayBufferInputStream

public ByteArrayBuffer.ByteArrayBufferInputStream(ByteArrayBuffer _bab,
                                                  boolean _sharedPointer)
Constructs a new ByteArrayBufferInputStream from an existing ByteArrayBuffer and specifies whether they should share a read/write pointer.

Method Detail

available

public int available()
Returns the number of bytes available to be read.

Overrides:
available in class java.io.InputStream

close

public void close()
Closes this stream (nulls the reference to the ByteArrayBuffer).

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream

mark

public void mark(int readLimit)
Sets the limit for mark().

Overrides:
mark in class java.io.InputStream

markSupported

public boolean markSupported()
Returns true.

Overrides:
markSupported in class java.io.InputStream

read

public int read()
Reads a single byte.

Specified by:
read in class java.io.InputStream

read

public int read(byte[] b)
Reads up to b.length bytes into b.

Overrides:
read in class java.io.InputStream

read

public int read(byte[] b,
                int offset,
                int len)
Reads up to offset bytes into array b starting at b[offset].

Overrides:
read in class java.io.InputStream

reset

public void reset()
           throws java.io.IOException
Resets the read pointer back to the mark. If no mark has been set or too many bytes have been read since the mark, an IOException is thrown.

Overrides:
reset in class java.io.InputStream
Throws:
java.io.IOException

skip

public long skip(long n)
Advances the pointer n bytes.

Overrides:
skip in class java.io.InputStream

seek

public int seek(int newReadPtr)
Seeks the pointer to newReadPtr.