Class Bzip2BlockDecompressor
java.lang.Object
io.netty.handler.codec.compression.Bzip2BlockDecompressor
Reads and decompresses a single Bzip2 block.
Block decoding consists of the following stages:
1. Read block header
2. Read Huffman tables
3. Read and decode Huffman encoded data -
4. Run-Length Decoding[2] -
5. Inverse Move To Front Transform -
6. Inverse Burrows Wheeler Transform -
7. Run-Length Decoding[1] -
8. Optional Block De-Randomisation -
Block decoding consists of the following stages:
1. Read block header
2. Read Huffman tables
3. Read and decode Huffman encoded data -
decodeHuffmanData(Bzip2HuffmanStageDecoder)4. Run-Length Decoding[2] -
decodeHuffmanData(Bzip2HuffmanStageDecoder)5. Inverse Move To Front Transform -
decodeHuffmanData(Bzip2HuffmanStageDecoder)6. Inverse Burrows Wheeler Transform -
initialiseInverseBWT()7. Run-Length Decoding[1] -
read()8. Optional Block De-Randomisation -
read() (through decodeNextBWTByte())-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe CRC of the current block as read from the block header.private final booleantrueif the current block is randomised, otherwisefalse.private final byte[]The Burrows-Wheeler Transform processed data.private intThe actual length in bytes of the current block at the Inverse Burrows Wheeler Transform stage (before final Run-Length Decoding).private final int[]Counts of each byte value within thehuffmanSymbolMapdata.private intThe number of output bytes that have been decoded up to the Inverse Burrows Wheeler Transform stage.private intThe current merged pointer into the Burrow-Wheeler Transform array.private int[]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 final intStarting pointer into BWT for after untransform.private final Crc32Calculates the block CRC from the fully decoded bytes of the block.(package private) intThe end-of-block Huffman symbol.(package private) intBitmap, of ranges of 16 bytes, present/not present.(package private) final byte[]A map from Huffman symbol index to output character.private intprivate intIf the current block is randomised, the remaining count at the current RNUMS position.private intIf the current block is randomised, the position within the RNUMS randomisation array.private final Bzip2BitReaderA reader that provides bit-level reads.private intprivate intprivate intThe number of previous identical output bytes decoded.private intThe most recently RLE decoded byte.private intThe RLE repeat count of the current decoded byte.private final Bzip2MoveToFrontTableTable for Move To Front transformations. -
Constructor Summary
ConstructorsConstructorDescriptionBzip2BlockDecompressor(int blockSize, int blockCRC, boolean blockRandomised, int bwtStartPointer, Bzip2BitReader reader) -
Method Summary
Modifier and TypeMethodDescriptionint(package private) intcheckCRC()Verify and return the block CRC.(package private) booleandecodeHuffmanData(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 intDecodes a byte from the Burrows-Wheeler Transform stage.private voidSet up the Inverse Burrows-Wheeler Transform merged pointer array.intread()Decodes a byte from the final Run-Length Encoding stage, pulling a new byte from the Burrows-Wheeler Transform stage when required.
-
Field Details
-
reader
A reader that provides bit-level reads. -
crc
Calculates the block CRC from the fully decoded bytes of the block. -
blockCRC
private final int blockCRCThe CRC of the current block as read from the block header. -
blockRandomised
private final boolean blockRandomisedtrueif the current block is randomised, otherwisefalse. -
huffmanEndOfBlockSymbol
int huffmanEndOfBlockSymbolThe end-of-block Huffman symbol. Decoding of the block ends when this is encountered. -
huffmanInUse16
int huffmanInUse16Bitmap, of ranges of 16 bytes, present/not present. -
huffmanSymbolMap
final byte[] huffmanSymbolMapA 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[] bwtByteCountsCounts of each byte value within thehuffmanSymbolMapdata. Collected at the Move To Front stage, consumed by the Inverse Burrows Wheeler Transform stage. -
bwtBlock
private final byte[] bwtBlockThe Burrows-Wheeler Transform processed data. Read at the Move To Front stage, consumed by the Inverse Burrows Wheeler Transform stage. -
bwtStartPointer
private final int bwtStartPointerStarting pointer into BWT for after untransform. -
bwtMergedPointers
private int[] bwtMergedPointersAt 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 bwtCurrentMergedPointerThe current merged pointer into the Burrow-Wheeler Transform array. -
bwtBlockLength
private int bwtBlockLengthThe actual length in bytes of the current block at the Inverse Burrows Wheeler Transform stage (before final Run-Length Decoding). -
bwtBytesDecoded
private int bwtBytesDecodedThe number of output bytes that have been decoded up to the Inverse Burrows Wheeler Transform stage. -
rleLastDecodedByte
private int rleLastDecodedByteThe most recently RLE decoded byte. -
rleAccumulator
private int rleAccumulatorThe number of previous identical output bytes decoded. After 4 identical bytes, the next byte decoded is an RLE repeat count. -
rleRepeat
private int rleRepeatThe RLE repeat count of the current decoded byte. When this reaches zero, a new byte is decoded. -
randomIndex
private int randomIndexIf the current block is randomised, the position within the RNUMS randomisation array. -
randomCount
private int randomCountIf the current block is randomised, the remaining count at the current RNUMS position. -
symbolMTF
Table for Move To Front transformations. -
repeatCount
private int repeatCount -
repeatIncrement
private int repeatIncrement -
mtfValue
private int mtfValue
-
-
Constructor Details
-
Bzip2BlockDecompressor
Bzip2BlockDecompressor(int blockSize, int blockCRC, boolean blockRandomised, int bwtStartPointer, Bzip2BitReader reader)
-
-
Method Details
-
decodeHuffmanData
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
-