Home / Class/ SpdyHeaderBlockJZlibEncoder Class — netty Architecture

SpdyHeaderBlockJZlibEncoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  b937aa0f_a3c6_4d56_b7da_79ec59f96c8b["SpdyHeaderBlockJZlibEncoder"]
  fc44b8c6_02f4_50e9_b4e2_827d186d4b13["SpdyHeaderBlockJZlibEncoder.java"]
  b937aa0f_a3c6_4d56_b7da_79ec59f96c8b -->|defined in| fc44b8c6_02f4_50e9_b4e2_827d186d4b13
  853f218a_4dfb_7433_16dd_9f41f5d610c7["SpdyHeaderBlockJZlibEncoder()"]
  b937aa0f_a3c6_4d56_b7da_79ec59f96c8b -->|method| 853f218a_4dfb_7433_16dd_9f41f5d610c7
  753bdf9e_802b_a9ca_7897_9cc56d1189a3["setInput()"]
  b937aa0f_a3c6_4d56_b7da_79ec59f96c8b -->|method| 753bdf9e_802b_a9ca_7897_9cc56d1189a3
  b3efdd15_4c0c_d02e_84d6_27d3d3602708["ByteBuf()"]
  b937aa0f_a3c6_4d56_b7da_79ec59f96c8b -->|method| b3efdd15_4c0c_d02e_84d6_27d3d3602708
  c6a1338d_53aa_7e0d_f42a_38caf8f8d33a["end()"]
  b937aa0f_a3c6_4d56_b7da_79ec59f96c8b -->|method| c6a1338d_53aa_7e0d_f42a_38caf8f8d33a

Relationship Graph

Source Code

codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockJZlibEncoder.java lines 28–156

class SpdyHeaderBlockJZlibEncoder extends SpdyHeaderBlockRawEncoder {

    private final Deflater z = new Deflater();

    private boolean finished;

    SpdyHeaderBlockJZlibEncoder(
            SpdyVersion version, int compressionLevel, int windowBits, int memLevel) {
        super(version);
        if (compressionLevel < 0 || compressionLevel > 9) {
            throw new IllegalArgumentException(
                    "compressionLevel: " + compressionLevel + " (expected: 0-9)");
        }
        if (windowBits < 9 || windowBits > 15) {
            throw new IllegalArgumentException(
                    "windowBits: " + windowBits + " (expected: 9-15)");
        }
        if (memLevel < 1 || memLevel > 9) {
            throw new IllegalArgumentException(
                    "memLevel: " + memLevel + " (expected: 1-9)");
        }

        int resultCode = z.deflateInit(
                compressionLevel, windowBits, memLevel, JZlib.W_ZLIB);
        if (resultCode != JZlib.Z_OK) {
            throw new CompressionException(
                    "failed to initialize an SPDY header block deflater: " + resultCode);
        } else {
            resultCode = z.deflateSetDictionary(SPDY_DICT, SPDY_DICT.length);
            if (resultCode != JZlib.Z_OK) {
                throw new CompressionException(
                        "failed to set the SPDY dictionary: " + resultCode);
            }
        }
    }

    private void setInput(ByteBuf decompressed) {
        int len = decompressed.readableBytes();

        byte[] in;
        int offset;
        if (decompressed.hasArray()) {
            in = decompressed.array();
            offset = decompressed.arrayOffset() + decompressed.readerIndex();
        } else {
            in = new byte[len];
            decompressed.getBytes(decompressed.readerIndex(), in);
            offset = 0;
        }
        z.next_in = in;
        z.next_in_index = offset;
        z.avail_in = len;
    }

    private ByteBuf encode(ByteBufAllocator alloc) {
        boolean release = true;
        ByteBuf out = null;
        try {
            int oldNextInIndex = z.next_in_index;
            int oldNextOutIndex = z.next_out_index;

            int maxOutputLength = (int) Math.ceil(z.next_in.length * 1.001) + 12;
            out = alloc.heapBuffer(maxOutputLength);
            z.next_out = out.array();
            z.next_out_index = out.arrayOffset() + out.writerIndex();
            z.avail_out = maxOutputLength;

            int resultCode;
            try {
                resultCode = z.deflate(JZlib.Z_SYNC_FLUSH);
            } finally {
                out.skipBytes(z.next_in_index - oldNextInIndex);
            }
            if (resultCode != JZlib.Z_OK) {
                throw new CompressionException("compression failure: " + resultCode);
            }

            int outputLength = z.next_out_index - oldNextOutIndex;
            if (outputLength > 0) {
                out.writerIndex(out.writerIndex() + outputLength);
            }

Frequently Asked Questions

What is the SpdyHeaderBlockJZlibEncoder class?
SpdyHeaderBlockJZlibEncoder is a class in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockJZlibEncoder.java.
Where is SpdyHeaderBlockJZlibEncoder defined?
SpdyHeaderBlockJZlibEncoder is defined in codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHeaderBlockJZlibEncoder.java at line 28.

Analyze Your Own Codebase

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

Try Supermodel Free