ZlibDecoder Class — netty Architecture
Architecture documentation for the ZlibDecoder class in ZlibDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD c6c9a2c2_7ac0_219d_db9e_bb2f3577a8fa["ZlibDecoder"] 9b8e0618_872b_aac7_1917_b1dc64cf886f["ZlibDecoder.java"] c6c9a2c2_7ac0_219d_db9e_bb2f3577a8fa -->|defined in| 9b8e0618_872b_aac7_1917_b1dc64cf886f ecbbb7a0_4b76_58da_a86a_f7755152a9f0["ZlibDecoder()"] c6c9a2c2_7ac0_219d_db9e_bb2f3577a8fa -->|method| ecbbb7a0_4b76_58da_a86a_f7755152a9f0 49b2ee61_2ceb_1a3c_2c74_9a7aa97ed482["isClosed()"] c6c9a2c2_7ac0_219d_db9e_bb2f3577a8fa -->|method| 49b2ee61_2ceb_1a3c_2c74_9a7aa97ed482 d4e9d28c_64e9_4aca_f5d6_26754b244701["ByteBuf()"] c6c9a2c2_7ac0_219d_db9e_bb2f3577a8fa -->|method| d4e9d28c_64e9_4aca_f5d6_26754b244701 247b1bbd_6674_8b74_87db_807943f1eeb6["decompressionBufferExhausted()"] c6c9a2c2_7ac0_219d_db9e_bb2f3577a8fa -->|method| 247b1bbd_6674_8b74_87db_807943f1eeb6
Relationship Graph
Source Code
codec-compression/src/main/java/io/netty/handler/codec/compression/ZlibDecoder.java lines 28–95
public abstract class ZlibDecoder extends ByteToMessageDecoder {
/**
* Maximum allowed size of the decompression buffer.
*/
protected final int maxAllocation;
/**
* Same as {@link #ZlibDecoder(int)} with maxAllocation = 0.
*/
public ZlibDecoder() {
this(0);
}
/**
* Construct a new ZlibDecoder.
* @param maxAllocation
* Maximum size of the decompression buffer. Must be >= 0.
* If zero, maximum size is decided by the {@link ByteBufAllocator}.
*/
public ZlibDecoder(int maxAllocation) {
this.maxAllocation = checkPositiveOrZero(maxAllocation, "maxAllocation");
}
/**
* Returns {@code true} if and only if the end of the compressed stream
* has been reached.
*/
public abstract boolean isClosed();
/**
* Allocate or expand the decompression buffer, without exceeding the maximum allocation.
* Calls {@link #decompressionBufferExhausted(ByteBuf)} if the buffer is full and cannot be expanded further.
*/
protected ByteBuf prepareDecompressBuffer(ChannelHandlerContext ctx, ByteBuf buffer, int preferredSize) {
if (buffer == null) {
if (maxAllocation == 0) {
return ctx.alloc().heapBuffer(preferredSize);
}
return ctx.alloc().heapBuffer(Math.min(preferredSize, maxAllocation), maxAllocation);
}
// this always expands the buffer if possible, even if the expansion is less than preferredSize
// we throw the exception only if the buffer could not be expanded at all
// this means that one final attempt to deserialize will always be made with the buffer at maxAllocation
if (buffer.ensureWritable(preferredSize, true) == 1) {
// buffer must be consumed so subclasses don't add it to output
// we therefore duplicate it when calling decompressionBufferExhausted() to guarantee non-interference
// but wait until after to consume it so the subclass can tell how much output is really in the buffer
decompressionBufferExhausted(buffer.duplicate());
buffer.skipBytes(buffer.readableBytes());
throw new DecompressionException("Decompression buffer has reached maximum size: " + buffer.maxCapacity());
}
return buffer;
}
/**
* Called when the decompression buffer cannot be expanded further.
* Default implementation is a no-op, but subclasses can override in case they want to
* do something before the {@link DecompressionException} is thrown, such as log the
* data that was decompressed so far.
*/
protected void decompressionBufferExhausted(ByteBuf buffer) {
}
}
Source
Frequently Asked Questions
What is the ZlibDecoder class?
ZlibDecoder is a class in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/ZlibDecoder.java.
Where is ZlibDecoder defined?
ZlibDecoder is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/ZlibDecoder.java at line 28.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free