Home / Class/ Bzip2Encoder Class — netty Architecture

Bzip2Encoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  f5a67cba_5005_73f8_aa68_98f6f92e4a9a["Bzip2Encoder"]
  dc3ae5a7_2ff1_c3ea_9810_df756e023406["Bzip2Encoder.java"]
  f5a67cba_5005_73f8_aa68_98f6f92e4a9a -->|defined in| dc3ae5a7_2ff1_c3ea_9810_df756e023406
  35d43d69_b851_9b7c_af54_366569f32fd4["Bzip2Encoder()"]
  f5a67cba_5005_73f8_aa68_98f6f92e4a9a -->|method| 35d43d69_b851_9b7c_af54_366569f32fd4
  35e37b6a_cb9e_fb64_b499_c94674308a46["encode()"]
  f5a67cba_5005_73f8_aa68_98f6f92e4a9a -->|method| 35e37b6a_cb9e_fb64_b499_c94674308a46
  493c0913_17c0_d05d_64f9_62bdd17d5666["closeBlock()"]
  f5a67cba_5005_73f8_aa68_98f6f92e4a9a -->|method| 493c0913_17c0_d05d_64f9_62bdd17d5666
  abe8a2d1_af48_e98f_e54e_c50723c8db60["isClosed()"]
  f5a67cba_5005_73f8_aa68_98f6f92e4a9a -->|method| abe8a2d1_af48_e98f_e54e_c50723c8db60
  abe92a1c_ed15_ba3f_baa8_ae9c03bdd4a1["ChannelFuture()"]
  f5a67cba_5005_73f8_aa68_98f6f92e4a9a -->|method| abe92a1c_ed15_ba3f_baa8_ae9c03bdd4a1
  40ad1917_c091_1ab2_d975_f2d66402d28b["close()"]
  f5a67cba_5005_73f8_aa68_98f6f92e4a9a -->|method| 40ad1917_c091_1ab2_d975_f2d66402d28b
  5c55f960_494c_0e58_0bbc_6f17f451acf6["ChannelHandlerContext()"]
  f5a67cba_5005_73f8_aa68_98f6f92e4a9a -->|method| 5c55f960_494c_0e58_0bbc_6f17f451acf6
  a27f2c3b_b266_8999_5fef_e331d0da40c1["handlerAdded()"]
  f5a67cba_5005_73f8_aa68_98f6f92e4a9a -->|method| a27f2c3b_b266_8999_5fef_e331d0da40c1

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2Encoder.java lines 39–242

public class Bzip2Encoder extends MessageToByteEncoder<ByteBuf> {
    /**
     * Current state of stream.
     */
    private enum State {
        INIT,
        INIT_BLOCK,
        WRITE_DATA,
        CLOSE_BLOCK
    }

    private State currentState = State.INIT;

    /**
     * A writer that provides bit-level writes.
     */
    private final Bzip2BitWriter writer = new Bzip2BitWriter();

    /**
     * The declared maximum block size of the stream (before final run-length decoding).
     */
    private final int streamBlockSize;

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

    /**
     * The compressor for the current block.
     */
    private Bzip2BlockCompressor blockCompressor;

    /**
     * (@code true} if the compressed stream has been finished, otherwise {@code false}.
     */
    private volatile boolean finished;

    /**
     * Used to interact with its {@link ChannelPipeline} and other handlers.
     */
    private volatile ChannelHandlerContext ctx;

    /**
     * Creates a new bzip2 encoder with the maximum (900,000 byte) block size.
     */
    public Bzip2Encoder() {
        this(MAX_BLOCK_SIZE);
    }

    /**
     * Creates a new bzip2 encoder with the specified {@code blockSizeMultiplier}.
     * @param blockSizeMultiplier
     *        The Bzip2 block size as a multiple of 100,000 bytes (minimum {@code 1}, maximum {@code 9}).
     *        Larger block sizes require more memory for both compression and decompression,
     *        but give better compression ratios. {@code 9} will usually be the best value to use.
     */
    public Bzip2Encoder(final int blockSizeMultiplier) {
        super(ByteBuf.class);
        if (blockSizeMultiplier < MIN_BLOCK_SIZE || blockSizeMultiplier > MAX_BLOCK_SIZE) {
            throw new IllegalArgumentException(
                    "blockSizeMultiplier: " + blockSizeMultiplier + " (expected: 1-9)");
        }
        streamBlockSize = blockSizeMultiplier * BASE_BLOCK_SIZE;
    }

    @Override
    protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
        if (finished) {
            out.writeBytes(in);
            return;
        }

        for (;;) {
            switch (currentState) {
                case INIT:
                    out.ensureWritable(4);
                    out.writeMedium(MAGIC_NUMBER);
                    out.writeByte('0' + streamBlockSize / BASE_BLOCK_SIZE);
                    currentState = State.INIT_BLOCK;
                    // fall through

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free