jdk/src/share/classes/java/util/zip/ZipFile.java
changeset 7550 700dd1df3aa8
parent 6882 637546039be3
child 7668 d4a77089c587
child 7803 56bc97d69d93
--- a/jdk/src/share/classes/java/util/zip/ZipFile.java	Mon Dec 13 15:07:20 2010 +0000
+++ b/jdk/src/share/classes/java/util/zip/ZipFile.java	Mon Dec 13 14:12:56 2010 -0800
@@ -315,7 +315,7 @@
     private static native void freeEntry(long jzfile, long jzentry);
 
     // the outstanding inputstreams that need to be closed.
-    private Set<ZipFileInputStream> streams = new HashSet<ZipFileInputStream>();
+    private Set<InputStream> streams = new HashSet<>();
 
     /**
      * Returns an input stream for reading the contents of the specified
@@ -348,55 +348,58 @@
                 return null;
             }
             in = new ZipFileInputStream(jzentry);
-            streams.add(in);
-        }
-        final ZipFileInputStream zfin = in;
-        switch (getEntryMethod(jzentry)) {
-        case STORED:
-            return zfin;
-        case DEFLATED:
-            // MORE: Compute good size for inflater stream:
-            long size = getEntrySize(jzentry) + 2; // Inflater likes a bit of slack
-            if (size > 65536) size = 8192;
-            if (size <= 0) size = 4096;
-            return new InflaterInputStream(zfin, getInflater(), (int)size) {
-                private boolean isClosed = false;
 
-                public void close() throws IOException {
-                    if (!isClosed) {
-                        releaseInflater(inf);
-                        this.in.close();
-                        isClosed = true;
+            switch (getEntryMethod(jzentry)) {
+            case STORED:
+                streams.add(in);
+                return in;
+            case DEFLATED:
+                final ZipFileInputStream zfin = in;
+                // MORE: Compute good size for inflater stream:
+                long size = getEntrySize(jzentry) + 2; // Inflater likes a bit of slack
+                if (size > 65536) size = 8192;
+                if (size <= 0) size = 4096;
+                InputStream is = new InflaterInputStream(zfin, getInflater(), (int)size) {
+                    private boolean isClosed = false;
+
+                    public void close() throws IOException {
+                        if (!isClosed) {
+                            super.close();
+                            releaseInflater(inf);
+                            isClosed = true;
+                        }
                     }
-                }
-                // Override fill() method to provide an extra "dummy" byte
-                // at the end of the input stream. This is required when
-                // using the "nowrap" Inflater option.
-                protected void fill() throws IOException {
-                    if (eof) {
-                        throw new EOFException(
-                            "Unexpected end of ZLIB input stream");
-                    }
-                    len = this.in.read(buf, 0, buf.length);
-                    if (len == -1) {
-                        buf[0] = 0;
-                        len = 1;
-                        eof = true;
+                    // Override fill() method to provide an extra "dummy" byte
+                    // at the end of the input stream. This is required when
+                    // using the "nowrap" Inflater option.
+                    protected void fill() throws IOException {
+                        if (eof) {
+                            throw new EOFException(
+                                "Unexpected end of ZLIB input stream");
+                        }
+                        len = this.in.read(buf, 0, buf.length);
+                        if (len == -1) {
+                            buf[0] = 0;
+                            len = 1;
+                            eof = true;
+                        }
+                        inf.setInput(buf, 0, len);
                     }
-                    inf.setInput(buf, 0, len);
-                }
-                private boolean eof;
+                    private boolean eof;
 
-                public int available() throws IOException {
-                    if (isClosed)
-                        return 0;
-                    long avail = zfin.size() - inf.getBytesWritten();
-                    return avail > (long) Integer.MAX_VALUE ?
-                        Integer.MAX_VALUE : (int) avail;
-                }
-            };
-        default:
-            throw new ZipException("invalid compression method");
+                    public int available() throws IOException {
+                        if (isClosed)
+                            return 0;
+                        long avail = zfin.size() - inf.getBytesWritten();
+                        return avail > (long) Integer.MAX_VALUE ?
+                            Integer.MAX_VALUE : (int) avail;
+                    }
+                };
+                streams.add(is);
+                return is;
+            default:
+                throw new ZipException("invalid compression method");
+            }
         }
     }
 
@@ -539,9 +542,9 @@
             closeRequested = true;
 
             if (streams.size() !=0) {
-                Set<ZipFileInputStream> copy = streams;
-                streams = new HashSet<ZipFileInputStream>();
-                for (ZipFileInputStream is: copy)
+                Set<InputStream> copy = streams;
+                streams = new HashSet<InputStream>();
+                for (InputStream is: copy)
                     is.close();
             }