This class implements an output stream filter for uncompressing data stored in the “deflate” compression format.
Constructors
- InflaterOutputStream(OutputStream out) : Creates a new output stream with a default decompressor and buffer size.
- InflaterOutputStream(OutputStream out, Inflater infl) : Creates a new output stream with the specified decompressor and a default buffer size.
- InflaterOutputStream(OutputStream out, Inflater infl, int bufLen) : Creates a new output stream with the specified decompressor and buffer size.
Methods:
- void close() : Writes any remaining uncompressed data to the output stream and closes the underlying output stream.
Syntax : public void close() throws IOException Overrides: close in class FilterOutputStream Throws: IOException - void finish() : Finishes writing uncompressed data to the output stream without closing the underlying stream.
Syntax :public void finish() throws IOException Throws: IOException - void flush() : Flushes this output stream, forcing any pending buffered output bytes to be written.
Syntax :public void flush() throws IOException Overrides: flush in class FilterOutputStream Throws: IOException - void write(byte[] b, int off, int len) : Writes an array of bytes to the uncompressed output stream.
Syntax :public void write(byte[] b, int off, int len) throws IOException Overrides: write in class FilterOutputStream Parameters: b - buffer containing compressed data to decompress and write to the output stream off - starting offset of the compressed data within b len - number of bytes to decompress from b Throws: IndexOutOfBoundsException IOException NullPointerException ZipException - void write(int b) : Writes a byte to the uncompressed output stream.
Syntax :public void write(int b) throws IOException Parameters: b - a single byte of compressed data to decompress and write to the output stream Throws: IOException ZipException
Program 1
//Java program to illustrate InflaterInputStream class import java.io.*; import java.util.Arrays; import java.util.zip.DeflaterInputStream; import java.util.zip.InflaterOutputStream; class InflaterOutputStreamDemo { public static void main(String[] args) throws IOException { byte b[] = {1, 2, 3, 4, 5, 6}; ByteArrayInputStream bin = new ByteArrayInputStream(b); DeflaterInputStream din = new DeflaterInputStream(bin); byte c[] = new byte[10]; din.read(c); din.close(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); InflaterOutputStream ios = new InflaterOutputStream(bos); //illustrating write(byte b[],int off,int len) ios.write(c); //flushing ios.flush(); //Finishes writing uncompressed data to the output stream // without closing the underlying stream. ios.finish(); System.out.println(Arrays.toString(bos.toByteArray())); bos.close(); //illustrating close() ios.close(); } } |
Output :
[1, 2, 3, 4, 5, 6]
Program 2:
//Java program to illustrate InflaterInputStream class import java.io.*; import java.util.Arrays; import java.util.zip.DeflaterInputStream; import java.util.zip.InflaterOutputStream; class InflaterOutputStreamDemo { public static void main(String[] args) throws IOException { byte b[] = {1, 2, 3, 4, 5, 6}; ByteArrayInputStream bin = new ByteArrayInputStream(b); DeflaterInputStream din = new DeflaterInputStream(bin); FileOutputStream fos=new FileOutputStream("file.txt"); byte c[] = new byte[10]; din.read(c); fos.write(c); din.close(); fos.close(); //reading the compressed data FileInputStream fis = new FileInputStream("file.txt"); ByteArrayOutputStream bos1=new ByteArrayOutputStream(); InflaterOutputStream ios = new InflaterOutputStream(bos1); int ch; //illustrating write() method while ( (ch=fis.read() ) != -1) { ios.write(ch); } System.out.print(Arrays.toString(bos1.toByteArray())); } } |
Output :
[1, 2, 3, 4, 5, 6]
Next article: Java.util.zip.InflaterInputStream class in Java
This article is contributed by Nishant Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- Java.lang.Class class in Java | Set 1
- Java.lang.Class class in Java | Set 2
- Using predefined class name as Class or Variable name in Java
- Java.util.TimeZone Class (Set-2) | Example On TimeZone Class
- Implement Pair Class with Unit Class in Java using JavaTuples
- Implement Triplet Class with Pair Class in Java using JavaTuples
- Implement Quintet Class with Quartet Class in Java using JavaTuples
- Implement Quartet Class with Triplet Class in Java using JavaTuples
- Implement Octet Class from Septet Class in Java using JavaTuples
- Implement Ennead Class from Octet Class in Java using JavaTuples
- Implement Sextet Class from Quintet Class in Java using JavaTuples
- Implement Septet Class from Sextet Class in Java using JavaTuples
- Implement Decade Class from Ennead Class in Java using JavaTuples
- Difference between Abstract Class and Concrete Class in Java
- In Java, Can we call the main() method of a class from another class?
- Does JVM create object of Main class (the class with main())?
- Inner Class And Anonymous Inner Class that Implements Runnable | Concurrent Programming Approach 3
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java.Lang.Float class in Java
- Java.io.BufferedInputStream class in Java

