Class Bzip2BitWriter


  • final class Bzip2BitWriter
    extends java.lang.Object
    A bit writer that allows the writing of single bit booleans, unary numbers, bit strings of arbitrary length (up to 32 bits), and bit aligned 32-bit integers. A single byte at a time is written to the ByteBuf when sufficient bits have been accumulated.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long bitBuffer
      A buffer of bits waiting to be written to the output stream.
      private int bitCount
      The number of bits currently buffered in bitBuffer.
    • Constructor Summary

      Constructors 
      Constructor Description
      Bzip2BitWriter()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void flush​(ByteBuf out)
      Writes any remaining bits to the output ByteBuf, zero padding to a whole byte as required.
      (package private) void writeBits​(ByteBuf out, int count, long value)
      Writes up to 32 bits to the output ByteBuf.
      (package private) void writeBoolean​(ByteBuf out, boolean value)
      Writes a single bit to the output ByteBuf.
      (package private) void writeInt​(ByteBuf out, int value)
      Writes an integer as 32 bits to the output ByteBuf.
      (package private) void writeUnary​(ByteBuf out, int value)
      Writes a zero-terminated unary number to the output ByteBuf.
      • Methods inherited from class java.lang.Object

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

      • bitBuffer

        private long bitBuffer
        A buffer of bits waiting to be written to the output stream.
      • bitCount

        private int bitCount
        The number of bits currently buffered in bitBuffer.
    • Constructor Detail

      • Bzip2BitWriter

        Bzip2BitWriter()
    • Method Detail

      • writeBits

        void writeBits​(ByteBuf out,
                       int count,
                       long value)
        Writes up to 32 bits to the output ByteBuf.
        Parameters:
        count - The number of bits to write (maximum 32 as a size of int)
        value - The bits to write
      • writeBoolean

        void writeBoolean​(ByteBuf out,
                          boolean value)
        Writes a single bit to the output ByteBuf.
        Parameters:
        value - The bit to write
      • writeUnary

        void writeUnary​(ByteBuf out,
                        int value)
        Writes a zero-terminated unary number to the output ByteBuf. Example of the output for value = 6: 1111110
        Parameters:
        value - The number of 1 to write
      • writeInt

        void writeInt​(ByteBuf out,
                      int value)
        Writes an integer as 32 bits to the output ByteBuf.
        Parameters:
        value - The integer to write
      • flush

        void flush​(ByteBuf out)
        Writes any remaining bits to the output ByteBuf, zero padding to a whole byte as required.