commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r911795 - in /commons/proper/compress/trunk/src: changes/ main/java/org/apache/commons/compress/archivers/ main/java/org/apache/commons/compress/archivers/zip/ test/java/org/apache/commons/compress/archivers/ test/java/org/apache/commons/co...
Date Fri, 19 Feb 2010 12:23:27 GMT
Author: bodewig
Date: Fri Feb 19 12:23:27 2010
New Revision: 911795

URL: http://svn.apache.org/viewvc?rev=911795&view=rev
Log:
move canRead/canWrite up.  Remove isSupportedCompressionMethod.  COMPRESS-93

Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
    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/ZipArchiveOutputStream.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.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=911795&r1=911794&r2=911795&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Fri Feb 19 12:23:27 2010
@@ -24,11 +24,11 @@
   <body>
     <release version="1.1" date="as in SVN" description="Release 1.1">
       <action type="add" date="2010-02-19">
-        The Zip*Stream and ZipFile classes now have canRead/Write
+        The Achive*Stream and ZipFile classes now have canRead/Write
         methods that can be used to check whether a given entry can be
         read/written.
-        The method currently returns false if an entry uses an
-        unsupported compression method or encryption.
+        The method currently returns false for ZIP archives if an
+        entry uses an unsupported compression method or encryption.
       </action>
       <action type="add" date="2010-02-19" issue="COMPRESS-89">
         The ZIP classes now detect encrypted entries.

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java?rev=911795&r1=911794&r2=911795&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
Fri Feb 19 12:23:27 2010
@@ -96,6 +96,7 @@
      * Doesn't increment if the EOF has been hit (read == -1)
      * 
      * @param read the number of bytes read
