Class Zlib
- java.lang.Object
-
- org.apache.mina.filter.compression.Zlib
-
class Zlib extends java.lang.ObjectA helper class for interfacing with the JZlib library. This class acts both as a compressor and decompressor, but only as one at a time. The only flush method supported isZ_SYNC_FLUSHalso known asZ_PARTIAL_FLUSH
-
-
Field Summary
Fields Modifier and Type Field Description static intCOMPRESSION_DEFAULTDefault compressionstatic intCOMPRESSION_MAXTry o get the best possible compressionstatic intCOMPRESSION_MINFavor speed over compression ratiostatic intCOMPRESSION_NONENo compressionprivate intcompressionLevelThe requested compression levelprivate intmodeThe selected operation mode : INFLATE or DEFLATEstatic intMODE_DEFLATERCompression modestatic intMODE_INFLATERUncompress modeprivate com.jcraft.jzlib.ZStreamzStreamThe inner stream used to inflate or deflate the data
-
Constructor Summary
Constructors Constructor Description Zlib(int compressionLevel, int mode)Creates an instance of the ZLib class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanUp()Cleans up the resources used by the compression library.IoBufferdeflate(IoBuffer inBuffer)Compress the input.IoBufferinflate(IoBuffer inBuffer)Uncompress the given buffer, returning it in a new buffer.
-
-
-
Field Detail
-
COMPRESSION_MAX
public static final int COMPRESSION_MAX
Try o get the best possible compression- See Also:
- Constant Field Values
-
COMPRESSION_MIN
public static final int COMPRESSION_MIN
Favor speed over compression ratio- See Also:
- Constant Field Values
-
COMPRESSION_NONE
public static final int COMPRESSION_NONE
No compression- See Also:
- Constant Field Values
-
COMPRESSION_DEFAULT
public static final int COMPRESSION_DEFAULT
Default compression- See Also:
- Constant Field Values
-
MODE_DEFLATER
public static final int MODE_DEFLATER
Compression mode- See Also:
- Constant Field Values
-
MODE_INFLATER
public static final int MODE_INFLATER
Uncompress mode- See Also:
- Constant Field Values
-
compressionLevel
private int compressionLevel
The requested compression level
-
zStream
private com.jcraft.jzlib.ZStream zStream
The inner stream used to inflate or deflate the data
-
mode
private int mode
The selected operation mode : INFLATE or DEFLATE
-
-
Constructor Detail
-
Zlib
public Zlib(int compressionLevel, int mode)Creates an instance of the ZLib class.- Parameters:
compressionLevel- the level of compression that should be used. One ofCOMPRESSION_MAX,COMPRESSION_MIN,COMPRESSION_NONEorCOMPRESSION_DEFAULTmode- the mode in which the instance will operate. Can be either ofMODE_DEFLATERorMODE_INFLATER- Throws:
java.lang.IllegalArgumentException- if the mode is incorrect
-
-
Method Detail
-
inflate
public IoBuffer inflate(IoBuffer inBuffer) throws java.io.IOException
Uncompress the given buffer, returning it in a new buffer.- Parameters:
inBuffer- theIoBufferto be decompressed. The contents of the buffer are transferred into a local byte array and the buffer is flipped and returned intact.- Returns:
- the decompressed data
- Throws:
java.io.IOException- if the decompression of the data failed for some reason.java.lang.IllegalArgumentException- if the mode is notMODE_DEFLATER
-
deflate
public IoBuffer deflate(IoBuffer inBuffer) throws java.io.IOException
Compress the input. The result will be put in a new buffer.- Parameters:
inBuffer- the buffer to be compressed. The contents are transferred into a local byte array and the buffer is flipped and returned intact.- Returns:
- the buffer with the compressed data
- Throws:
java.io.IOException- if the compression of teh buffer failed for some reasonjava.lang.IllegalStateException- if the mode is notMODE_DEFLATER
-
cleanUp
public void cleanUp()
Cleans up the resources used by the compression library.
-
-