decode() — netty Function Reference
Architecture documentation for the decode() function in Bzip2Decoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD aa16deec_b8b5_56a6_86f7_022b242fed1c["decode()"] 1dcad4ee_512f_750e_51bc_5fd809d92ae4["Bzip2Decoder"] aa16deec_b8b5_56a6_86f7_022b242fed1c -->|defined in| 1dcad4ee_512f_750e_51bc_5fd809d92ae4 style aa16deec_b8b5_56a6_86f7_022b242fed1c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2Decoder.java lines 92–335
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (!in.isReadable()) {
return;
}
final Bzip2BitReader reader = this.reader;
reader.setByteBuf(in);
for (;;) {
switch (currentState) {
case INIT:
if (in.readableBytes() < 4) {
return;
}
int magicNumber = in.readUnsignedMedium();
if (magicNumber != MAGIC_NUMBER) {
throw new DecompressionException("Unexpected stream identifier contents. Mismatched bzip2 " +
"protocol version?");
}
int blockSize = in.readByte() - '0';
if (blockSize < MIN_BLOCK_SIZE || blockSize > MAX_BLOCK_SIZE) {
throw new DecompressionException("block size is invalid");
}
this.blockSize = blockSize * BASE_BLOCK_SIZE;
streamCRC = 0;
currentState = State.INIT_BLOCK;
// fall through
case INIT_BLOCK:
if (!reader.hasReadableBytes(10)) {
return;
}
// Get the block magic bytes.
final int magic1 = reader.readBits(24);
final int magic2 = reader.readBits(24);
if (magic1 == END_OF_STREAM_MAGIC_1 && magic2 == END_OF_STREAM_MAGIC_2) {
// End of stream was reached. Check the combined CRC.
final int storedCombinedCRC = reader.readInt();
if (storedCombinedCRC != streamCRC) {
throw new DecompressionException("stream CRC error");
}
currentState = State.EOF;
break;
}
if (magic1 != BLOCK_HEADER_MAGIC_1 || magic2 != BLOCK_HEADER_MAGIC_2) {
throw new DecompressionException("bad block header");
}
blockCRC = reader.readInt();
currentState = State.INIT_BLOCK_PARAMS;
// fall through
case INIT_BLOCK_PARAMS:
if (!reader.hasReadableBits(25)) {
return;
}
final boolean blockRandomised = reader.readBoolean();
final int bwtStartPointer = reader.readBits(24);
blockDecompressor = new Bzip2BlockDecompressor(this.blockSize, blockCRC,
blockRandomised, bwtStartPointer, reader);
currentState = State.RECEIVE_HUFFMAN_USED_MAP;
// fall through
case RECEIVE_HUFFMAN_USED_MAP:
if (!reader.hasReadableBits(16)) {
return;
}
blockDecompressor.huffmanInUse16 = reader.readBits(16);
currentState = State.RECEIVE_HUFFMAN_USED_BITMAPS;
// fall through
case RECEIVE_HUFFMAN_USED_BITMAPS:
Bzip2BlockDecompressor blockDecompressor = this.blockDecompressor;
final int inUse16 = blockDecompressor.huffmanInUse16;
final int bitNumber = Integer.bitCount(inUse16);
final byte[] huffmanSymbolMap = blockDecompressor.huffmanSymbolMap;
if (!reader.hasReadableBits(bitNumber * HUFFMAN_SYMBOL_RANGE_SIZE + 3)) {
return;
}
int huffmanSymbolCount = 0;
if (bitNumber > 0) {
Domain
Subdomains
Source
Frequently Asked Questions
What does decode() do?
decode() is a function in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2Decoder.java.
Where is decode() defined?
decode() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2Decoder.java at line 92.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free