You should see the implementation of GZIPInputStream.close() .
public void close() throws IOException { if (!closed) { super.close(); eos = true; closed = true; } }
If you look at the constructor for GZIPInputStream , it looks like this:
public GZIPInputStream(InputStream in, int size) throws IOException { super(in, new Inflater(true), size); usesDefaultInflater = true; readHeader(in); }
Observe the in variable. Notice how this is passed to the super class, which in this case is InflaterInputStream .
Now, if we look at the implementation of the InflaterInputStream.close() method, we will find this:
public void close() throws IOException { if (!closed) { if (usesDefaultInflater) inf.end(); in.close(); closed = true; } }
It is clear that in.close() called. Thus, the completed (decorated) FileInputStream also closes when GZIPInputStream.close() called. Thich makes calling fis.close() redundant.
source share