Class JdkZlibEncoder
- java.lang.Object
-
- org.jboss.netty.handler.codec.oneone.OneToOneEncoder
-
- org.jboss.netty.handler.codec.oneone.OneToOneStrictEncoder
-
- org.jboss.netty.handler.codec.compression.JdkZlibEncoder
-
- All Implemented Interfaces:
ChannelDownstreamHandler,ChannelHandler,LifeCycleAwareChannelHandler
public class JdkZlibEncoder 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
-
-
Constructor Summary
Constructors Constructor Description JdkZlibEncoder()Creates a new zlib encoder with the default compression level (6) and the default wrapper (ZlibWrapper.ZLIB).JdkZlibEncoder(byte[] dictionary)Creates a new zlib encoder with the default compression level (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 the default compression level (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 voidafterAdd(ChannelHandlerContext ctx)voidafterRemove(ChannelHandlerContext ctx)voidbeforeAdd(ChannelHandlerContext ctx)voidbeforeRemove(ChannelHandlerContext ctx)ChannelFutureclose()protected Objectencode(ChannelHandlerContext ctx, Channel channel, Object msg)Transforms the specified message into another message and return the transformed message.voidhandleDownstream(ChannelHandlerContext ctx, ChannelEvent evt)Handles the specified downstream event.booleanisClosed()-
Methods inherited from class org.jboss.netty.handler.codec.oneone.OneToOneStrictEncoder
doEncode
-
-
-
-
Constructor Detail
-
JdkZlibEncoder
public JdkZlibEncoder()
Creates a new zlib encoder with the default compression level (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 the default compression level (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 is6.- Throws:
CompressionException- if failed to initialize zlib
-
JdkZlibEncoder
public JdkZlibEncoder(byte[] dictionary)
Creates a new zlib encoder with the default compression level (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 is6.dictionary- the preset dictionary- Throws:
CompressionException- if failed to initialize zlib
-
-
Method Detail
-
close
public ChannelFuture close()
-
isClosed
public boolean isClosed()
-
encode
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws 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:
Exception
-
handleDownstream
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent evt) throws 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:
Exception
-
beforeAdd
public void beforeAdd(ChannelHandlerContext ctx) throws Exception
- Specified by:
beforeAddin interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
afterAdd
public void afterAdd(ChannelHandlerContext ctx) throws Exception
- Specified by:
afterAddin interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
beforeRemove
public void beforeRemove(ChannelHandlerContext ctx) throws Exception
- Specified by:
beforeRemovein interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
afterRemove
public void afterRemove(ChannelHandlerContext ctx) throws Exception
- Specified by:
afterRemovein interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
-