Compression and Decompression Interfaces
CompressionStream and DecompressionStream classes cover most
typical usage scenarios. Therefore, you need to work directly with
Compressor and Decompressor objects only in the cases as follows:
CompressionStream and DecompressionStream classes do not cover
your specific usage model.
You want to control memory allocation and deallocation for
results of compression and decompression.
You need to modify compression and decompression default
The Compressor and Decompressor classes provide interfaces to
supported compression and decompression methods (ZLIB, LZO, RLE,
Compression and decompression objects are initialized with a set
of default parameters. You can modify parameters of a specific
compression method by accessing the parameter field of the
Compressor or Decompressor object.
To perform compression or decompression using the Compressor or
Decompressor classes, respectively, provide input data using the
setInputDataBlock() method and call the run() method. This
approach requires that you allocate and control the memory to
store the results of compression or decompression. In general, it
is impossible to accurately estimate the required size of the
output data block, and the memory you provide may be insufficient
to store results of compression or decompression. However, you can
check whether you need to allocate additional memory to continue
the run() operation. To do this, use the isOutputDataBlockFull()
method. You can also use the getUsedOutputDataBlockSize() method
to obtain the size of compressed or decompressed data actually
written to the output data block.
You can use your own compression and decompression methods in
CompressionStream and DecompressionStream. In this case, you need
to override Compressor and Decompressor objects.