public class JdkZlibEncoder extends ZlibEncoder
ByteBuf using the deflate algorithm.ChannelHandler.Sharable| Modifier and Type | Field and Description |
|---|---|
private java.util.zip.CRC32 |
crc |
private ChannelHandlerContext |
ctx |
private java.util.zip.Deflater |
deflater |
private boolean |
finished |
private static byte[] |
gzipHeader |
private ZlibWrapper |
wrapper |
private boolean |
writeHeader |
| Constructor and Description |
|---|
JdkZlibEncoder()
Creates a new zlib encoder with the default compression level (
6)
and the default wrapper (ZlibWrapper.ZLIB). |
JdkZlibEncoder(byte[] dictionary)
Creates a new zlib encoder with the default compression level (
6)
and the specified preset dictionary. |
JdkZlibEncoder(int compressionLevel)
Creates a new zlib encoder with the specified
compressionLevel
and the default wrapper (ZlibWrapper.ZLIB). |
JdkZlibEncoder(int compressionLevel,
byte[] dictionary)
Creates a new zlib encoder with the specified
compressionLevel
and the specified preset dictionary. |
JdkZlibEncoder(ZlibWrapper wrapper)
Creates a new zlib encoder with the default compression level (
6)
and the specified wrapper. |
JdkZlibEncoder(ZlibWrapper wrapper,
int compressionLevel)
Creates a new zlib encoder with the specified
compressionLevel
and the specified wrapper. |
| Modifier and Type | Method and Description |
|---|---|
protected ByteBuf |
allocateBuffer(ChannelHandlerContext ctx,
ByteBuf msg,
boolean preferDirect)
Allocate a
ByteBuf which will be used as argument of #encode(ChannelHandlerContext, I, ByteBuf). |
ChannelFuture |
close()
Close this
ZlibEncoder and so finish the encoding. |
void |
close(ChannelHandlerContext ctx,
ChannelPromise promise)
Calls
ChannelOutboundInvoker.close(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline. |
ChannelFuture |
close(ChannelPromise promise)
Close this
ZlibEncoder and so finish the encoding. |
private ChannelHandlerContext |
ctx() |
private void |
deflate(ByteBuf out) |
protected void |
encode(ChannelHandlerContext ctx,
ByteBuf uncompressed,
ByteBuf out)
Encode a message into a
ByteBuf. |
private ChannelFuture |
finishEncode(ChannelHandlerContext ctx,
ChannelPromise promise) |
void |
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
boolean |
isClosed()
Returns
true if and only if the end of the compressed stream
has been reached. |
acceptOutboundMessage, isPreferDirect, writebind, connect, deregister, disconnect, flush, readensureNotSharable, exceptionCaught, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaught, handlerRemovedprivate final ZlibWrapper wrapper
private final java.util.zip.Deflater deflater
private volatile boolean finished
private volatile ChannelHandlerContext ctx
private final java.util.zip.CRC32 crc
private static final byte[] gzipHeader
private boolean writeHeader
public JdkZlibEncoder()
6)
and the default wrapper (ZlibWrapper.ZLIB).CompressionException - if failed to initialize zlibpublic JdkZlibEncoder(int compressionLevel)
compressionLevel
and the default wrapper (ZlibWrapper.ZLIB).compressionLevel - 1 yields the fastest compression and 9 yields the
best compression. 0 means no compression. The default
compression level is 6.CompressionException - if failed to initialize zlibpublic JdkZlibEncoder(ZlibWrapper wrapper)
6)
and the specified wrapper.CompressionException - if failed to initialize zlibpublic JdkZlibEncoder(ZlibWrapper wrapper, int compressionLevel)
compressionLevel
and the specified wrapper.compressionLevel - 1 yields the fastest compression and 9 yields the
best compression. 0 means no compression. The default
compression level is 6.CompressionException - if failed to initialize zlibpublic JdkZlibEncoder(byte[] dictionary)
6)
and the specified preset dictionary. The wrapper is always
ZlibWrapper.ZLIB because it is the only format that supports
the preset dictionary.dictionary - the preset dictionaryCompressionException - if failed to initialize zlibpublic JdkZlibEncoder(int compressionLevel,
byte[] dictionary)
compressionLevel
and the specified preset dictionary. The wrapper is always
ZlibWrapper.ZLIB because it is the only format that supports
the preset dictionary.compressionLevel - 1 yields the fastest compression and 9 yields the
best compression. 0 means no compression. The default
compression level is 6.dictionary - the preset dictionaryCompressionException - if failed to initialize zlibpublic ChannelFuture close()
ZlibEncoderZlibEncoder and so finish the encoding.
The returned ChannelFuture will be notified once the
operation completes.close in class ZlibEncoderpublic ChannelFuture close(ChannelPromise promise)
ZlibEncoderZlibEncoder and so finish the encoding.
The given ChannelFuture will be notified once the operation
completes and will also be returned.close in class ZlibEncoderprivate ChannelHandlerContext ctx()
public boolean isClosed()
ZlibEncodertrue if and only if the end of the compressed stream
has been reached.isClosed in class ZlibEncoderprotected void encode(ChannelHandlerContext ctx, ByteBuf uncompressed, ByteBuf out) throws java.lang.Exception
MessageToByteEncoderByteBuf. This method will be called for each written message that can be handled
by this encoder.encode in class MessageToByteEncoder<ByteBuf>ctx - the ChannelHandlerContext which this MessageToByteEncoder belongs touncompressed - the message to encodeout - the ByteBuf into which the encoded message will be writtenjava.lang.Exception - is thrown if an error occursprotected final ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws java.lang.Exception
MessageToByteEncoderByteBuf 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.allocateBuffer in class MessageToByteEncoder<ByteBuf>java.lang.Exceptionpublic void close(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
ChannelOutboundHandlerAdapterChannelOutboundInvoker.close(ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.close in interface ChannelOutboundHandlerclose in class ChannelOutboundHandlerAdapterctx - the ChannelHandlerContext for which the close operation is madepromise - the ChannelPromise to notify once the operation completesjava.lang.Exception - thrown if an error occursprivate ChannelFuture finishEncode(ChannelHandlerContext ctx, ChannelPromise promise)
private void deflate(ByteBuf out)
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapterhandlerAdded in interface ChannelHandlerhandlerAdded in class ChannelHandlerAdapterjava.lang.Exception