public class ZlibEncoder extends OneToOneStrictEncoder implements LifeCycleAwareChannelHandler
ChannelBuffer using the deflate algorithm.ChannelHandler.Sharable| Modifier and Type | Field and Description |
|---|---|
private ChannelHandlerContext |
ctx |
private static byte[] |
EMPTY_ARRAY |
private java.util.concurrent.atomic.AtomicBoolean |
finished |
private int |
wrapperOverhead |
private com.jcraft.jzlib.ZStream |
z |
| Constructor and Description |
|---|
ZlibEncoder()
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). |
ZlibEncoder(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. |
ZlibEncoder(int compressionLevel)
Creates a new zlib encoder with the specified
compressionLevel,
default window bits (15), default memory level (8),
and the default wrapper (ZlibWrapper.ZLIB). |
ZlibEncoder(int compressionLevel,
byte[] dictionary)
Creates a new zlib encoder with the specified
compressionLevel,
default window bits (15), default memory level (8),
and the specified preset dictionary. |
ZlibEncoder(int compressionLevel,
int windowBits,
int memLevel,
byte[] dictionary)
Creates a new zlib encoder with the specified
compressionLevel,
the specified windowBits, the specified memLevel,
and the specified preset dictionary. |
ZlibEncoder(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. |
ZlibEncoder(ZlibWrapper wrapper,
int compressionLevel)
Creates a new zlib encoder with the specified
compressionLevel,
default window bits (15), default memory level (8),
and the specified wrapper. |
ZlibEncoder(ZlibWrapper wrapper,
int compressionLevel,
int windowBits,
int memLevel)
Creates a new zlib encoder with the specified
compressionLevel,
the specified windowBits, the specified memLevel, and
the specified wrapper. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterAdd(ChannelHandlerContext ctx) |
void |
afterRemove(ChannelHandlerContext ctx) |
void |
beforeAdd(ChannelHandlerContext ctx) |
void |
beforeRemove(ChannelHandlerContext ctx) |
ChannelFuture |
close() |
protected java.lang.Object |
encode(ChannelHandlerContext ctx,
Channel channel,
java.lang.Object msg)
Transforms the specified message into another message and return the
transformed message.
|
private ChannelFuture |
finishEncode(ChannelHandlerContext ctx,
ChannelEvent evt) |
void |
handleDownstream(ChannelHandlerContext ctx,
ChannelEvent evt)
Handles the specified downstream event.
|
boolean |
isClosed() |
doEncodeprivate static final byte[] EMPTY_ARRAY
private final int wrapperOverhead
private final com.jcraft.jzlib.ZStream z
private final java.util.concurrent.atomic.AtomicBoolean finished
private volatile ChannelHandlerContext ctx
public ZlibEncoder()
6),
default window bits (15), default memory level (8),
and the default wrapper (ZlibWrapper.ZLIB).CompressionException - if failed to initialize zlibpublic ZlibEncoder(int compressionLevel)
compressionLevel,
default window bits (15), default memory level (8),
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 ZlibEncoder(ZlibWrapper wrapper)
6),
default window bits (15), default memory level (8),
and the specified wrapper.CompressionException - if failed to initialize zlibpublic ZlibEncoder(ZlibWrapper wrapper, int compressionLevel)
compressionLevel,
default window bits (15), default memory level (8),
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 ZlibEncoder(ZlibWrapper wrapper, int compressionLevel, int windowBits, int memLevel)
compressionLevel,
the specified windowBits, the specified memLevel, 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.windowBits - The base two logarithm of the size of the history buffer. The
value should be in the range 9 to 15 inclusive.
Larger values result in better compression at the expense of
memory usage. The default value is 15.memLevel - How much memory should be allocated for the internal compression
state. 1 uses minimum memory and 9 uses maximum
memory. Larger values result in better and faster compression
at the expense of memory usage. The default value is 8CompressionException - if failed to initialize zlibpublic ZlibEncoder(byte[] dictionary)
6),
default window bits (15), default memory level (8),
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 ZlibEncoder(int compressionLevel,
byte[] dictionary)
compressionLevel,
default window bits (15), default memory level (8),
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 ZlibEncoder(int compressionLevel,
int windowBits,
int memLevel,
byte[] dictionary)
compressionLevel,
the specified windowBits, the specified memLevel,
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.windowBits - The base two logarithm of the size of the history buffer. The
value should be in the range 9 to 15 inclusive.
Larger values result in better compression at the expense of
memory usage. The default value is 15.memLevel - How much memory should be allocated for the internal compression
state. 1 uses minimum memory and 9 uses maximum
memory. Larger values result in better and faster compression
at the expense of memory usage. The default value is 8dictionary - the preset dictionaryCompressionException - if failed to initialize zlibpublic ChannelFuture close()
public boolean isClosed()
protected java.lang.Object encode(ChannelHandlerContext ctx, Channel channel, java.lang.Object msg) throws java.lang.Exception
OneToOneEncodernull, unlike
you can in OneToOneDecoder.decode(ChannelHandlerContext, Channel, Object);
you must return something, at least ChannelBuffers.EMPTY_BUFFER.encode in class OneToOneEncoderjava.lang.Exceptionpublic void handleDownstream(ChannelHandlerContext ctx, ChannelEvent evt) throws java.lang.Exception
ChannelDownstreamHandlerhandleDownstream in interface ChannelDownstreamHandlerhandleDownstream in class OneToOneEncoderctx - the context object for this handlerevt - the downstream event to process or interceptjava.lang.Exceptionprivate ChannelFuture finishEncode(ChannelHandlerContext ctx, ChannelEvent evt)
public void beforeAdd(ChannelHandlerContext ctx) throws java.lang.Exception
beforeAdd in interface LifeCycleAwareChannelHandlerjava.lang.Exceptionpublic void afterAdd(ChannelHandlerContext ctx) throws java.lang.Exception
afterAdd in interface LifeCycleAwareChannelHandlerjava.lang.Exceptionpublic void beforeRemove(ChannelHandlerContext ctx) throws java.lang.Exception
beforeRemove in interface LifeCycleAwareChannelHandlerjava.lang.Exceptionpublic void afterRemove(ChannelHandlerContext ctx) throws java.lang.Exception
afterRemove in interface LifeCycleAwareChannelHandlerjava.lang.Exception