In this tutorial, we will define the use of Deflater class. The
Deflater class is used to compressed data by using ZLIB library. The Deflater
class is available in java.util.zip package .The getBytes() method
get byte of string.
Deflater is use Dictionary-Based Compression .This tries to replace repeated patterns of the data with the reference of the first occurrence of repeated pattern.
In the given Example, we will compress data. The Defleter class create a deflater object for compressing data. The setLevel() method of Deflater class set level of compression. The setInput() method of Deflater class is used to input data for compression. The ByteArrayOutputStream class create output stream in which data is written. The deflater() method of Deflater class store compressed data into buffer.
About Deflater API:
|int||deflater(byte b)||The deflater() method store compressed data into associated buffer.|
|void||setLevel()||The setLevel() method set te leve of compression.|
|void||setInput()||The setInput() method set data for compression.|
|void||finish()||Thefinish() method define that compression will be finished .|
Actual Size of String : 59
Compressed size of String : 19
Posted on: July 15, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles