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

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

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
          the 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()
          Read a byte at the current bit boundary.
 int readBit()
          Read the next bit from the underlying input stream.
 int readBits(int numBits)
          Read 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
the 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
Read a byte at the current bit boundary. Returns -1 if 8 bits are not available before EOF is reached.

Throws:
IOException

readBits

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

Throws:
EOFException - if the given number of bits are not available before EOF.
IOException

readBit

public int readBit()
            throws IOException
Read the next bit from the underlying input stream. Returns -1 on EOF.

Throws:
IOException


Copyright Jo Wood, 1996-2004, last modified, 3rd September, 2004