Class JZlibEncoder
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelOutboundHandlerAdapter
io.netty.handler.codec.MessageToByteEncoder<ByteBuf>
io.netty.handler.codec.compression.ZlibEncoder
io.netty.handler.codec.compression.JZlibEncoder
- All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler
Compresses a
ByteBuf using the deflate algorithm.-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new zlib encoder with the default compression level (6), default window bits (15), default memory level (8), and the default wrapper (ZlibWrapper.ZLIB).JZlibEncoder(byte[] dictionary) Creates a new zlib encoder with the default compression level (6), default window bits (15), default memory level (8), and the specified preset dictionary.JZlibEncoder(int compressionLevel) Creates a new zlib encoder with the specifiedcompressionLevel, default window bits (15), default memory level (8), and the default wrapper (ZlibWrapper.ZLIB).JZlibEncoder(int compressionLevel, byte[] dictionary) Creates a new zlib encoder with the specifiedcompressionLevel, default window bits (15), default memory level (8), and the specified preset dictionary.JZlibEncoder(int compressionLevel, int windowBits, int memLevel, byte[] dictionary) Creates a new zlib encoder with the specifiedcompressionLevel, the specifiedwindowBits, the specifiedmemLevel, and the specified preset dictionary.JZlibEncoder(ZlibWrapper wrapper) Creates a new zlib encoder with the default compression level (6), default window bits (15), default memory level (8), and the specified wrapper.JZlibEncoder(ZlibWrapper wrapper, int compressionLevel) Creates a new zlib encoder with the specifiedcompressionLevel, default window bits (15), default memory level (8), and the specified wrapper.JZlibEncoder(ZlibWrapper wrapper, int compressionLevel, int windowBits, int memLevel) Creates a new zlib encoder with the specifiedcompressionLevel, the specifiedwindowBits, the specifiedmemLevel, and the specified wrapper. -
Method Summary
Modifier and TypeMethodDescriptionclose()Close thisZlibEncoderand so finish the encoding.voidclose(ChannelHandlerContext ctx, ChannelPromise promise) CallsChannelOutboundInvoker.close(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline.close(ChannelPromise promise) Close thisZlibEncoderand so finish the encoding.protected voidencode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) Encode a message into aByteBuf.voidDo nothing by default, sub-classes may override this method.booleanisClosed()Returnstrueif and only if the end of the compressed stream has been reached.Methods inherited from class MessageToByteEncoder
acceptOutboundMessage, allocateBuffer, isPreferDirect, writeMethods inherited from class ChannelOutboundHandlerAdapter
bind, connect, deregister, disconnect, flush, readMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerRemoved, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChannelHandler
exceptionCaught, handlerRemoved
-
Constructor Details
-
JZlibEncoder
public JZlibEncoder()Creates a new zlib encoder with the default compression level (6), default window bits (15), default memory level (8), and the default wrapper (ZlibWrapper.ZLIB).- Throws:
CompressionException- if failed to initialize zlib
-
JZlibEncoder
public JZlibEncoder(int compressionLevel) Creates a new zlib encoder with the specifiedcompressionLevel, default window bits (15), default memory level (8), and the default wrapper (ZlibWrapper.ZLIB).- Parameters:
compressionLevel-1yields the fastest compression and9yields the best compression.0means no compression. The default compression level is6.- Throws:
CompressionException- if failed to initialize zlib
-
JZlibEncoder
Creates a new zlib encoder with the default compression level (6), default window bits (15), default memory level (8), and the specified wrapper.- Throws:
CompressionException- if failed to initialize zlib
-
JZlibEncoder
Creates a new zlib encoder with the specifiedcompressionLevel, default window bits (15), default memory level (8), and the specified wrapper.- Parameters:
compressionLevel-1yields the fastest compression and9yields the best compression.0means no compression. The default compression level is6.- Throws:
CompressionException- if failed to initialize zlib
-
JZlibEncoder
Creates a new zlib encoder with the specifiedcompressionLevel, the specifiedwindowBits, the specifiedmemLevel, and the specified wrapper.- Parameters:
compressionLevel-1yields the fastest compression and9yields the best compression.0means no compression. The default compression level is6.windowBits- The base two logarithm of the size of the history buffer. The value should be in the range9to15inclusive. Larger values result in better compression at the expense of memory usage. The default value is15.memLevel- How much memory should be allocated for the internal compression state.1uses minimum memory and9uses maximum memory. Larger values result in better and faster compression at the expense of memory usage. The default value is8- Throws:
CompressionException- if failed to initialize zlib
-
JZlibEncoder
public JZlibEncoder(byte[] dictionary) Creates a new zlib encoder with the default compression level (6), default window bits (15), default memory level (8), and the specified preset dictionary. The wrapper is alwaysZlibWrapper.ZLIBbecause it is the only format that supports the preset dictionary.- Parameters:
dictionary- the preset dictionary- Throws:
CompressionException- if failed to initialize zlib
-
JZlibEncoder
public JZlibEncoder(int compressionLevel, byte[] dictionary) Creates a new zlib encoder with the specifiedcompressionLevel, default window bits (15), default memory level (8), and the specified preset dictionary. The wrapper is alwaysZlibWrapper.ZLIBbecause it is the only format that supports the preset dictionary.- Parameters:
compressionLevel-1yields the fastest compression and9yields the best compression.0means no compression. The default compression level is6.dictionary- the preset dictionary- Throws:
CompressionException- if failed to initialize zlib
-
JZlibEncoder
public JZlibEncoder(int compressionLevel, int windowBits, int memLevel, byte[] dictionary) Creates a new zlib encoder with the specifiedcompressionLevel, the specifiedwindowBits, the specifiedmemLevel, and the specified preset dictionary. The wrapper is alwaysZlibWrapper.ZLIBbecause it is the only format that supports the preset dictionary.- Parameters:
compressionLevel-1yields the fastest compression and9yields the best compression.0means no compression. The default compression level is6.windowBits- The base two logarithm of the size of the history buffer. The value should be in the range9to15inclusive. Larger values result in better compression at the expense of memory usage. The default value is15.memLevel- How much memory should be allocated for the internal compression state.1uses minimum memory and9uses maximum memory. Larger values result in better and faster compression at the expense of memory usage. The default value is8dictionary- the preset dictionary- Throws:
CompressionException- if failed to initialize zlib
-
-
Method Details
-
close
Description copied from class:ZlibEncoderClose thisZlibEncoderand so finish the encoding. The returnedChannelFuturewill be notified once the operation completes.- Specified by:
closein classZlibEncoder
-
close
Description copied from class:ZlibEncoderClose thisZlibEncoderand so finish the encoding. The givenChannelFuturewill be notified once the operation completes and will also be returned.- Specified by:
closein classZlibEncoder
-
isClosed
public boolean isClosed()Description copied from class:ZlibEncoderReturnstrueif and only if the end of the compressed stream has been reached.- Specified by:
isClosedin classZlibEncoder
-
encode
Description copied from class:MessageToByteEncoderEncode a message into aByteBuf. This method will be called for each written message that can be handled by this encoder.- Specified by:
encodein classMessageToByteEncoder<ByteBuf>- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToByteEncoderbelongs toin- the message to encodeout- theByteBufinto which the encoded message will be written- Throws:
Exception- is thrown if an error occurs
-
close
Description copied from class:ChannelOutboundHandlerAdapterCallsChannelOutboundInvoker.close(ChannelPromise)to forward to the nextChannelOutboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
closein interfaceChannelOutboundHandler- Overrides:
closein classChannelOutboundHandlerAdapter- Parameters:
ctx- theChannelHandlerContextfor which the close operation is madepromise- theChannelPromiseto notify once the operation completes
-
handlerAdded
Description copied from class:ChannelHandlerAdapterDo nothing by default, sub-classes may override this method.- Specified by:
handlerAddedin interfaceChannelHandler- Overrides:
handlerAddedin classChannelHandlerAdapter- Throws:
Exception
-