You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sj...@apache.org on 2008/02/13 11:00:58 UTC

svn commit: r627335 - /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java

Author: sjanuary
Date: Wed Feb 13 02:00:56 2008
New Revision: 627335

URL: http://svn.apache.org/viewvc?rev=627335&view=rev
Log:
Partial fix for HARMONY-5489 ([pack200][classlib] java.util.ZipException("No Entries") on unpack close())

Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java?rev=627335&r1=627334&r2=627335&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java Wed Feb 13 02:00:56 2008
@@ -127,15 +127,15 @@
                 while((jarEntry = jarInputStream.getNextJarEntry()) != null) {
                     outputStream.putNextEntry(jarEntry);
                     byte[] bytes = new byte[16384];
-                    int bytesRead = 0;
+                    int bytesRead = jarInputStream.read(bytes);
                     while(bytesRead != -1) {
-                        bytesRead = jarInputStream.read(bytes);
                         outputStream.write(bytes, 0, bytesRead);
+                        bytesRead = jarInputStream.read(bytes);
                     }
                     outputStream.closeEntry();
                 }
             } else {
-                while (inputStream.available() > 0) {
+                while (available(inputStream)) {
                     Segment segment = new Segment();
                     segment.setLogLevel(logLevel);
                     segment.setLogStream(logFile != null ? (OutputStream) logFile
@@ -144,19 +144,28 @@
                         segment.overrideDeflateHint(deflateHint);
                     }
                     segment.unpack(inputStream, outputStream);
+                    outputStream.flush();
                 }
             }
-        } catch (Exception e) {
+        } finally {
             try {
                 inputStream.close();
-            } finally {
+            } catch (Exception e2) {}
+            try {
                 outputStream.close();
-            }
+            } catch (Exception e2) {}
         }
         if (removePackFile) {
             File file = new File(inputFileName);
             file.delete();
         }
+    }
+
+    private boolean available(InputStream inputStream) throws IOException {
+        inputStream.mark(1);
+        int check = inputStream.read();
+        inputStream.reset();
+        return check != -1;
     }
 
     /**