jwo.utils.gifutils
Class BitInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byjwo.utils.gifutils.BitInputStream
Direct Known Subclasses:
GIFInputStream

public class BitInputStream
extends FilterInputStream

Allows the reading of 1 to 32 bits at a time, on any bit boundary. Bits are read from bytes, least significant bit first.

Version:
2.2, 22nd August, 1998, modified 10th April, 2002.
Author:
Benjamin E. Norman, Minor modificiations, Jo Wood.

Field Summary
protected  long cachedBits
          Any cached bits which have been read in from the underlying stream but not yet returned to the user
protected  int numCachedBits
          Number of valid bits in 'cachedBits'.
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
BitInputStream(InputStream is)
          Create a BitInputStream, assuming that at least 5 bytes are avaliable on the underlying stream.
 
Method Summary
 int read()
          Reads a byte at the current bit boundary.
 int readBit()
          Reads the next bit from the underlying input stream.
 int readBits(int numBits)
          Reads the given number of bits (1 to 32) from the underlying input stream.
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cachedBits

protected long cachedBits
Any cached bits which have been read in from the underlying stream but not yet returned to the user


numCachedBits

protected int numCachedBits
Number of valid bits in 'cachedBits'. This should always be >= 32 for efficiency, unless EOF has been reached

Constructor Detail

BitInputStream

public BitInputStream(InputStream is)
Create a BitInputStream, assuming that at least 5 bytes are avaliable on the underlying stream.

Method Detail

read

public int read()
         throws IOException
Reads a byte at the current bit boundary.

Returns:
The byte that has been read or -1 if 8 bits are not available before EOF is reached.
Throws:
IOException

readBits

public int readBits(int numBits)
             throws IOException
Reads the given number of bits (1 to 32) from the underlying input stream.

Returns:
Data read from input stream.
Throws:
EOFException - if the given number of bits are not available before EOF.
IOException

readBit

public int readBit()
            throws IOException
Reads the next bit from the underlying input stream.

Returns:
The read data or -1 on EOF.
Throws:
IOException


Copyright Jo Wood, 1996-2005, last modified, 11th March, 2005