Class Bzip2BlockDecompressor

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int blockCRC
      The CRC of the current block as read from the block header.
      private boolean blockRandomised
      true if the current block is randomised, otherwise false.
      private byte[] bwtBlock
      The Burrows-Wheeler Transform processed data.
      private int bwtBlockLength
      The actual length in bytes of the current block at the Inverse Burrows Wheeler Transform stage (before final Run-Length Decoding).
      private int[] bwtByteCounts
      Counts of each byte value within the huffmanSymbolMap data.
      private int bwtBytesDecoded
      The number of output bytes that have been decoded up to the Inverse Burrows Wheeler Transform stage.
      private int bwtCurrentMergedPointer
      The current merged pointer into the Burrow-Wheeler Transform array.
      private int[] bwtMergedPointers
      At each position contains the union of :- An output character (8 bits) A pointer from each position to its successor (24 bits, left shifted 8 bits) As the pointer cannot exceed the maximum block size of 900k, 24 bits is more than enough to hold it; Folding the character data into the spare bits while performing the inverse BWT, when both pieces of information are available, saves a large number of memory accesses in the final decoding stages.
      private int bwtStartPointer
      Starting pointer into BWT for after untransform.
      private Crc32 crc
      Calculates the block CRC from the fully decoded bytes of the block.
      (package private) int huffmanEndOfBlockSymbol
      The end-of-block Huffman symbol.
      (package private) int huffmanInUse16
      Bitmap, of ranges of 16 bytes, present/not present.
      (package private) byte[] huffmanSymbolMap
      A map from Huffman symbol index to output character.
      private int mtfValue  
      private int randomCount
      If the current block is randomised, the remaining count at the current RNUMS position.
      private int randomIndex
      If the current block is randomised, the position within the RNUMS randomisation array.
      private Bzip2BitReader reader
      A reader that provides bit-level reads.
      private int repeatCount  
      private int repeatIncrement  
      private int rleAccumulator
      The number of previous identical output bytes decoded.
      private int rleLastDecodedByte
      The most recently RLE decoded byte.
      private int rleRepeat
      The RLE repeat count of the current decoded byte.
      private Bzip2MoveToFrontTable symbolMTF
      Table for Move To Front transformations.
    • Constructor Summary

      Constructors 
      Constructor Description
      Bzip2BlockDecompressor​(int blockSize, int blockCRC, boolean blockRandomised, int bwtStartPointer, Bzip2BitReader reader)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int blockLength()  
      (package private) int checkCRC()
      Verify and return the block CRC.
      (package private) boolean decodeHuffmanData​(Bzip2HuffmanStageDecoder huffmanDecoder)
      Reads the Huffman encoded data from the input stream, performs Run-Length Decoding and applies the Move To Front transform to reconstruct the Burrows-Wheeler Transform array.
      private int decodeNextBWTByte()
      Decodes a byte from the Burrows-Wheeler Transform stage.
      private void initialiseInverseBWT()
      Set up the Inverse Burrows-Wheeler Transform merged pointer array.
      int read()
      Decodes a byte from the final Run-Length Encoding stage, pulling a new byte from the Burrows-Wheeler Transform stage when required.
      • Methods inherited from class java.lang.Object

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

      • reader

        private final Bzip2BitReader reader
        A reader that provides bit-level reads.
      • crc

        private final Crc32 crc
        Calculates the block CRC from the fully decoded bytes of the block.
      • blockCRC

        private final int blockCRC
        The CRC of the current block as read from the block header.
      • blockRandomised

        private final boolean blockRandomised
        true if the current block is randomised, otherwise false.
      • huffmanEndOfBlockSymbol

        int huffmanEndOfBlockSymbol
        The end-of-block Huffman symbol. Decoding of the block ends when this is encountered.
      • huffmanInUse16

        int huffmanInUse16
        Bitmap, of ranges of 16 bytes, present/not present.
      • huffmanSymbolMap

        final byte[] huffmanSymbolMap
        A map from Huffman symbol index to output character. Some types of data (e.g. ASCII text) may contain only a limited number of byte values; Huffman symbols are only allocated to those values that actually occur in the uncompressed data.
      • bwtByteCounts

        private final int[] bwtByteCounts
        Counts of each byte value within the huffmanSymbolMap data. Collected at the Move To Front stage, consumed by the Inverse Burrows Wheeler Transform stage.
      • bwtBlock

        private final byte[] bwtBlock
        The Burrows-Wheeler Transform processed data. Read at the Move To Front stage, consumed by the Inverse Burrows Wheeler Transform stage.
      • bwtStartPointer

        private final int bwtStartPointer
        Starting pointer into BWT for after untransform.
      • bwtMergedPointers

        private int[] bwtMergedPointers
        At each position contains the union of :- An output character (8 bits) A pointer from each position to its successor (24 bits, left shifted 8 bits) As the pointer cannot exceed the maximum block size of 900k, 24 bits is more than enough to hold it; Folding the character data into the spare bits while performing the inverse BWT, when both pieces of information are available, saves a large number of memory accesses in the final decoding stages.
      • bwtCurrentMergedPointer

        private int bwtCurrentMergedPointer
        The current merged pointer into the Burrow-Wheeler Transform array.
      • bwtBlockLength

        private int bwtBlockLength
        The actual length in bytes of the current block at the Inverse Burrows Wheeler Transform stage (before final Run-Length Decoding).
      • bwtBytesDecoded

        private int bwtBytesDecoded
        The number of output bytes that have been decoded up to the Inverse Burrows Wheeler Transform stage.
      • rleLastDecodedByte

        private int rleLastDecodedByte
        The most recently RLE decoded byte.
      • rleAccumulator

        private int rleAccumulator
        The number of previous identical output bytes decoded. After 4 identical bytes, the next byte decoded is an RLE repeat count.
      • rleRepeat

        private int rleRepeat
        The RLE repeat count of the current decoded byte. When this reaches zero, a new byte is decoded.
      • randomIndex

        private int randomIndex
        If the current block is randomised, the position within the RNUMS randomisation array.
      • randomCount

        private int randomCount
        If the current block is randomised, the remaining count at the current RNUMS position.
      • repeatCount

        private int repeatCount
      • repeatIncrement

        private int repeatIncrement
      • mtfValue

        private int mtfValue
    • Constructor Detail

      • Bzip2BlockDecompressor

        Bzip2BlockDecompressor​(int blockSize,
                               int blockCRC,
                               boolean blockRandomised,
                               int bwtStartPointer,
                               Bzip2BitReader reader)
    • Method Detail

      • decodeHuffmanData

        boolean decodeHuffmanData​(Bzip2HuffmanStageDecoder huffmanDecoder)
        Reads the Huffman encoded data from the input stream, performs Run-Length Decoding and applies the Move To Front transform to reconstruct the Burrows-Wheeler Transform array.
      • initialiseInverseBWT

        private void initialiseInverseBWT()
        Set up the Inverse Burrows-Wheeler Transform merged pointer array.
      • read

        public int read()
        Decodes a byte from the final Run-Length Encoding stage, pulling a new byte from the Burrows-Wheeler Transform stage when required.
        Returns:
        The decoded byte, or -1 if there are no more bytes
      • decodeNextBWTByte

        private int decodeNextBWTByte()
        Decodes a byte from the Burrows-Wheeler Transform stage. If the block has randomisation applied, reverses the randomisation.
        Returns:
        The decoded byte
      • blockLength

        public int blockLength()
      • checkCRC

        int checkCRC()
        Verify and return the block CRC. This method may only be called after all of the block's bytes have been read.
        Returns:
        The block CRC