Class Bzip2BlockCompressor

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) int availableSize()
      Gets available size of the current block.
      (package private) void close​(ByteBuf out)
      Compresses and writes out the block.
      (package private) int crc()
      Gets the CRC of the completed block.
      (package private) boolean isEmpty()
      Determines if any bytes have been written to the block.
      (package private) boolean isFull()
      Determines if the block is full and ready for compression.
      (package private) boolean write​(int value)
      Writes a byte to the block, accumulating to an RLE run where possible.
      (package private) int write​(ByteBuf buffer, int offset, int length)
      Writes an array to the block.
      private void writeRun​(int value, int runLength)
      Writes an RLE run to the block array, updating the block CRC and present values array as required.
      private void writeSymbolMap​(ByteBuf out)
      Write the Huffman symbol to output byte map.
      • Methods inherited from class java.lang.Object

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

      • writer

        private final Bzip2BitWriter writer
        A writer that provides bit-level writes.
      • crc

        private final Crc32 crc
        CRC builder for the block.
      • block

        private final byte[] block
        The RLE'd block data.
      • blockLength

        private int blockLength
        Current length of the data within the block array.
      • blockLengthLimit

        private final int blockLengthLimit
        A limit beyond which new data will not be accepted into the block.
      • blockValuesPresent

        private final boolean[] blockValuesPresent
        The values that are present within the RLE'd block data. For each index, true if that value is present within the data, otherwise false.
      • bwtBlock

        private final int[] bwtBlock
        The Burrows Wheeler Transformed block data.
      • rleCurrentValue

        private int rleCurrentValue
        The current RLE value being accumulated (undefined when rleLength is 0).
      • rleLength

        private int rleLength
        The repeat count of the current RLE value.
    • Constructor Detail

      • Bzip2BlockCompressor

        Bzip2BlockCompressor​(Bzip2BitWriter writer,
                             int blockSize)
        Parameters:
        writer - The Bzip2BitWriter which provides bit-level writes
        blockSize - The declared block size in bytes. Up to this many bytes will be accepted into the block after Run-Length Encoding is applied
    • Method Detail

      • writeSymbolMap

        private void writeSymbolMap​(ByteBuf out)
        Write the Huffman symbol to output byte map.
      • writeRun

        private void writeRun​(int value,
                              int runLength)
        Writes an RLE run to the block array, updating the block CRC and present values array as required.
        Parameters:
        value - The value to write
        runLength - The run length of the value to write
      • write

        boolean write​(int value)
        Writes a byte to the block, accumulating to an RLE run where possible.
        Parameters:
        value - The byte to write
        Returns:
        true if the byte was written, or false if the block is already full
      • write

        int write​(ByteBuf buffer,
                  int offset,
                  int length)
        Writes an array to the block.
        Parameters:
        buffer - The buffer to write
        offset - The offset within the input data to write from
        length - The number of bytes of input data to write
        Returns:
        The actual number of input bytes written. May be less than the number requested, or zero if the block is already full
      • close

        void close​(ByteBuf out)
        Compresses and writes out the block.
      • availableSize

        int availableSize()
        Gets available size of the current block.
        Returns:
        Number of available bytes which can be written
      • isFull

        boolean isFull()
        Determines if the block is full and ready for compression.
        Returns:
        true if the block is full, otherwise false
      • isEmpty

        boolean isEmpty()
        Determines if any bytes have been written to the block.
        Returns:
        true if one or more bytes has been written to the block, otherwise false
      • crc

        int crc()
        Gets the CRC of the completed block. Only valid after calling close(ByteBuf).
        Returns:
        The block's CRC