In this tutorial, we will discuss the use of getTotalIn() and getTotalout() method of Deflater. The Deflater class is used to compressed data by using ZLIB library. The Deflater class is available in java.util.zip package.The getTotalIn() method returns total number of uncompressed bytes of input stream. The getTotalOut() method returns total number of compressed bytes of output stream. The finish() method of Deflater class is used to indicate that compression of data is finished.
In this Example, we will see the getTotalIn() method and getTotalOut() method. The Defleter class create a compressor object for compressing data. The FileInputStream class creates a input stream for reading data from a file. The read() method of FileInputStream class read data from input stream. The deflater(byte buff, int offset, int length) method of Deflater class fills buffer with compressed data. The finish() method of Deflater class is used to indicate that compression of data is finished. The finished() method of Deflater class returns true if output stream reached at the end of compressed data and release the system resource.
About Deflater API:
The java.util.zip.Deflater class extends java.lang.Object class. It provides the following method:
|int||getTotalIn()||The getTotalIn() method return total number of uncompressed byte from input stream.|
|int||getTotalOut()||The getTotalOut() method return total number compressed byte after compression.|
|int||deflater(byte b, int offset, int length)||The deflater(.....) method store compressed data into associated buffer.|
|void||finished()||The finished() method returns true if output stream reached at the end of compressed data.|
|void||setInput()||The setInput() method set data for compression.|
|void||finish()||Thefinish() method define that compression will be finished .|
|C:\>java DefGetTotal C:\Work\Bharat\today\Deflater2\bharat.txt
Size of fille before Compression : 59
Size of fille after Compression : 19
The given file's data Successfully Compressed
Posted on: July 17, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles