jj2000.j2k.codestream.reader
Class PktHeaderBitReader

java.lang.Object
  |
  +--jj2000.j2k.codestream.reader.PktHeaderBitReader

class PktHeaderBitReader
extends java.lang.Object

This class provides a bit based reading facility from a byte based one, applying the bit unstuffing procedure as required by the packet headers.


Field Summary
(package private)  java.io.ByteArrayInputStream bais
          The byte array that is the source of data if the PktHeaderBitReader is instantiated with a buffer instead of a RandomAccessIO
(package private)  int bbuf
          The current bit buffer
(package private)  int bpos
          The position of the next bit to read in the bit buffer (0 means empty, 8 full)
(package private)  RandomAccessIO in
          The byte based source of data
(package private)  int nextbbuf
          The next bit buffer, if bit stuffing occurred (i.e.
(package private)  boolean usebais
          Flag indicating whether the data should be read from the buffer
 
Constructor Summary
(package private) PktHeaderBitReader(java.io.ByteArrayInputStream bais)
          Instantiates a 'PktHeaderBitReader' that gets the byte data from the given source.
(package private) PktHeaderBitReader(RandomAccessIO in)
          Instantiates a 'PktHeaderBitReader' that gets the byte data from the given source.
 
Method Summary
(package private)  int readBit()
          Reads a single bit from the input.
(package private)  int readBits(int n)
          Reads a specified number of bits and returns them in a single integer.
(package private)  void setInput(java.io.ByteArrayInputStream bais)
          Sets the underlying byte based input to the given object.
(package private)  void setInput(RandomAccessIO in)
          Sets the underlying byte based input to the given object.
(package private)  void sync()
          Synchronizes this object with the underlying byte based input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

RandomAccessIO in
The byte based source of data


bais

java.io.ByteArrayInputStream bais
The byte array that is the source of data if the PktHeaderBitReader is instantiated with a buffer instead of a RandomAccessIO


usebais

boolean usebais
Flag indicating whether the data should be read from the buffer


bbuf

int bbuf
The current bit buffer


bpos

int bpos
The position of the next bit to read in the bit buffer (0 means empty, 8 full)


nextbbuf

int nextbbuf
The next bit buffer, if bit stuffing occurred (i.e. current bit buffer holds 0xFF)

Constructor Detail

PktHeaderBitReader

PktHeaderBitReader(RandomAccessIO in)
Instantiates a 'PktHeaderBitReader' that gets the byte data from the given source.

Parameters:
in - The source of byte data

PktHeaderBitReader

PktHeaderBitReader(java.io.ByteArrayInputStream bais)
Instantiates a 'PktHeaderBitReader' that gets the byte data from the given source.

Parameters:
bais - The source of byte data
Method Detail

readBit

final int readBit()
           throws java.io.IOException
Reads a single bit from the input.

Returns:
The read bit (0 or 1)
Throws:
java.io.IOException - If an I/O error occurred
java.io.EOFException - If teh end of file has been reached

readBits

final int readBits(int n)
            throws java.io.IOException
Reads a specified number of bits and returns them in a single integer. The bits are returned in the 'n' least significant bits of the returned integer. The maximum number of bits that can be read is 31.

Parameters:
n - The number of bits to read
Returns:
The read bits, packed in the 'n' LSBs.
Throws:
java.io.IOException - If an I/O error occurred
java.io.EOFException - If teh end of file has been reached

sync

void sync()
Synchronizes this object with the underlying byte based input. It discards and buffered bits and gets ready to read bits from the current position in the underlying byte based input.

This method should always be called when some data has been read directly from the underlying byte based input since the last call to 'readBits()' or 'readBit()' before a new call to any of those methods.


setInput

void setInput(RandomAccessIO in)
Sets the underlying byte based input to the given object. This method discards any currently buffered bits and gets ready to start reading bits from 'in'.

This method is equivalent to creating a new 'PktHeaderBitReader' object.

Parameters:
in - The source of byte data

setInput

void setInput(java.io.ByteArrayInputStream bais)
Sets the underlying byte based input to the given object. This method discards any currently buffered bits and gets ready to start reading bits from 'in'.

This method is equivalent to creating a new 'PktHeaderBitReader' object.

Parameters:
bais - The source of byte data