Class Zlib

java.lang.Object
org.apache.mina.filter.compression.Zlib

class Zlib extends Object
A 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 is Z_SYNC_FLUSH also known as Z_PARTIAL_FLUSH
  • Field Details

    • COMPRESSION_MAX

      public static final int COMPRESSION_MAX
      Try o get the best possible compression
      See Also:
    • COMPRESSION_MIN

      public static final int COMPRESSION_MIN
      Favor speed over compression ratio
      See Also:
    • COMPRESSION_NONE

      public static final int COMPRESSION_NONE
      No compression
      See Also:
    • COMPRESSION_DEFAULT

      public static final int COMPRESSION_DEFAULT
      Default compression
      See Also:
    • MODE_DEFLATER

      public static final int MODE_DEFLATER
      Compression mode
      See Also:
    • MODE_INFLATER

      public static final int MODE_INFLATER
      Uncompress mode
      See Also:
    • 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 Details

    • 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 of COMPRESSION_MAX, COMPRESSION_MIN, COMPRESSION_NONE or COMPRESSION_DEFAULT
      mode - the mode in which the instance will operate. Can be either of MODE_DEFLATER or MODE_INFLATER
      Throws:
      IllegalArgumentException - if the mode is incorrect
  • Method Details

    • inflate

      public IoBuffer inflate(IoBuffer inBuffer) throws IOException
      Uncompress the given buffer, returning it in a new buffer.
      Parameters:
      inBuffer - the IoBuffer to 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:
      IOException - if the decompression of the data failed for some reason.
      IllegalArgumentException - if the mode is not MODE_DEFLATER
    • deflate

      public IoBuffer deflate(IoBuffer inBuffer) throws 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:
      IOException - if the compression of teh buffer failed for some reason
      IllegalStateException - if the mode is not MODE_DEFLATER
    • cleanUp

      public void cleanUp()
      Cleans up the resources used by the compression library.