Class ZlibEncoder
- java.lang.Object
-
- org.jboss.netty.handler.codec.oneone.OneToOneEncoder
-
- org.jboss.netty.handler.codec.oneone.OneToOneStrictEncoder
-
- org.jboss.netty.handler.codec.compression.ZlibEncoder
-
- All Implemented Interfaces:
ChannelDownstreamHandler,ChannelHandler,LifeCycleAwareChannelHandler
public class ZlibEncoder extends OneToOneStrictEncoder implements LifeCycleAwareChannelHandler
Compresses aChannelBufferusing the deflate algorithm.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description private ChannelHandlerContextctxprivate static byte[]EMPTY_ARRAYprivate java.util.concurrent.atomic.AtomicBooleanfinishedprivate intwrapperOverheadprivate com.jcraft.jzlib.ZStreamz
-
Constructor Summary
Constructors Constructor 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 specifiedcompressionLevel, 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 specifiedcompressionLevel, 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 specifiedcompressionLevel, the specifiedwindowBits, the specifiedmemLevel, 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 specifiedcompressionLevel, 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 specifiedcompressionLevel, the specifiedwindowBits, the specifiedmemLevel, and the specified wrapper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterAdd(ChannelHandlerContext ctx)voidafterRemove(ChannelHandlerContext ctx)voidbeforeAdd(ChannelHandlerContext ctx)voidbeforeRemove(ChannelHandlerContext ctx)ChannelFutureclose()protected java.lang.Objectencode(ChannelHandlerContext ctx, Channel channel, java.lang.Object msg)Transforms the specified message into another message and return the transformed message.private ChannelFuturefinishEncode(ChannelHandlerContext ctx, ChannelEvent evt)voidhandleDownstream(ChannelHandlerContext ctx, ChannelEvent evt)Handles the specified downstream event.booleanisClosed()-
Methods inherited from class org.jboss.netty.handler.codec.oneone.OneToOneStrictEncoder
doEncode
-
-
-
-
Field Detail
-
EMPTY_ARRAY
private static final byte[] EMPTY_ARRAY
-
wrapperOverhead
private final int wrapperOverhead
-
z
private final com.jcraft.jzlib.ZStream z
-
finished
private final java.util.concurrent.atomic.AtomicBoolean finished
-
ctx
private volatile ChannelHandlerContext ctx
-
-
Constructor Detail
-
ZlibEncoder
public 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).- Throws:
CompressionException- if failed to initialize zlib
-
ZlibEncoder
public ZlibEncoder(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
-
ZlibEncoder
public 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.- Throws:
CompressionException- if failed to initialize zlib
-
ZlibEncoder
public ZlibEncoder(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-1yields the fastest compression and9yields the best compression.0means no compression. The default compression level is6.- Throws:
CompressionException- if failed to initialize zlib
-
ZlibEncoder
public ZlibEncoder(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-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
-
ZlibEncoder
public 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. 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
-
ZlibEncoder
public ZlibEncoder(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
-
ZlibEncoder
public ZlibEncoder(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 Detail
-
close
public ChannelFuture close()
-
isClosed
public boolean isClosed()
-
encode
protected java.lang.Object encode(ChannelHandlerContext ctx, Channel channel, java.lang.Object msg) throws java.lang.Exception
Description copied from class:OneToOneEncoderTransforms the specified message into another message and return the transformed message. Note that you can not returnnull, unlike you can inOneToOneDecoder.decode(ChannelHandlerContext, Channel, Object); you must return something, at leastChannelBuffers.EMPTY_BUFFER.- Specified by:
encodein classOneToOneEncoder- Throws:
java.lang.Exception
-
handleDownstream
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent evt) throws java.lang.Exception
Description copied from interface:ChannelDownstreamHandlerHandles the specified downstream event.- Specified by:
handleDownstreamin interfaceChannelDownstreamHandler- Overrides:
handleDownstreamin classOneToOneEncoder- Parameters:
ctx- the context object for this handlerevt- the downstream event to process or intercept- Throws:
java.lang.Exception
-
finishEncode
private ChannelFuture finishEncode(ChannelHandlerContext ctx, ChannelEvent evt)
-
beforeAdd
public void beforeAdd(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
beforeAddin interfaceLifeCycleAwareChannelHandler- Throws:
java.lang.Exception
-
afterAdd
public void afterAdd(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
afterAddin interfaceLifeCycleAwareChannelHandler- Throws:
java.lang.Exception
-
beforeRemove
public void beforeRemove(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
beforeRemovein interfaceLifeCycleAwareChannelHandler- Throws:
java.lang.Exception
-
afterRemove
public void afterRemove(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
afterRemovein interfaceLifeCycleAwareChannelHandler- Throws:
java.lang.Exception
-
-