commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r920808 - in /commons/proper/compress/trunk/src: changes/ main/java/org/apache/commons/compress/archivers/zip/ test/java/org/apache/commons/compress/archivers/zip/
Date Tue, 09 Mar 2010 11:23:41 GMT
Author: bodewig
Date: Tue Mar  9 11:23:41 2010
New Revision: 920808

URL: http://svn.apache.org/viewvc?rev=920808&view=rev
Log:
provide more information if an entry cannot be read/written.  OCMPRESS-98

Added:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java
  (with props)
Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=920808&r1=920807&r2=920808&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Tue Mar  9 11:23:41 2010
@@ -23,6 +23,11 @@
   </properties>
   <body>
     <release version="1.1" date="as in SVN" description="Release 1.1">
+      <action type="add" date="2010-03-09" issue="COMPRESS-98">
+        The ZIP classes will throw specialized exceptions if any
+        attempt is made to read or write data that uses zip features
+        not supported (yet).
+      </action>
       <action type="add" date="2010-03-08" issue="COMPRESS-99">
         ZipFile#getEntries returns entries in a predictable order -
         the order they appear inside the central directory.

Added: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java?rev=920808&view=auto
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java
(added)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java
Tue Mar  9 11:23:41 2010
@@ -0,0 +1,84 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.commons.compress.archivers.zip;
+
+import java.util.zip.ZipException;
+
+/**
+ * Exception thrown when attempting to read or write data for a zip
+ * entry that uses ZIP features not supported by this library.
+ * @since Commons Compress 1.1
+ */
+public class UnsupportedZipFeatureException extends ZipException {
+
+    private final Feature reason;
+    private final ZipArchiveEntry entry;
+
+    /**
+     * Creates an exception.
+     * @param the feature that is not supported
+     * @param the entry using the feature
+     */
+    public UnsupportedZipFeatureException(Feature reason,
+                                          ZipArchiveEntry entry) {
+        super("unsupported feature " + reason +  " used in entry "
+              + entry.getName());
+        this.reason = reason;
+        this.entry = entry;
+    }
+
+    /**
+     * The unsupported feature that has been used.
+     */
+    public Feature getFeature() {
+        return reason;
+    }
+
+    /**
+     * The entry using the unsupported feature.
+     */
+    public ZipArchiveEntry getEntry() {
+        return entry;
+    }
+
+    /**
+     * ZIP Features that may or may not be supported.
+     * @since Commons Compress 1.1
+     */
+    public static class Feature {
+        /**
+         * The entry is encrypted.
+         */
+        public static Feature ENCRYPTION = new Feature("encryption");
+        /**
+         * The entry used an unsupported compression method.
+         */
+        public static Feature METHOD = new Feature("compression method");
+        
+        private final String name;
+
+        private Feature(String name) {
+            this.name = name;
+        }
+
+        public String toString() {
+            return name;
+        }
+    }
+}
\ No newline at end of file

Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=920808&r1=920807&r2=920808&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
Tue Mar  9 11:23:41 2010
@@ -212,15 +212,17 @@ public abstract class ZipUtil {
      * Checks whether the entry requires features not (yet) supported
      * by the library and throws an exception if it does.
      */
-    static void checkRequestedFeatures(ZipArchiveEntry ze) throws IOException {
+    static void checkRequestedFeatures(ZipArchiveEntry ze)
+        throws UnsupportedZipFeatureException {
         if (!supportsEncryptionOf(ze)) {
-            throw new IOException("Encryption is not supported, used in "
-                                  + "entry " + ze.getName());
+            throw
+                new UnsupportedZipFeatureException(UnsupportedZipFeatureException
+                                                   .Feature.ENCRYPTION, ze);
         }
         if (!supportsMethodOf(ze)) {
-            throw new IOException("Unsupported compression method "
-                                  + ze.getMethod() + " in ZIP archive entry "
-                                  + ze.getName());
+            throw
+                new UnsupportedZipFeatureException(UnsupportedZipFeatureException
+                                                   .Feature.METHOD, ze);
         }
     }
 }
\ No newline at end of file

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java?rev=920808&r1=920807&r2=920808&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java
Tue Mar  9 11:23:41 2010
@@ -42,8 +42,9 @@ public class EncryptedArchiveTest extend
             try {
                 zf.getInputStream(zae);
                 fail("expected an exception");
-            } catch (IOException ex) {
-                assertTrue(ex.getMessage().indexOf("Encryption") >= 0);
+            } catch (UnsupportedZipFeatureException ex) {
+                assertSame(UnsupportedZipFeatureException.Feature.ENCRYPTION,
+                           ex.getFeature());
             }
         } finally {
             ZipFile.closeQuietly(zf);
@@ -66,8 +67,9 @@ public class EncryptedArchiveTest extend
                 byte[] buf = new byte[1024];
                 zin.read(buf, 0, buf.length);
                 fail("expected an exception");
-            } catch (IOException ex) {
-                assertTrue(ex.getMessage().indexOf("Encryption") >= 0);
+            } catch (UnsupportedZipFeatureException ex) {
+                assertSame(UnsupportedZipFeatureException.Feature.ENCRYPTION,
+                           ex.getFeature());
             }
         } finally {
             if (zin != null) {



Mime
View raw message