Author: jukka
Date: Sun Dec 13 20:07:59 2009
New Revision: 890110

URL: http://svn.apache.org/viewvc?rev=890110&view=rev
Log:
COMPRESS-93: Support for alternative ZIP compression methods

Fix the Maven221MultiVolumeTest failure by not using skip() to skip bytes. The 
FileInputStream implementation of skip() will happily skip past the end of the 
file, so we never see the EOFException that Maven221MultiVolumeTest expects to 
see when closing a truncated entry.

Also added an explicit test case for the ability to skip entries with 
unsupported compression methods.

Modified:
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
    
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java?rev=890110&r1=890109&r2=890110&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
 Sun Dec 13 20:07:59 2009
@@ -333,10 +333,7 @@
                 && !hasDataDescriptor) {
             long remaining = current.getCompressedSize() - bytesReadFromStream;
             while (remaining > 0) {
-                long n = in.skip(remaining);
-                if (n == 0) { // skip() may return 0, use read() as a fallback
-                    n = in.read(buf, 0, (int) Math.min(buf.length, remaining));
-                }
+                long n = in.read(buf, 0, (int) Math.min(buf.length, 
remaining));
                 if (n < 0) {
                     throw new EOFException(
                             "Truncated ZIP entry: " + current.getName());

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java?rev=890110&r1=890109&r2=890110&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
 Sun Dec 13 20:07:59 2009
@@ -29,6 +29,7 @@
 
 import org.apache.commons.compress.AbstractTestCase;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
 import org.apache.commons.compress.archivers.zip.ZipFile;
 import org.apache.commons.compress.utils.IOUtils;
@@ -130,6 +131,32 @@
     }
 
     /**
+     * Test case for being able to skip an entry in an 
+     * {...@link ZipArchiveInputStream} even if the compression method of that
+     * entry is unsupported.
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-93";
+     *        >COMPRESS-93</a>
+     */
+    public void testSkipEntryWithUnsupportedCompressionMethod()
+            throws IOException {
+        ZipArchiveInputStream zip =
+            new ZipArchiveInputStream(new 
FileInputStream(getFile("moby.zip")));
+        try {
+            ZipArchiveEntry entry = zip.getNextZipEntry();
+            assertEquals("README", entry.getName());
+            assertFalse(entry.isSupportedCompressionMethod());
+            try {
+                assertNull(zip.getNextZipEntry());
+            } catch (IOException e) {
+                fail("COMPRESS-93: Unable to skip an unsupported zip entry");
+            }
+        } finally {
+            zip.close();
+        }
+    }
+
+    /**
      * Checks if all entries from a nested archive can be read.
      * The archive: OSX_ArchiveWithNestedArchive.zip contains:
      * NestedArchiv.zip and test.xml3.


Reply via email to