Home / Class/ Bzip2Decoder Class — netty Architecture

Bzip2Decoder Class — netty Architecture

Architecture documentation for the Bzip2Decoder class in Bzip2Decoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  1dcad4ee_512f_750e_51bc_5fd809d92ae4["Bzip2Decoder"]
  b65c585d_1ddb_6bcc_e964_063f75d70a9a["Bzip2Decoder.java"]
  1dcad4ee_512f_750e_51bc_5fd809d92ae4 -->|defined in| b65c585d_1ddb_6bcc_e964_063f75d70a9a
  aa16deec_b8b5_56a6_86f7_022b242fed1c["decode()"]
  1dcad4ee_512f_750e_51bc_5fd809d92ae4 -->|method| aa16deec_b8b5_56a6_86f7_022b242fed1c
  0161fc75_7ea6_9d19_a9c6_71466158a18b["isClosed()"]
  1dcad4ee_512f_750e_51bc_5fd809d92ae4 -->|method| 0161fc75_7ea6_9d19_a9c6_71466158a18b

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2Decoder.java lines 44–344

public class Bzip2Decoder extends ByteToMessageDecoder {
    /**
     * Current state of stream.
     */
    private enum State {
        INIT,
        INIT_BLOCK,
        INIT_BLOCK_PARAMS,
        RECEIVE_HUFFMAN_USED_MAP,
        RECEIVE_HUFFMAN_USED_BITMAPS,
        RECEIVE_SELECTORS_NUMBER,
        RECEIVE_SELECTORS,
        RECEIVE_HUFFMAN_LENGTH,
        DECODE_HUFFMAN_DATA,
        EOF
    }
    private State currentState = State.INIT;

    /**
     * A reader that provides bit-level reads.
     */
    private final Bzip2BitReader reader = new Bzip2BitReader();

    /**
     * The decompressor for the current block.
     */
    private Bzip2BlockDecompressor blockDecompressor;

    /**
     * Bzip2 Huffman coding stage.
     */
    private Bzip2HuffmanStageDecoder huffmanStageDecoder;

    /**
     * Always: in the range 0 .. 9. The current block size is 100000 * this number.
     */
    private int blockSize;

    /**
     * The CRC of the current block as read from the block header.
     */
    private int blockCRC;

    /**
     * The merged CRC of all blocks decompressed so far.
     */
    private int streamCRC;

    @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;
                }

Frequently Asked Questions

What is the Bzip2Decoder class?
Bzip2Decoder is a class in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2Decoder.java.
Where is Bzip2Decoder defined?
Bzip2Decoder is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2Decoder.java at line 44.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free