Package tigase.util
Class ZLibWrapper
- java.lang.Object
-
- tigase.util.ZLibWrapper
-
public class ZLibWrapper extends java.lang.ObjectThis is a warpper for java.util.zip package and Deflater/Inflater classes specifically. This implementation allows for easy interaction between Deflater/Inflater and java.nio API which operates on ByteBuffer data. It also does some tricky stuff to flush Deflater without reseting it and allow a better compression ration on the data.
There are a few convenience methods allowing to directly compress String to ByteBuffer and other way around - from ByteBuffer to String decompression. For these methods data are assumed to be UTF-8 character String.
Created: Jul 30, 2009 11:46:55 AM- Version:
- $Rev$
- Author:
- Artur Hefczyc
-
-
Field Summary
Fields Modifier and Type Field Description static intCOMPRESSED_BUFF_SIZEstatic intDECOMPRESSED_BUFF_SIZE
-
Constructor Summary
Constructors Constructor Description ZLibWrapper()ZLibWrapper(int level)ZLibWrapper(int level, int comp_buff_size)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description floataverageCompressionRate()floataverageDecompressionRate()java.nio.ByteBuffercompress(java.lang.String input)java.nio.ByteBuffercompress(java.nio.ByteBuffer input)java.nio.ByteBufferdecompress(java.nio.ByteBuffer input)java.lang.StringdecompressToString(java.nio.ByteBuffer input)voidend()floatlastCompressionRate()floatlastDecompressionRate()static voidmain(java.lang.String[] args)voidsetIOListener(IOListener listener)
-
-
-
Field Detail
-
COMPRESSED_BUFF_SIZE
public static final int COMPRESSED_BUFF_SIZE
- See Also:
- Constant Field Values
-
DECOMPRESSED_BUFF_SIZE
public static final int DECOMPRESSED_BUFF_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception- Throws:
java.lang.Exception
-
averageCompressionRate
public float averageCompressionRate()
-
averageDecompressionRate
public float averageDecompressionRate()
-
compress
public java.nio.ByteBuffer compress(java.nio.ByteBuffer input)
-
compress
public java.nio.ByteBuffer compress(java.lang.String input) throws java.nio.charset.CharacterCodingException- Throws:
java.nio.charset.CharacterCodingException
-
decompress
public java.nio.ByteBuffer decompress(java.nio.ByteBuffer input) throws java.io.IOException- Throws:
java.io.IOException
-
decompressToString
public java.lang.String decompressToString(java.nio.ByteBuffer input) throws java.nio.charset.CharacterCodingException, java.io.IOException- Throws:
java.nio.charset.CharacterCodingExceptionjava.io.IOException
-
end
public void end()
-
lastCompressionRate
public float lastCompressionRate()
-
lastDecompressionRate
public float lastDecompressionRate()
-
setIOListener
public void setIOListener(IOListener listener)
-
-