jj2000.j2k.entropy.decoder
Class ByteInputBuffer

java.lang.Object
  |
  +--jj2000.j2k.entropy.decoder.ByteInputBuffer

public class ByteInputBuffer
extends java.lang.Object

This class provides a byte input facility from byte buffers. It is similar to the ByteArrayInputStream class, but adds the possibility to add data to the stream after the creation of the object.

Unlike the ByteArrayInputStream this class is not thread safe (i.e. no two threads can use the same object at the same time, but different objects may be used in different threads).

This class can modify the contents of the buffer given to the constructor, when the addByteArray() method is called.

See Also:
InputStream

Field Summary
private  byte[] buf
          The byte array containing the data
private  int count
          The index one greater than the last valid character in the input stream buffer
private  int pos
          The index of the next character to read from the input stream buffer
 
Constructor Summary
ByteInputBuffer(byte[] buf)
          Creates a new byte array input stream that reads data from the specified byte array.
ByteInputBuffer(byte[] buf, int offset, int length)
          Creates a new byte array input stream that reads data from the specified byte array.
 
Method Summary
 void addByteArray(byte[] data, int off, int len)
          Adds the specified data to the end of the byte array stream.
 int read()
          Reads the next byte of data from this input stream.
 int readChecked()
          Reads the next byte of data from this input stream.
 void setByteArray(byte[] buf, int offset, int length)
          Sets the underlying buffer byte array to the given one, with the given offset and length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

private byte[] buf
The byte array containing the data


count

private int count
The index one greater than the last valid character in the input stream buffer


pos

private int pos
The index of the next character to read from the input stream buffer

Constructor Detail

ByteInputBuffer

public ByteInputBuffer(byte[] buf)
Creates a new byte array input stream that reads data from the specified byte array. The byte array is not copied.

Parameters:
buf - the input buffer.

ByteInputBuffer

public ByteInputBuffer(byte[] buf,
                       int offset,
                       int length)
Creates a new byte array input stream that reads data from the specified byte array. Up to length characters are to be read from the byte array, starting at the indicated offset.

The byte array is not copied.

Parameters:
buf - the input buffer.
offset - the offset in the buffer of the first byte to read.
length - the maximum number of bytes to read from the buffer.
Method Detail

setByteArray

public void setByteArray(byte[] buf,
                         int offset,
                         int length)
Sets the underlying buffer byte array to the given one, with the given offset and length. If 'buf' is null then the current byte buffer is assumed. If 'offset' is negative, then it will be assumed to be 'off+len', where 'off' and 'len' are the offset and length of the current byte buffer.

The byte array is not copied.

Parameters:
buf - the input buffer. If null it is the current input buffer.
offset - the offset in the buffer of the first byte to read. If negative it is assumed to be the byte just after the end of the current input buffer, only permitted if 'buf' is null.
length - the maximum number of bytes to read frmo the buffer.

addByteArray

public void addByteArray(byte[] data,
                         int off,
                         int len)
Adds the specified data to the end of the byte array stream. This method modifies the byte array buffer. It can also discard the already read input.

Parameters:
data - The data to add. The data is copied.
off - The index, in data, of the first element to add to the stream.
len - The number of elements to add to the array.

readChecked

public int readChecked()
                throws java.io.IOException
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the EOFException exception is thrown.

This method is not synchronized, so it is not thread safe.

Returns:
The byte read in the range 0-255.
Throws:
java.io.EOFException - If the end of the stream is reached.
java.io.IOException

read

public int read()
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, -1 is returned.

This method is not synchronized, so it is not thread safe.

Returns:
The byte read in the range 0-255, or -1 if the end of stream has been reached.