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
public class JZlibEncoder extends ZlibEncoder
Compresses aByteBuf
using the deflate algorithm.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Constructor Description 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
).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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ChannelFuture
close()
Close thisZlibEncoder
and so finish the encoding.void
close(ChannelHandlerContext ctx, ChannelPromise promise)
CallsChannelOutboundInvoker.close(ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
.ChannelFuture
close(ChannelPromise promise)
Close thisZlibEncoder
and so finish the encoding.protected void
encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out)
Encode a message into aByteBuf
.void
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.boolean
isClosed()
Returnstrue
if and only if the end of the compressed stream has been reached.-
Methods inherited from class io.netty.handler.codec.MessageToByteEncoder
acceptOutboundMessage, allocateBuffer, 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
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.channel.ChannelHandler
exceptionCaught, handlerRemoved
-
-
-
-
Constructor Detail
-
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
-1
yields the fastest compression and9
yields the best compression.0
means no compression. The default compression level is6
.- Throws:
CompressionException
- if failed to initialize zlib
-
JZlibEncoder
public 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.- Throws:
CompressionException
- if failed to initialize zlib
-
JZlibEncoder
public 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.- Parameters:
compressionLevel
-1
yields the fastest compression and9
yields the best compression.0
means no compression. The default compression level is6
.- Throws:
CompressionException
- if failed to initialize zlib
-
JZlibEncoder
public 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.- Parameters:
compressionLevel
-1
yields the fastest compression and9
yields the best compression.0
means 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 range9
to15
inclusive. 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.1
uses minimum memory and9
uses 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.ZLIB
because 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.ZLIB
because it is the only format that supports the preset dictionary.- Parameters:
compressionLevel
-1
yields the fastest compression and9
yields the best compression.0
means 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.ZLIB
because it is the only format that supports the preset dictionary.- Parameters:
compressionLevel
-1
yields the fastest compression and9
yields the best compression.0
means 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 range9
to15
inclusive. 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.1
uses minimum memory and9
uses maximum memory. Larger values result in better and faster compression at the expense of memory usage. The default value is8
dictionary
- the preset dictionary- Throws:
CompressionException
- if failed to initialize zlib
-
-
Method Detail
-
close
public ChannelFuture close()
Description copied from class:ZlibEncoder
Close thisZlibEncoder
and so finish the encoding. The returnedChannelFuture
will be notified once the operation completes.- Specified by:
close
in classZlibEncoder
-
close
public ChannelFuture close(ChannelPromise promise)
Description copied from class:ZlibEncoder
Close thisZlibEncoder
and so finish the encoding. The givenChannelFuture
will be notified once the operation completes and will also be returned.- Specified by:
close
in classZlibEncoder
-
isClosed
public boolean isClosed()
Description copied from class:ZlibEncoder
Returnstrue
if and only if the end of the compressed stream has been reached.- Specified by:
isClosed
in classZlibEncoder
-
encode
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws java.lang.Exception
Description copied from class:MessageToByteEncoder
Encode a message into aByteBuf
. This method will be called for each written message that can be handled by this encoder.- Specified by:
encode
in classMessageToByteEncoder<ByteBuf>
- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToByteEncoder
belongs toin
- the message to encodeout
- theByteBuf
into which the encoded message will be written- Throws:
java.lang.Exception
- is thrown if an error occurs
-
close
public void close(ChannelHandlerContext ctx, ChannelPromise promise)
Description copied from class:ChannelOutboundHandlerAdapter
CallsChannelOutboundInvoker.close(ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
close
in interfaceChannelOutboundHandler
- Overrides:
close
in classChannelOutboundHandlerAdapter
- Parameters:
ctx
- theChannelHandlerContext
for which the close operation is madepromise
- theChannelPromise
to notify once the operation completes
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerAdded
in interfaceChannelHandler
- Overrides:
handlerAdded
in classChannelHandlerAdapter
- Throws:
java.lang.Exception
-
-