Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Java.util.jar.JarInputStream class in Java
Next article icon

Java.util.zip.InflaterInputStream class in Java

Last Updated : 12 Sep, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

This class implements a stream filter for uncompressing data in the “deflate” compression format. It is also used as the basis for other decompression filters, such as GZIPInputStream.
Constructors

  • InflaterInputStream(InputStream in) : Creates a new input stream with a default decompressor and buffer size.
  • InflaterInputStream(InputStream in, Inflater inf) : Creates a new input stream with the specified decompressor and a default buffer size.
  • InflaterInputStream(InputStream in, Inflater inf, int size) : Creates a new input stream with the specified decompressor and buffer size.

Methods:

  • int available() : Returns 0 after EOF has been reached, otherwise always return 1.
    Syntax : public int available()                throws IOException  Returns:  1 before EOF and 0 after EOF.  Throws:  IOException  
  • void close() : Closes this input stream and releases any system resources associated with the stream.
    Syntax : public void close()             throws IOException  Throws:  IOException   
  • protected void fill() : Fills input buffer with more data to decompress.
    Syntax : protected void fill()               throws IOException  Throws:  IOException  
  • void mark(int readlimit) : Marks the current position in this input stream.
    Syntax : public void mark(int readlimit)  Parameters:  readlimit - the maximum limit of bytes that can be read  before the mark position becomes invalid.
  • boolean markSupported() : Tests if this input stream supports the mark and reset methods.
    Syntax : public boolean markSupported()  Returns:  a boolean indicating if this stream type supports the mark and reset methods.  
  • int read() : Reads a byte of uncompressed data.
    Syntax : public int read()           throws IOException  Returns:  the byte read, or -1 if end of compressed input is reached  Throws:  IOException
  • int read(byte[] b, int off, int len) : Reads uncompressed data into an array of bytes.
    Syntax : public int read(byte[] b,         int off,         int len)           throws IOException  Parameters:  b - the buffer into which the data is read  off - the start offset in the destination array b  len - the maximum number of bytes read  Returns:  the actual number of bytes read, or -1 if the end of the compressed input is reached.  Throws:  NullPointerException   IndexOutOfBoundsException   ZipException  IOException  
  • void reset() : Repositions this stream to the position at the time the mark method was last called on this input stream.
    Syntax : public void reset()             throws IOException  Throws:  IOException  
  • long skip(long n) : Skips specified number of bytes of uncompressed data.
    Syntax : public long skip(long n)            throws IOException  Parameters:  n - the number of bytes to skip  Returns:  the actual number of bytes skipped.  Throws:  IOException   IllegalArgumentException 

Program:




//Java program to demonstrate InflaterInputStream
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
  
  
class InflaterInputStreamDemo
{
    public static void main(String[] args) throws IOException
    {
  
        FileOutputStream fos = new FileOutputStream("file.txt");
  
        //Assign FileOutputStream to DeflaterOutputStream
        DeflaterOutputStream dos = new DeflaterOutputStream(fos);
  
        //write it into DeflaterOutputStream
        for (int i = 0; i < 10; i++)
        {
            dos.write(i);
        }
        dos.flush();
        dos.close();
        FileInputStream fis = new FileInputStream("file.txt");
        InflaterInputStream iis = new InflaterInputStream(fis);
  
        //illustrating available() method
        System.out.println(iis.available());
  
        //illustrating mark and markSupported()
        if (iis.markSupported())
            iis.mark(15);
        else
            System.out.println(false);
          
        //illustrating skip() method
        iis.skip(3);
  
        //illustrating read()
        for (int i = 0; i <3 ; i++) 
        {
            System.out.print(iis.read());
        }
  
        //illustrating read(byte[] b,int off,int len)
        byte b[]=new byte[4];
          
        for (int i = 0; i <4 ; i++) 
        {
            iis.read(b,0,4);
        }
          
        for (int i = 0; i < 4; i++) 
        {
            System.out.print(b[i]);
        }
    }
}
 
 

Output:

1  false  3456789


Next Article:
Java.util.zip.InflaterOutputStream class in Java



Next Article
Java.util.jar.JarInputStream class in Java

N

Nishant Sharma
Improve
Article Tags :
  • Java
Practice Tags :
  • Java

Similar Reads

  • Java.util.zip.InflaterOutputStream class in Java
    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) : Crea
    3 min read
  • Java.util.zip.DeflaterInputStream class in Java
    Implements an input stream filter for compressing data in the "deflate" compression format. Constructor and Description DeflaterInputStream(InputStream in) : Creates a new input stream with a default compressor and buffer size. DeflaterInputStream(InputStream in, Deflater defl) : Creates a new input
    3 min read
  • Java.util.jar.JarInputStream class in Java
    The JarInputStream class is used to read the contents of a JAR file from any input stream. It extends the class java.util.zip.ZipInputStream with support for reading an optional Manifest entry. The Manifest can be used to store meta-information about the JAR file and its entries. Constructors JarInp
    3 min read
  • Java.util.zip.GZIPInputStream class in Java
    This class implements a stream filter for reading compressed data in the GZIP file format. Constructors 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. Meth
    2 min read
  • Java.io.InputStream Class in Java
    Java InputStream class is the superclass of all the io classes i.e. representing an input stream of bytes. It represents an input stream of bytes. Applications that are defining a subclass of the Java InputStream class must provide a method, that returns the next byte of input. A reset() method is i
    3 min read
  • Java.io.FilterInputStream Class in Java
    Filter Streams filters data as they read and write data in the Input Stream, filters it and pass it on to the underlying Streams. Filter Streams are FilterInputStream FilterOutput Stream FilterInputStream : Java.io.FilterInputStream class works almost like InputStream class in Java but what it does
    9 min read
  • Java.util.jar.JarEntry class in Java
    This class is used to represent a JAR file entry. Constructors : JarEntry(JarEntry je) : Creates a new JarEntry with fields taken from the specified JarEntry object. JarEntry(String name) : Creates a new JarEntry for the specified JAR file entry name. JarEntry(ZipEntry ze) : Creates a new JarEntry w
    2 min read
  • Java.io.DataInputStream class in Java | Set 2
    Java.io.DataInputStream class in Java | Set 1 More Methods: byte readByte() : Reads and returns one input byte. Syntax:public final byte readByte() throws IOException Returns: the next byte of this input stream as a signed 8-bit byte. Throws: EOFException IOException float readFloat() : Reads four i
    3 min read
  • Java.io.DataInputStream class in Java | Set 1
    A data input stream enables an application to read primitive Java data types from an underlying input stream in a machine-independent way(instead of raw bytes). That is why it is called DataInputStream - because it reads data (numbers) instead of just bytes.  An application uses a data output stream
    3 min read
  • Java.io.FilterOutputStream Class in Java
    java.io.FilterInputStream Class in Java Java.io.FilterOutputStream class is the superclass of all those classes which filters output streams. The write() method of FilterOutputStream Class filters the data and write it to the underlying stream, filtering which is done depending on the Streams. Decla
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences