Class BitOutputStream

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class BitOutputStream extends FilterOutputStream
Output Stream which allows to write single bits sequentially. Bits are written left aligned. Explicit calls to write bytes and primitce types of multiple bytes cause the bit buffer to be flushed. A file can grow like this:
          0    1000 0001      | <= write((byte)0x81);
 
          0    1000 0001      
          1    101. ....      | <= write(true); write(false);write(true);
 
          0    1000 0001      
          1    101. ....      
          2    0000 0001      
          3    0000 0010      | <= write((int)258));
  
  • Field Summary

    Fields inherited from class java.io.FilterOutputStream

    out
  • Constructor Summary

    Constructors
    Constructor
    Description
    Only constructed.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Shifts the bits written to the buffer buf to be left aligned, writes the resulting byte and clears the buffer.
    void
    Closes the output stream after flushing the bit buffer..
    void
    Flushes the output stream after flushing the bit buffer.
    void
    write(byte[] b)
    Writes bytes to the output after flushing the bit buffer.
    void
    write(byte[] b, int off, int len)
    Writes bytes to the output after flushing the bit buffer
    void
    write(int b)
    Writes one integer to the output after flushing the bit buffer.
    final void
    writeBit(boolean b)
    Write a boolean value as a bit value.
    void
    writeBit(int b)
    Appends a bit value at the lowest position in the buffer.

    Methods inherited from class java.io.OutputStream

    nullOutputStream

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait