Class JdkZlibEncoder
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelOutboundHandlerAdapter
-
- io.netty.handler.codec.MessageToByteEncoder<io.netty.buffer.ByteBuf>
-
- io.netty.handler.codec.compression.ZlibEncoder
-
- io.netty.handler.codec.compression.JdkZlibEncoder
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelOutboundHandler
public class JdkZlibEncoder extends ZlibEncoder
Compresses aByteBufusing the deflate algorithm.
-
-
Constructor Summary
Constructors Constructor Description JdkZlibEncoder()Creates a new zlib encoder with a compression level of (6) and the default wrapper (ZlibWrapper.ZLIB).JdkZlibEncoder(byte[] dictionary)Creates a new zlib encoder with a compression level of (6) and the specified preset dictionary.JdkZlibEncoder(int compressionLevel)Creates a new zlib encoder with the specifiedcompressionLeveland the default wrapper (ZlibWrapper.ZLIB).JdkZlibEncoder(int compressionLevel, byte[] dictionary)Creates a new zlib encoder with the specifiedcompressionLeveland the specified preset dictionary.JdkZlibEncoder(ZlibWrapper wrapper)Creates a new zlib encoder with a compression level of (6) and the specified wrapper.JdkZlibEncoder(ZlibWrapper wrapper, int compressionLevel)Creates a new zlib encoder with the specifiedcompressionLeveland the specified wrapper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected io.netty.buffer.ByteBufallocateBuffer(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, boolean preferDirect)io.netty.channel.ChannelFutureclose()Close thisZlibEncoderand so finish the encoding.voidclose(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)io.netty.channel.ChannelFutureclose(io.netty.channel.ChannelPromise promise)Close thisZlibEncoderand so finish the encoding.protected voidencode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf uncompressed, io.netty.buffer.ByteBuf out)voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx)booleanisClosed()Returnstrueif and only if the end of the compressed stream has been reached.-
Methods inherited from class io.netty.handler.codec.MessageToByteEncoder
acceptOutboundMessage, isPreferDirect, write
-
Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter
bind, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerRemoved, isSharable
-
-
-
-
Constructor Detail
-
JdkZlibEncoder
public JdkZlibEncoder()
Creates a new zlib encoder with a compression level of (6) and the default wrapper (ZlibWrapper.ZLIB).- Throws:
CompressionException- if failed to initialize zlib
-
JdkZlibEncoder
public JdkZlibEncoder(int compressionLevel)
Creates a new zlib encoder with the specifiedcompressionLeveland 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
-
JdkZlibEncoder
public JdkZlibEncoder(ZlibWrapper wrapper)
Creates a new zlib encoder with a compression level of (6) and the specified wrapper.- Throws:
CompressionException- if failed to initialize zlib
-
JdkZlibEncoder
public JdkZlibEncoder(ZlibWrapper wrapper, int compressionLevel)
Creates a new zlib encoder with the specifiedcompressionLeveland the specified wrapper.- Parameters:
compressionLevel-1yields the fastest compression and9yields the best compression.0means no compression. The default compression level can be set as-1which correlates to the underlyingDeflater.DEFAULT_COMPRESSIONlevel.- Throws:
CompressionException- if failed to initialize zlib
-
JdkZlibEncoder
public JdkZlibEncoder(byte[] dictionary)
Creates a new zlib encoder with a compression level of (6) 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
-
JdkZlibEncoder
public JdkZlibEncoder(int compressionLevel, byte[] dictionary)Creates a new zlib encoder with the specifiedcompressionLeveland 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 can be set as-1which correlates to the underlyingDeflater.DEFAULT_COMPRESSIONlevel.dictionary- the preset dictionary- Throws:
CompressionException- if failed to initialize zlib
-
-
Method Detail
-
close
public io.netty.channel.ChannelFuture close()
Description copied from class:ZlibEncoderClose thisZlibEncoderand so finish the encoding. The returnedChannelFuturewill be notified once the operation completes.- Specified by:
closein classZlibEncoder
-
close
public io.netty.channel.ChannelFuture close(io.netty.channel.ChannelPromise promise)
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
protected void encode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf uncompressed, io.netty.buffer.ByteBuf out) throws Exception- Specified by:
encodein classio.netty.handler.codec.MessageToByteEncoder<io.netty.buffer.ByteBuf>- Throws:
Exception
-
allocateBuffer
protected final io.netty.buffer.ByteBuf allocateBuffer(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, boolean preferDirect) throws Exception- Overrides:
allocateBufferin classio.netty.handler.codec.MessageToByteEncoder<io.netty.buffer.ByteBuf>- Throws:
Exception
-
close
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
closein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
closein classio.netty.channel.ChannelOutboundHandlerAdapter- Throws:
Exception
-
-