Class BitOutputStream

  • All Implemented Interfaces:
    BitWriter

    public class BitOutputStream
    extends java.lang.Object
    implements BitWriter
    This is a big endian bit writer. It writes its bits to an OutputStream.
    • Constructor Summary

      Constructors 
      Constructor Description
      BitOutputStream​(Stream out)
      Use an OutputStream to produce a BitWriter.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long nrBits()
      Returns the number of bits that have been written to this bitOutputStream.
      void one()
      Write a 1 bit.
      void pad​(int width)
      Pad the rest of the block with zeros and flush.
      void write​(int bits, int width)
      Write some bits.
      void zero()
      Write a 0 bit.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BitOutputStream

        public BitOutputStream​(Stream out)
        Use an OutputStream to produce a BitWriter. The BitWriter will send its bits to the OutputStream as each byte is filled.
        Parameters:
        out - An Output Stream
    • Method Detail

      • nrBits

        public long nrBits()
        Returns the number of bits that have been written to this bitOutputStream. This may include bits that have not yet been written to the underlying outputStream.
      • pad

        public void pad​(int width)
                 throws IOException
        Pad the rest of the block with zeros and flush. pad(8) flushes the last unfinished byte. The underlying OutputStream will be flushed.
        Specified by:
        pad in interface BitWriter
        Parameters:
        width - The size of the block to pad in bits. This will typically be 8, 16, 32, 64, 128, 256, etc.
        Throws:
        IOException
      • write

        public void write​(int bits,
                          int width)
                   throws IOException
        Write some bits. Up to 32 bits can be written at a time.
        Specified by:
        write in interface BitWriter
        Parameters:
        bits - The bits to be written.
        width - The number of bits to write. (0..32)
        Throws:
        IOException