Class Bzip2BlockCompressor
java.lang.Object
io.netty.handler.codec.compression.Bzip2BlockCompressor
Compresses and writes a single Bzip2 block.
Block encoding consists of the following stages:
1. Run-Length Encoding[1] -
2. Burrows Wheeler Transform -
3. Write block header -
4. Move To Front Transform -
5. Run-Length Encoding[2] -
6. Create and write Huffman tables -
7. Huffman encode and write data -
Block encoding consists of the following stages:
1. Run-Length Encoding[1] -
write(int)
2. Burrows Wheeler Transform -
close(ByteBuf)
(through Bzip2DivSufSort
)3. Write block header -
close(ByteBuf)
4. Move To Front Transform -
close(ByteBuf)
(through Bzip2HuffmanStageEncoder
)5. Run-Length Encoding[2] -
close(ByteBuf)
(through Bzip2HuffmanStageEncoder
)6. Create and write Huffman tables -
close(ByteBuf)
(through Bzip2HuffmanStageEncoder
)7. Huffman encode and write data -
close(ByteBuf)
(through Bzip2HuffmanStageEncoder
)-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]
The RLE'd block data.private int
Current length of the data within theblock
array.private final int
A limit beyond which new data will not be accepted into the block.private final boolean[]
The values that are present within the RLE'd block data.private final int[]
The Burrows Wheeler Transformed block data.private final Crc32
CRC builder for the block.private int
The current RLE value being accumulated (undefined whenrleLength
is 0).private int
The repeat count of the current RLE value.private final ByteProcessor
private final Bzip2BitWriter
A writer that provides bit-level writes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) int
Gets available size of the current block.(package private) void
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
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.
-
Field Details
-
writeProcessor
-
writer
A writer that provides bit-level writes. -
crc
CRC builder for the block. -
block
private final byte[] blockThe RLE'd block data. -
blockLength
private int blockLengthCurrent length of the data within theblock
array. -
blockLengthLimit
private final int blockLengthLimitA limit beyond which new data will not be accepted into the block. -
blockValuesPresent
private final boolean[] blockValuesPresentThe values that are present within the RLE'd block data. For each index,true
if that value is present within the data, otherwisefalse
. -
bwtBlock
private final int[] bwtBlockThe Burrows Wheeler Transformed block data. -
rleCurrentValue
private int rleCurrentValueThe current RLE value being accumulated (undefined whenrleLength
is 0). -
rleLength
private int rleLengthThe repeat count of the current RLE value.
-
-
Constructor Details
-
Bzip2BlockCompressor
Bzip2BlockCompressor(Bzip2BitWriter writer, int blockSize) - Parameters:
writer
- TheBzip2BitWriter
which provides bit-level writesblockSize
- The declared block size in bytes. Up to this many bytes will be accepted into the block after Run-Length Encoding is applied
-
-
Method Details
-
writeSymbolMap
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 writerunLength
- 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, orfalse
if the block is already full
-
write
Writes an array to the block.- Parameters:
buffer
- The buffer to writeoffset
- The offset within the input data to write fromlength
- 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
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, otherwisefalse
-
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, otherwisefalse
-
crc
int crc()Gets the CRC of the completed block. Only valid after callingclose(ByteBuf)
.- Returns:
- The block's CRC
-