Class CompressionFilter
- All Implemented Interfaces:
org.apache.mina.common.IoFilter
IoFilter which compresses all data using
JZlib.
Support for the LZW (DLCZ) algorithm is also planned.
This filter only supports compression using the PARTIAL FLUSH method, since that is the only method useful when doing stream level compression.
This filter supports compression/decompression of the input and output channels selectively. It can also be enabled/disabled on the fly.
This filter does not discard the zlib objects, keeping them around for the entire life of the filter. This is because the zlib dictionary needs to be built up over time, which is used during compression and decompression. Over time, as repetitive data is sent over the wire, the compression efficiency steadily increases.
Note that the zlib header is written only once. It is not necessary that the data received after processing by this filter may not be complete due to packet fragmentation.
It goes without saying that the other end of this stream should also have a compatible compressor/decompressor using the same algorithm.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.mina.common.IoFilter
org.apache.mina.common.IoFilter.NextFilter, org.apache.mina.common.IoFilter.WriteRequest -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default compression level used.static final intMax compression level.static final intProvides the best speed at the price of a low compression ratio.static final intNo compression done on the data.static final StringA flag that allows you to disable compression once. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance which compresses outboud data and decompresses inbound data with default compression level.CompressionFilter(boolean compressInbound, boolean compressOutbound, int compressionLevel) Creates a new instance.CompressionFilter(int compressionLevel) Creates a new instance which compresses outboud data and decompresses inbound data with the specified compressionLevel. -
Method Summary
Modifier and TypeMethodDescriptionvoidfilterWrite(org.apache.mina.common.IoFilter.NextFilter nextFilter, org.apache.mina.common.IoSession session, org.apache.mina.common.IoFilter.WriteRequest writeRequest) booleanReturns true if incoming data is being compressed.booleanReturns true if the filter is compressing data being written.voidmessageReceived(org.apache.mina.common.IoFilter.NextFilter nextFilter, org.apache.mina.common.IoSession session, Object message) voidonPostRemove(org.apache.mina.common.IoFilterChain parent, String name, org.apache.mina.common.IoFilter.NextFilter nextFilter) voidonPreAdd(org.apache.mina.common.IoFilterChain parent, String name, org.apache.mina.common.IoFilter.NextFilter nextFilter) voidsetCompressInbound(boolean compressInbound) Sets if incoming data has to be compressed.voidsetCompressOutbound(boolean compressOutbound) Set if outgoing data has to be compressed.Methods inherited from class org.apache.mina.common.IoFilterAdapter
destroy, exceptionCaught, filterClose, init, messageSent, onPostAdd, onPreRemove, sessionClosed, sessionCreated, sessionIdle, sessionOpened
-
Field Details
-
COMPRESSION_MAX
public static final int COMPRESSION_MAXMax compression level. Will give the highest compression ratio, but will also take more cpu time and is the slowest.- See Also:
-
COMPRESSION_MIN
public static final int COMPRESSION_MINProvides the best speed at the price of a low compression ratio.- See Also:
-
COMPRESSION_NONE
public static final int COMPRESSION_NONENo compression done on the data.- See Also:
-
COMPRESSION_DEFAULT
public static final int COMPRESSION_DEFAULTThe default compression level used. Provides the best balance between speed and compression- See Also:
-
DISABLE_COMPRESSION_ONCE
A flag that allows you to disable compression once.
-
-
Constructor Details
-
CompressionFilter
public CompressionFilter()Creates a new instance which compresses outboud data and decompresses inbound data with default compression level. -
CompressionFilter
public CompressionFilter(int compressionLevel) Creates a new instance which compresses outboud data and decompresses inbound data with the specified compressionLevel.- Parameters:
compressionLevel- the level of compression to be used. Must be one ofCOMPRESSION_DEFAULT,COMPRESSION_MAX,COMPRESSION_MIN, andCOMPRESSION_NONE.
-
CompressionFilter
public CompressionFilter(boolean compressInbound, boolean compressOutbound, int compressionLevel) Creates a new instance.- Parameters:
compressInbound- true if data read is to be decompressedcompressOutbound- true if data written is to be compressedcompressionLevel- the level of compression to be used. Must be one ofCOMPRESSION_DEFAULT,COMPRESSION_MAX,COMPRESSION_MIN, andCOMPRESSION_NONE.
-
-
Method Details
-
messageReceived
public void messageReceived(org.apache.mina.common.IoFilter.NextFilter nextFilter, org.apache.mina.common.IoSession session, Object message) throws Exception - Specified by:
messageReceivedin interfaceorg.apache.mina.common.IoFilter- Overrides:
messageReceivedin classorg.apache.mina.common.IoFilterAdapter- Throws:
Exception
-
filterWrite
public void filterWrite(org.apache.mina.common.IoFilter.NextFilter nextFilter, org.apache.mina.common.IoSession session, org.apache.mina.common.IoFilter.WriteRequest writeRequest) throws IOException - Specified by:
filterWritein interfaceorg.apache.mina.common.IoFilter- Overrides:
filterWritein classorg.apache.mina.common.IoFilterAdapter- Throws:
IOException
-
onPreAdd
public void onPreAdd(org.apache.mina.common.IoFilterChain parent, String name, org.apache.mina.common.IoFilter.NextFilter nextFilter) throws Exception - Specified by:
onPreAddin interfaceorg.apache.mina.common.IoFilter- Overrides:
onPreAddin classorg.apache.mina.common.IoFilterAdapter- Throws:
Exception
-
isCompressInbound
public boolean isCompressInbound()Returns true if incoming data is being compressed. -
setCompressInbound
public void setCompressInbound(boolean compressInbound) Sets if incoming data has to be compressed. -
isCompressOutbound
public boolean isCompressOutbound()Returns true if the filter is compressing data being written. -
setCompressOutbound
public void setCompressOutbound(boolean compressOutbound) Set if outgoing data has to be compressed. -
onPostRemove
public void onPostRemove(org.apache.mina.common.IoFilterChain parent, String name, org.apache.mina.common.IoFilter.NextFilter nextFilter) throws Exception - Specified by:
onPostRemovein interfaceorg.apache.mina.common.IoFilter- Overrides:
onPostRemovein classorg.apache.mina.common.IoFilterAdapter- Throws:
Exception
-