Top Description Fields Constructors Methods
io.netty.handler.codec.compression

public Class JdkZlibEncoder

extends ZlibEncoder
Class Inheritance
Imports
io.netty.buffer.ByteBuf, io.netty.channel.ChannelFuture, .ChannelHandlerContext, .ChannelPromise, io.netty.util.concurrent.EventExecutor, .PromiseNotifier, io.netty.util.internal.EmptyArrays, .ObjectUtil, .PlatformDependent, .SuppressJava6Requirement, .SystemPropertyUtil, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.util.zip.CRC32, .Deflater

Compresses a ByteBuf using the deflate algorithm.

Field Summary

Modifier and TypeField and Description
private final CRC32
private volatile ChannelHandlerContext
private final Deflater
private volatile boolean
private static final byte[]
private static final InternalLogger
private static final int
MAX_INITIAL_OUTPUT_BUFFER_SIZE

Maximum initial size for temporary heap buffers used for the compressed output.

private static final int
MAX_INPUT_BUFFER_SIZE

Max size for temporary heap buffers used to copy input data to heap.

private final ZlibWrapper
private boolean

Constructor Summary

AccessConstructor and Description
public
JdkZlibEncoder()

Creates a new zlib encoder with the default compression level (6) and the default wrapper (ZlibWrapper#ZLIB).

public
JdkZlibEncoder(int
1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
compressionLevel
)

Creates a new zlib encoder with the specified compressionLevel and the default wrapper (ZlibWrapper#ZLIB).

public
JdkZlibEncoder(ZlibWrapper wrapper)

Creates a new zlib encoder with the default compression level (6) and the specified wrapper.

public
JdkZlibEncoder(ZlibWrapper wrapper, int
1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
compressionLevel
)

Creates a new zlib encoder with the specified compressionLevel and the specified wrapper.

public
JdkZlibEncoder(byte[]
the preset dictionary
dictionary
)

Creates a new zlib encoder with the default compression level (6) and the specified preset dictionary.

public
JdkZlibEncoder(int
1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
compressionLevel
,
byte[]
the preset dictionary
dictionary
)

Creates a new zlib encoder with the specified compressionLevel and the specified preset dictionary.

Method Summary

Modifier and TypeMethod and Description
protected final ByteBuf
public ChannelFuture
close()

Implements abstract io.netty.handler.codec.compression.ZlibEncoder.close.

Close this ZlibEncoder and so finish the encoding.
public ChannelFuture
close(final ChannelPromise promise)

Implements abstract io.netty.handler.codec.compression.ZlibEncoder.close.

Close this ZlibEncoder and so finish the encoding.
public void
close(final ChannelHandlerContext
the ChannelHandlerContext for which the close operation is made
ctx
,
final ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.close.

Implements io.netty.channel.ChannelOutboundHandler.close.

Calls ChannelHandlerContext#close(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
private ChannelHandlerContext
ctx()

private void
private void
protected void
encode(ChannelHandlerContext ctx, ByteBuf
the message to encode
uncompressed
,
ByteBuf
the ByteBuf into which the encoded message will be written
out
)

Implements abstract io.netty.handler.codec.MessageToByteEncoder.encode.

Encode a message into a ByteBuf.
private void
private ChannelFuture
public void
handlerAdded(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.
public boolean
isClosed()

Implements abstract io.netty.handler.codec.compression.ZlibEncoder.isClosed.

Returns true if and only if the end of the compressed stream has been reached.

Field Detail

crcback to summary
private final CRC32 crc
ctxback to summary
private volatile ChannelHandlerContext ctx
deflaterback to summary
private final Deflater deflater
finishedback to summary
private volatile boolean finished
gzipHeaderback to summary
private static final byte[] gzipHeader
loggerback to summary
private static final InternalLogger logger
MAX_INITIAL_OUTPUT_BUFFER_SIZEback to summary
private static final int MAX_INITIAL_OUTPUT_BUFFER_SIZE

Maximum initial size for temporary heap buffers used for the compressed output. Buffer may still grow beyond this if necessary.

MAX_INPUT_BUFFER_SIZEback to summary
private static final int MAX_INPUT_BUFFER_SIZE

Max size for temporary heap buffers used to copy input data to heap.

wrapperback to summary
private final ZlibWrapper wrapper
writeHeaderback to summary
private boolean writeHeader

Constructor Detail

JdkZlibEncoderback to summary
public JdkZlibEncoder()

Creates a new zlib encoder with the default compression level (6) and the default wrapper (ZlibWrapper#ZLIB).

Exceptions
CompressionException:
if failed to initialize zlib
JdkZlibEncoderback to summary
public JdkZlibEncoder(int compressionLevel)

Creates a new zlib encoder with the specified compressionLevel and the default wrapper (ZlibWrapper#ZLIB).

Parameters
compressionLevel:int

1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.

Exceptions
CompressionException:
if failed to initialize zlib
JdkZlibEncoderback to summary
public JdkZlibEncoder(ZlibWrapper wrapper)

Creates a new zlib encoder with the default compression level (6) and the specified wrapper.

Exceptions
CompressionException:
if failed to initialize zlib
JdkZlibEncoderback to summary
public JdkZlibEncoder(ZlibWrapper wrapper, int compressionLevel)

Creates a new zlib encoder with the specified compressionLevel and the specified wrapper.

Parameters
compressionLevel:int

1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.

Exceptions
CompressionException:
if failed to initialize zlib
JdkZlibEncoderback to summary
public JdkZlibEncoder(byte[] dictionary)

Creates a new zlib encoder with the default compression level (6) and the specified preset dictionary. The wrapper is always ZlibWrapper#ZLIB because it is the only format that supports the preset dictionary.

Parameters
dictionary:byte[]

the preset dictionary

Exceptions
CompressionException:
if failed to initialize zlib
JdkZlibEncoderback to summary
public JdkZlibEncoder(int compressionLevel, byte[] dictionary)

Creates a new zlib encoder with the specified compressionLevel and the specified preset dictionary. The wrapper is always ZlibWrapper#ZLIB because it is the only format that supports the preset dictionary.

Parameters
compressionLevel:int

1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.

dictionary:byte[]

the preset dictionary

Exceptions
CompressionException:
if failed to initialize zlib

Method Detail

allocateBufferback to summary
protected final ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws Exception

Overrides io.netty.handler.codec.MessageToByteEncoder.allocateBuffer.

Doc from io.netty.handler.codec.MessageToByteEncoder.allocateBuffer.

Allocate a ByteBuf which will be used as argument of encode(ChannelHandlerContext, I, ByteBuf). Sub-classes may override this method to return ByteBuf with a perfect matching initialCapacity.

Annotations
@Override
closeback to summary
public ChannelFuture close()

Implements abstract io.netty.handler.codec.compression.ZlibEncoder.close.

Doc from io.netty.handler.codec.compression.ZlibEncoder.close.

Close this ZlibEncoder and so finish the encoding. The returned ChannelFuture will be notified once the operation completes.

Annotations
@Override
closeback to summary
public ChannelFuture close(final ChannelPromise promise)

Implements abstract io.netty.handler.codec.compression.ZlibEncoder.close.

Doc from io.netty.handler.codec.compression.ZlibEncoder.close.

Close this ZlibEncoder and so finish the encoding. The given ChannelFuture will be notified once the operation completes and will also be returned.

Annotations
@Override
closeback to summary
public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.close.

Implements io.netty.channel.ChannelOutboundHandler.close.

Doc from io.netty.channel.ChannelOutboundHandlerAdapter.close.

Calls ChannelHandlerContext#close(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.close.

the ChannelHandlerContext for which the close operation is made

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.close.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.close.

thrown if an error occurs

ctxback to summary
private ChannelHandlerContext ctx()
deflateback to summary
private void deflate(ByteBuf out)
Annotations
@SuppressJava6Requirement
reason:Usage guarded by java version check
deflateJdk6back to summary
private void deflateJdk6(ByteBuf out)
encodeback to summary
protected void encode(ChannelHandlerContext ctx, ByteBuf uncompressed, ByteBuf out) throws Exception

Implements abstract io.netty.handler.codec.MessageToByteEncoder.encode.

Doc from io.netty.handler.codec.MessageToByteEncoder.encode.

Encode a message into a ByteBuf. This method will be called for each written message that can be handled by this encoder.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToByteEncoder belongs to

uncompressed:ByteBuf

the message to encode

out:ByteBuf

the ByteBuf into which the encoded message will be written

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
encodeSomeback to summary
private void encodeSome(ByteBuf in, ByteBuf out)
finishEncodeback to summary
private ChannelFuture finishEncode(final ChannelHandlerContext ctx, ChannelPromise promise)
handlerAddedback to summary
public void handlerAdded(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Doc from io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Annotations
@Override
isClosedback to summary
public boolean isClosed()

Implements abstract io.netty.handler.codec.compression.ZlibEncoder.isClosed.

Doc from io.netty.handler.codec.compression.ZlibEncoder.isClosed.

Returns true if and only if the end of the compressed stream has been reached.

Annotations
@Override