Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 63554 invoked from network); 19 Feb 2010 12:23:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Feb 2010 12:23:49 -0000 Received: (qmail 72517 invoked by uid 500); 19 Feb 2010 12:23:49 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 72429 invoked by uid 500); 19 Feb 2010 12:23:49 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 72417 invoked by uid 99); 19 Feb 2010 12:23:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Feb 2010 12:23:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Feb 2010 12:23:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id CB6CF23889B9; Fri, 19 Feb 2010 12:23:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100219122327.CB6CF23889B9@eris.apache.org> 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 @@ - 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. 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. + * + *

Some archive formats support variants or details that are + * not supported (yet).

+ * + *

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. + * + *

Some archive formats support variants or details that are + * not supported (yet).

+ * + *

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 COMPRESS-93 - * @return true if the compression method is known - * and supported, false 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.

* @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.

* @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. */ 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)); } /**