jwo.utils.gifutils
Class BitOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.FilterOutputStream
          extended byjwo.utils.gifutils.BitOutputStream
Direct Known Subclasses:
GIFOutputStream

public class BitOutputStream
extends FilterOutputStream

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

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

Field Summary
protected  int cachedBits
          any cached bits which need to be written to the underlying stream
protected  int numCachedBits
          the number of valid bits in 'cachedBits'.
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
BitOutputStream(OutputStream os)
           
 
Method Summary
 void flush()
          Flush any cached bits and bytes.
 void write(int byteValue)
          Write a byte at the current bit boundary.
 void writeBit(int bit)
          Write a single bit (1 or 0) to the underlying output stream.
 void writeBits(int value, int numBits)
          Write the given number of bits (1 to 32) from the given value to the underlying output stream.
 
Methods inherited from class java.io.FilterOutputStream
close, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cachedBits

protected int cachedBits
any cached bits which need to be written to the underlying stream


numCachedBits

protected int numCachedBits
the number of valid bits in 'cachedBits'. This is never > 7; only parital bytes are cached.

Constructor Detail

BitOutputStream

public BitOutputStream(OutputStream os)
Method Detail

write

public void write(int byteValue)
           throws IOException
Write a byte at the current bit boundary.

Throws:
IOException

writeBits

public void writeBits(int value,
                      int numBits)
               throws IOException
Write the given number of bits (1 to 32) from the given value to the underlying output stream.

Throws:
IOException

writeBit

public void writeBit(int bit)
              throws IOException
Write a single bit (1 or 0) to the underlying output stream.

Throws:
IOException

flush

public void flush()
           throws IOException
Flush any cached bits and bytes.

Throws:
IOException


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