Top Description Fields Constructors Methods
io.netty.handler.codec.compression

pack-priv final Class Bzip2BlockDecompressor

extends Object
Class Inheritance
Static Imports
io.netty.handler.codec.compression.Bzip2Constants.HUFFMAN_DECODE_MAX_CODE_LENGTH, .Bzip2Constants.HUFFMAN_SYMBOL_RUNA, .Bzip2Constants.HUFFMAN_SYMBOL_RUNB, .Bzip2Constants.MAX_BLOCK_LENGTH

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 - 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

Modifier and TypeField and Description
private final int
blockCRC

The CRC of the current block as read from the block header.

private final boolean
blockRandomised

true if the current block is randomised, otherwise false.

private final 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 final int[]
bwtByteCounts

Counts of each byte value within the Bzip2BlockDecompressor#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 final int
bwtStartPointer

Starting pointer into BWT for after untransform.

private final Crc32
crc

Calculates the block CRC from the fully decoded bytes of the block.

pack-priv int
huffmanEndOfBlockSymbol

The end-of-block Huffman symbol.

pack-priv int
huffmanInUse16

Bitmap, of ranges of 16 bytes, present/not present.

pack-priv final byte[]
huffmanSymbolMap

A map from Huffman symbol index to output character.

private int
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 final Bzip2BitReader
reader

A reader that provides bit-level reads.

private int
private int
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 final Bzip2MoveToFrontTable
symbolMTF

Table for Move To Front transformations.

Constructor Summary

AccessConstructor and Description
pack-priv
Bzip2BlockDecompressor(final int blockSize, final int blockCRC, final boolean blockRandomised, final int bwtStartPointer, final Bzip2BitReader reader)

Method Summary

Modifier and TypeMethod and Description
public int
pack-priv int

Returns:

The block CRC
checkCRC
()

Verify and return the block CRC.

pack-priv boolean
decodeHuffmanData(final 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

Returns:

The decoded byte
decodeNextBWTByte
()

Decodes a byte from the Burrows-Wheeler Transform stage.

private void
initialiseInverseBWT()

Set up the Inverse Burrows-Wheeler Transform merged pointer array.

public int

Returns:

The decoded byte, or -1 if there are no more bytes
read
()

Decodes a byte from the final Run-Length Encoding stage, pulling a new byte from the Burrows-Wheeler Transform stage when required.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockCRCback to summary
private final int blockCRC

The CRC of the current block as read from the block header.

blockRandomisedback to summary
private final boolean blockRandomised

true if the current block is randomised, otherwise false.

bwtBlockback to summary
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.

bwtBlockLengthback to summary
private int bwtBlockLength

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

bwtByteCountsback to summary
private final int[] bwtByteCounts

Counts of each byte value within the Bzip2BlockDecompressor#huffmanSymbolMap data. Collected at the Move To Front stage, consumed by the Inverse Burrows Wheeler Transform stage.

bwtBytesDecodedback to summary
private int bwtBytesDecoded

The number of output bytes that have been decoded up to the Inverse Burrows Wheeler Transform stage.

bwtCurrentMergedPointerback to summary
private int bwtCurrentMergedPointer

The current merged pointer into the Burrow-Wheeler Transform array.

bwtMergedPointersback to summary
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.

bwtStartPointerback to summary
private final int bwtStartPointer

Starting pointer into BWT for after untransform.

crcback to summary
private final Crc32 crc

Calculates the block CRC from the fully decoded bytes of the block.

huffmanEndOfBlockSymbolback to summary
pack-priv int huffmanEndOfBlockSymbol

The end-of-block Huffman symbol. Decoding of the block ends when this is encountered.

huffmanInUse16back to summary
pack-priv int huffmanInUse16

Bitmap, of ranges of 16 bytes, present/not present.

huffmanSymbolMapback to summary
pack-priv 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.

mtfValueback to summary
private int mtfValue
randomCountback to summary
private int randomCount

If the current block is randomised, the remaining count at the current RNUMS position.

randomIndexback to summary
private int randomIndex

If the current block is randomised, the position within the RNUMS randomisation array.

readerback to summary
private final Bzip2BitReader reader

A reader that provides bit-level reads.

repeatCountback to summary
private int repeatCount
repeatIncrementback to summary
private int repeatIncrement
rleAccumulatorback to summary
private int rleAccumulator

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

rleLastDecodedByteback to summary
private int rleLastDecodedByte

The most recently RLE decoded byte.

rleRepeatback to summary
private int rleRepeat

The RLE repeat count of the current decoded byte. When this reaches zero, a new byte is decoded.

symbolMTFback to summary
private final Bzip2MoveToFrontTable symbolMTF

Table for Move To Front transformations.

Constructor Detail

Bzip2BlockDecompressorback to summary
pack-priv Bzip2BlockDecompressor(final int blockSize, final int blockCRC, final boolean blockRandomised, final int bwtStartPointer, final Bzip2BitReader reader)

Method Detail

blockLengthback to summary
public int blockLength()
checkCRCback to summary
pack-priv 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:int

The block CRC

decodeHuffmanDataback to summary
pack-priv boolean decodeHuffmanData(final 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.

decodeNextBWTByteback to summary
private int decodeNextBWTByte()

Decodes a byte from the Burrows-Wheeler Transform stage. If the block has randomisation applied, reverses the randomisation.

Returns:int

The decoded byte

initialiseInverseBWTback to summary
private void initialiseInverseBWT()

Set up the Inverse Burrows-Wheeler Transform merged pointer array.

readback to summary
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:int

The decoded byte, or -1 if there are no more bytes