Class BitWriter


  • public class BitWriter
    extends Object
    Wrapper around a ByteBuffer that allows to write individual bits or group of bits All the writings/readings are performed to a temporary long which is stored into the backing ByteBuffer when it is "full" Don't forget to call flush after the last write, such that the long is written to the backing ByteBuffer
    • Constructor Detail

      • BitWriter

        public BitWriter​(ByteBuffer bb)
        Constructs a BitWriter around an existing ByteBuffer
        Parameters:
        bb -
    • Method Detail

      • write

        public void write​(int x,
                          int numBits)
        write the least significant numBits of x into the BitBuffer Note that there is no check that the bits will actually fit into the ByteBuffer, they will be stored in the temporary field. A buffer overflow exception will happen when the temporary field is full and flushed to the buffer
        Parameters:
        x -
        numBits -
      • flush

        public void flush()
        flush the temporary long to the ByteBuffer do not call this method twice!!