Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article class in Java

  • Difficulty Level : Hard
  • Last Updated : 10 May, 2017

This class implements a stream filter for reading compressed data in the GZIP file format.


  • GZIPInputStream(InputStream in) : Creates a new input stream with a default buffer size.
  • GZIPInputStream(InputStream in, int size) : Creates a new input stream with the specified buffer size.

Methods :

  • void close() : Closes this input stream and releases any system resources associated with the stream.
    Syntax :public void close()
               throws IOException
    Specified by:
    close in interface Closeable
    Specified by:
    close in interface AutoCloseable
    close in class InflaterInputStream
  • int read(byte[] buf, int off, int len) : Reads uncompressed data into an array of bytes. If len is not zero, the method will block until some input can be decompressed; otherwise, no bytes are read and 0 is returned.
    Syntax :public int read(byte[] buf,
           int off,
           int len)
             throws IOException
    read in class InflaterInputStream
    buf - the buffer into which the data is read
    off - the start offset in the destination array b
    len - the maximum number of bytes read
    the actual number of bytes read, or -1 if the end of the
    compressed input stream is reached

Methods inherited from class
available, fill, mark, markSupported, read, reset, skip
Methods inherited from class
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Program :

//Java program demonstrating GZipInputStream methods 
import java.util.Arrays;
class GZipInputStreamDemo        
    public static void main(String[] args) throws IOException 
        FileInputStream fis = new FileInputStream("file.txt"); 
        GZIPInputStream gzis = new GZIPInputStream(fis);    
        //Uncompressed FileContents      
        byte b[]=new byte[10];
        //skipping 1 byte    
        //illustrating available() and 
        //read(byte b[],int off,int len) 
        if( gzis.available()!=-1)    
        //closing the stream                                                 

Output :

[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

This article is contributed by Nishant Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to 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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!