harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r885602 - /harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipFile.java
Date Mon, 30 Nov 2009 22:37:19 GMT
Author: tellison
Date: Mon Nov 30 22:37:18 2009
New Revision: 885602

URL: http://svn.apache.org/viewvc?rev=885602&view=rev
Log:
Fix for HARMONY-6394 ([classlib][archive] ZipFile.getInputStream implements available() differently
to the RI)

Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipFile.java

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipFile.java?rev=885602&r1=885601&r2=885602&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipFile.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipFile.java
Mon Nov 30 22:37:18 2009
@@ -247,7 +247,8 @@
             rafstrm.skip(entry.nameLen + localExtraLenOrWhatever);
             rafstrm.mLength = rafstrm.mOffset + entry.compressedSize;
             if (entry.compressionMethod == ZipEntry.DEFLATED) {
-                return new InflaterInputStream(rafstrm, new Inflater(true));
+                int bufSize = Math.max(1024, (int)Math.min(entry.getSize(), 65535L));
+                return new ZipInflaterInputStream(rafstrm, new Inflater(true), bufSize, entry);
             } else {
                 return rafstrm;
             }
@@ -415,4 +416,29 @@
             return n;
         }
     }
+    
+    static class ZipInflaterInputStream extends InflaterInputStream {
+
+        ZipEntry entry;
+        long bytesRead = 0;
+
+        public ZipInflaterInputStream(InputStream is, Inflater inf, int bsize, ZipEntry entry)
{
+            super(is, inf, bsize);
+            this.entry = entry;
+        }
+
+        @Override
+        public int read(byte[] buffer, int off, int nbytes) throws IOException {
+            int i = super.read(buffer, off, nbytes);
+            if (i != -1) {
+                bytesRead += i;
+            }
+            return i;
+        }
+
+        @Override
+        public int available() throws IOException {
+            return super.available() == 0 ? 0 : (int) (entry.getSize() - bytesRead);
+        }
+    }
 }



Mime
View raw message