Home / Function/ ByteBuf() — netty Function Reference

ByteBuf() — netty Function Reference

Architecture documentation for the ByteBuf() function in JdkZlibEncoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  710100a4_5677_7b4f_0312_a3fbe54152f7["ByteBuf()"]
  8dcc2fdc_baa4_5fb3_e4d7_000af1ddd30a["JdkZlibEncoder"]
  710100a4_5677_7b4f_0312_a3fbe54152f7 -->|defined in| 8dcc2fdc_baa4_5fb3_e4d7_000af1ddd30a
  style 710100a4_5677_7b4f_0312_a3fbe54152f7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java lines 278–300

    @Override
    protected final ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg,
                                           boolean preferDirect) throws Exception {
        int sizeEstimate = (int) Math.ceil(msg.readableBytes() * 1.001) + 12;
        if (writeHeader) {
            switch (wrapper) {
                case GZIP:
                    sizeEstimate += gzipHeader.length;
                    break;
                case ZLIB:
                    sizeEstimate += 2; // first two magic bytes
                    break;
                default:
                    // no op
            }
        }
        // sizeEstimate might overflow if close to 2G
        if (sizeEstimate < 0 || sizeEstimate > MAX_INITIAL_OUTPUT_BUFFER_SIZE) {
            // can always expand later
            return ctx.alloc().heapBuffer(MAX_INITIAL_OUTPUT_BUFFER_SIZE);
        }
        return ctx.alloc().heapBuffer(sizeEstimate);
    }

Domain

Subdomains

Frequently Asked Questions

What does ByteBuf() do?
ByteBuf() is a function in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java.
Where is ByteBuf() defined?
ByteBuf() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java at line 278.

Analyze Your Own Codebase

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

Try Supermodel Free