encode() — netty Function Reference
Architecture documentation for the encode() function in JZlibEncoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD f0a5f09d_3615_cf2a_d358_6f7437d447e0["encode()"] 835bf072_cb98_c9aa_92d0_5d3c35dec6f6["JZlibEncoder"] f0a5f09d_3615_cf2a_d358_6f7437d447e0 -->|defined in| 835bf072_cb98_c9aa_92d0_5d3c35dec6f6 style f0a5f09d_3615_cf2a_d358_6f7437d447e0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-compression/src/main/java/io/netty/handler/codec/compression/JZlibEncoder.java lines 262–321
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
if (finished) {
out.writeBytes(in);
return;
}
int inputLength = in.readableBytes();
if (inputLength == 0) {
return;
}
try {
// Configure input.
boolean inHasArray = in.hasArray();
z.avail_in = inputLength;
if (inHasArray) {
z.next_in = in.array();
z.next_in_index = in.arrayOffset() + in.readerIndex();
} else {
byte[] array = new byte[inputLength];
in.getBytes(in.readerIndex(), array);
z.next_in = array;
z.next_in_index = 0;
}
int oldNextInIndex = z.next_in_index;
// Configure output.
int maxOutputLength = (int) Math.ceil(inputLength * 1.001) + 12 + wrapperOverhead;
out.ensureWritable(maxOutputLength);
z.avail_out = maxOutputLength;
z.next_out = out.array();
z.next_out_index = out.arrayOffset() + out.writerIndex();
int oldNextOutIndex = z.next_out_index;
// Note that Z_PARTIAL_FLUSH has been deprecated.
int resultCode;
try {
resultCode = z.deflate(JZlib.Z_SYNC_FLUSH);
} finally {
in.skipBytes(z.next_in_index - oldNextInIndex);
}
if (resultCode != JZlib.Z_OK) {
ZlibUtil.fail(z, "compression failure", resultCode);
}
int outputLength = z.next_out_index - oldNextOutIndex;
if (outputLength > 0) {
out.writerIndex(out.writerIndex() + outputLength);
}
} finally {
// Deference the external references explicitly to tell the VM that
// the allocated byte arrays are temporary so that the call stack
// can be utilized.
// I'm not sure if the modern VMs do this optimization though.
z.next_in = null;
z.next_out = null;
}
}
Domain
Subdomains
Source
Frequently Asked Questions
What does encode() do?
encode() is a function in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/JZlibEncoder.java.
Where is encode() defined?
encode() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/JZlibEncoder.java at line 262.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free