+     * @since Apache Commons Compress 1.1
      */
     protected void count(long read) {
         if (read != -1) {
@@ -107,6 +108,7 @@
      * Decrements the counter of already read bytes.
      * 
      * @param read the number of bytes pushed back.
+     * @since Apache Commons Compress 1.1
      */
     protected void pushedBackBytes(long pushedBack) {
         bytesRead -= pushedBack;
@@ -125,8 +127,24 @@
     /**
      * Returns the current number of bytes read from this stream.
      * @return the number of read bytes
+     * @since Apache Commons Compress 1.1
      */
     public long getBytesRead() {
         return bytesRead;
     }
+
+    /**
+     * Whether this stream is able to read the given entry.
+     *
+     * <p>Some archive formats support variants or details that are
+     * not supported (yet).</p>
+     *
+     * <p>This implementation always returns true.
+     *
+     * @since Apache Commons Compress 1.1
+     */
+    public boolean canRead(ArchiveEntry ae) {
+        return true;
+    }
+
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java?rev=911795&r1=911794&r2=911795&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
Fri Feb 19 12:23:27 2010
@@ -127,6 +127,7 @@
      * Doesn't increment if the EOF has been hit (read == -1)
      * 
      * @param written the number of bytes written
+     * @since Apache Commons Compress 1.1
      */
     protected void count(long written) {
         if (written != -1) {
@@ -147,8 +148,22 @@
     /**
      * Returns the current number of bytes written to this stream.
      * @return the number of written bytes
+     * @since Apache Commons Compress 1.1
      */
     public long getBytesWritten() {
         return bytesWritten;
     }
+
+    /**
+     * Whether this stream is able to write the given entry.
+     *
+     * <p>Some archive formats support variants or details that are
+     * not supported (yet).</p>
+     *
+     * <p>This implementation always returns true.
+     * @since Apache Commons Compress 1.1
+     */
+    public boolean canWrite(ArchiveEntry ae) {
+        return true;
+    }
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java?rev=911795&r1=911794&r2=911795&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
Fri Feb 19 12:23:27 2010
@@ -148,20 +148,6 @@
     }
 
     /**
-     * Checks whether the compression method of this entry is supported,
-     * i.e. whether the content of this entry can be accessed.
-     *
-     * @since Commons Compress 1.1
-     * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-93"
-     *         >COMPRESS-93</a>
-     * @return <code>true</code> if the compression method is known
-     *         and supported, <code>false</code> otherwise
-     */
-    public boolean isSupportedCompressionMethod() {
-        return method == STORED || method == DEFLATED;
-    }
-
-    /**
      * Returns the compression method of this entry, or -1 if the
      * compression method has not been specified.
      *

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=911795&r1=911794&r2=911795&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
Fri Feb 19 12:23:27 2010
@@ -196,10 +196,14 @@
      * compression method that hasn't been implemented yet.</p>
      * @since Apache Commons Compress 1.1
      */
-    public boolean canRead(ZipArchiveEntry ze) {
-        return !ze.isEncrypted() &&
-            (ze.getMethod() == ZipArchiveEntry.STORED
-             || ze.getMethod() == ZipArchiveEntry.DEFLATED);
+    public boolean canRead(ArchiveEntry ae) {
+        if (ae instanceof ZipArchiveEntry) {
+            ZipArchiveEntry ze = (ZipArchiveEntry) ae;
+            return !ze.isEncrypted() &&
+                (ze.getMethod() == ZipArchiveEntry.STORED
+                 || ze.getMethod() == ZipArchiveEntry.DEFLATED);
+        }
+        return super.canRead(ae);
     }
 
     public int read(byte[] buffer, int start, int length) throws IOException {

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=911795&r1=911794&r2=911795&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Fri Feb 19 12:23:27 2010
@@ -511,9 +511,13 @@
      * compression method that hasn't been implemented yet.</p>
      * @since Apache Commons Compress 1.1
      */
-    public boolean canWrite(ZipArchiveEntry ze) {
-        return !ze.isEncrypted() &&
-            (ze.getMethod() == STORED || ze.getMethod() == DEFLATED);
+    public boolean canWrite(ArchiveEntry ae) {
+        if (ae instanceof ZipArchiveEntry) {
+            ZipArchiveEntry ze = (ZipArchiveEntry) ae;
+            return !ze.isEncrypted() &&
+                (ze.getMethod() == STORED || ze.getMethod() == DEFLATED);
+        }
+        return super.canWrite(ae);
     }
 
     /**

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=911795&r1=911794&r2=911795&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
Fri Feb 19 12:23:27 2010
@@ -122,11 +122,11 @@
      */
     public void testSupportedCompressionMethod() throws IOException {
         ZipFile bla = new ZipFile(getFile("bla.zip"));
-        assertTrue(bla.getEntry("test1.xml").isSupportedCompressionMethod());
+        assertTrue(bla.canRead(bla.getEntry("test1.xml")));
         bla.close();
 
         ZipFile moby = new ZipFile(getFile("moby.zip"));
-        assertFalse(moby.getEntry("README").isSupportedCompressionMethod());
+        assertFalse(moby.canRead(moby.getEntry("README")));
         moby.close();
     }
 
@@ -145,7 +145,7 @@
         try {
             ZipArchiveEntry entry = zip.getNextZipEntry();
             assertEquals("README", entry.getName());
-            assertFalse(entry.isSupportedCompressionMethod());
+            assertFalse(zip.canRead(entry));
             try {
                 assertNull(zip.getNextZipEntry());
             } catch (IOException e) {

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java?rev=911795&r1=911794&r2=911795&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
Fri Feb 19 12:23:27 2010
@@ -201,22 +201,24 @@
      * >COMPRESS-93</a>.
      */
     public void testCompressionMethod() {
+        ZipArchiveOutputStream zos =
+            new ZipArchiveOutputStream((java.io.OutputStream) null);
         ZipArchiveEntry entry = new ZipArchiveEntry("foo");
         assertEquals(-1, entry.getMethod());
-        assertFalse(entry.isSupportedCompressionMethod());
+        assertFalse(zos.canWrite(entry));
 
         entry.setMethod(ZipArchiveEntry.STORED);
         assertEquals(ZipArchiveEntry.STORED, entry.getMethod());
-        assertTrue(entry.isSupportedCompressionMethod());
+        assertTrue(zos.canWrite(entry));
 
         entry.setMethod(ZipArchiveEntry.DEFLATED);
         assertEquals(ZipArchiveEntry.DEFLATED, entry.getMethod());
-        assertTrue(entry.isSupportedCompressionMethod());
+        assertTrue(zos.canWrite(entry));
 
         // Test the unsupported "imploded" compression method (6)
         entry.setMethod(6);
         assertEquals(6, entry.getMethod());
-        assertFalse(entry.isSupportedCompressionMethod());
+        assertFalse(zos.canWrite(entry));
     }
 
     /**



Mime
View raw message