commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r924342 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip: ZipArchiveInputStream.java ZipUtil.java
Date Wed, 17 Mar 2010 15:55:01 GMT
Author: bodewig
Date: Wed Mar 17 15:55:00 2010
New Revision: 924342

URL: http://svn.apache.org/viewvc?rev=924342&view=rev
Log:
STORED entry with data descriptors are not a problem for ZipFile and the output stream doesn't
care anyway - so only check for the combination inside the input stream.

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.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=924342&r1=924341&r2=924342&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
Wed Mar 17 15:55:00 2010
@@ -197,7 +197,10 @@ public class ZipArchiveInputStream exten
      */
     public boolean canReadEntryData(ArchiveEntry ae) {
         if (ae instanceof ZipArchiveEntry) {
-            return ZipUtil.canHandleEntryData((ZipArchiveEntry) ae);
+            ZipArchiveEntry ze = (ZipArchiveEntry) ae;
+            return ZipUtil.canHandleEntryData(ze)
+                && supportsDataDescriptorFor(ze);
+
         }
         return false;
     }
@@ -214,6 +217,12 @@ public class ZipArchiveInputStream exten
         if (start <= buffer.length && length >= 0 && start >= 0
             && buffer.length - start >= length) {
             ZipUtil.checkRequestedFeatures(current);
+            if (!supportsDataDescriptorFor(current)) {
+                throw new UnsupportedZipFeatureException(UnsupportedZipFeatureException
+                                                         .Feature
+                                                         .DATA_DESCRIPTOR,
+                                                         current);
+            }
 
             if (current.getMethod() == ZipArchiveOutputStream.STORED) {
                 int csize = (int) current.getSize();
@@ -419,4 +428,15 @@ public class ZipArchiveInputStream exten
         current.setSize(new ZipLong(b).getValue());
     }
 
+    /**
+     * Whether this entry requires a data descriptor this library can work with.
+     *
+     * @return true if the entry doesn't require any data descriptor
+     * or the method is DEFLATED).
+     */
+    private static boolean supportsDataDescriptorFor(ZipArchiveEntry entry) {
+        return !entry.getGeneralPurposeBit().usesDataDescriptor()
+            || entry.getMethod() == ZipArchiveEntry.DEFLATED;
+    }
+
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java?rev=924342&r1=924341&r2=924342&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
Wed Mar 17 15:55:00 2010
@@ -184,8 +184,7 @@ public abstract class ZipUtil {
      * Whether this library is able to read or write the given entry.
      */
     static boolean canHandleEntryData(ZipArchiveEntry entry) {
-        return supportsEncryptionOf(entry) && supportsMethodOf(entry)
-            && supportsDataDescriptorFor(entry);
+        return supportsEncryptionOf(entry) && supportsMethodOf(entry);
     }
 
     /**
@@ -210,17 +209,6 @@ public abstract class ZipUtil {
     }
 
     /**
-     * Whether this entry requires a data descriptor this library can work with.
-     *
-     * @return true if the entry doesn't require any data descriptor
-     * or the method is DEFLATED).
-     */
-    private static boolean supportsDataDescriptorFor(ZipArchiveEntry entry) {
-        return !entry.getGeneralPurposeBit().usesDataDescriptor()
-            || entry.getMethod() == ZipArchiveEntry.DEFLATED;
-    }
-
-    /**
      * Checks whether the entry requires features not (yet) supported
      * by the library and throws an exception if it does.
      */
@@ -236,10 +224,5 @@ public abstract class ZipUtil {
                 new UnsupportedZipFeatureException(UnsupportedZipFeatureException
                                                    .Feature.METHOD, ze);
         }
-        if (!supportsDataDescriptorFor(ze)) {
-            throw
-                new UnsupportedZipFeatureException(UnsupportedZipFeatureException
-                                                   .Feature.DATA_DESCRIPTOR, ze);
-        }
     }
 }
\ No newline at end of file



Mime
View raw message