You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2017/04/18 14:40:49 UTC

[4/4] commons-compress git commit: COMPRESS-385 some tweaks to Tim's code, allow detection of 7z

COMPRESS-385 some tweaks to Tim's code, allow detection of 7z

closes #18


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/f05101e2
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/f05101e2
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/f05101e2

Branch: refs/heads/master
Commit: f05101e28403494b81704029cc50e66703c34151
Parents: abf0755
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Apr 18 16:40:02 2017 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Apr 18 16:40:02 2017 +0200

----------------------------------------------------------------------
 src/changes/changes.xml                         |  8 +++---
 .../archivers/ArchiveStreamFactory.java         |  3 +-
 .../compressors/CompressorStreamFactory.java    |  4 +--
 .../commons/compress/MockEvilInputStream.java   | 30 +++++++++++---------
 .../archivers/ArchiveStreamFactoryTest.java     |  4 ++-
 .../compressors/DetectCompressorTestCase.java   |  4 +++
 6 files changed, 31 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/f05101e2/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f1ac318..055d11b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -44,10 +44,6 @@ The <action> type attribute can be add,update,fix,remove.
   <body>
     <release version="1.14" date="not released, yet"
              description="Release 1.14">
-      <action issue="COMPRESS-385" type="add" date="2017-04-14">
-        Add static detect(InputStream in) to CompressorStreamFactory
-        and ArchiveStreamFactory
-      </action>
       <action issue="COMPRESS-378" type="fix" date="2017-01-09">
         SnappyCompressorInputStream slides the window too early
         leading to ArrayIndexOutOfBoundsExceptions for some streams.
@@ -76,6 +72,10 @@ The <action> type attribute can be add,update,fix,remove.
         Fixed an integer overflow in CPIO's CRC calculation.
         Pull Request #17.
       </action>
+      <action issue="COMPRESS-385" type="add" date="2017-04-18">
+        Add static detect(InputStream in) to CompressorStreamFactory
+        and ArchiveStreamFactory
+      </action>
     </release>
     <release version="1.13" date="2016-12-29"
              description="Release 1.13 - API compatible to 1.12 but requires Java 7 at runtime.">

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/f05101e2/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
index 2d43463..ca15363 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
@@ -481,6 +481,7 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
      * @param in input stream
      * @return type of archiver if found
      * @throws ArchiveException if an archiver cannot be detected in the stream
+     * @since 1.14
      */
     public static String detect(InputStream in) throws ArchiveException {
         if (in == null) {
@@ -512,7 +513,7 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
         } else if (ArjArchiveInputStream.matches(signature, signatureLength)) {
             return ARJ;
         } else if (SevenZFile.matches(signature, signatureLength)) {
-            throw new StreamingNotSupportedException(SEVEN_Z);
+            return SEVEN_Z;
         }
 
         // Dump needs a bigger buffer to check the signature;

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/f05101e2/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java b/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
index 87c1209..a29179c 100644
--- a/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
+++ b/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
@@ -500,14 +500,14 @@ public class CompressorStreamFactory implements CompressorStreamProvider {
             }
 
             if (XZ.equalsIgnoreCase(name)) {
-                if (! XZUtils.isXZCompressionAvailable()) {
+                if (!XZUtils.isXZCompressionAvailable()) {
                     throw new CompressorException("XZ compression is not available.");
                 }
                 return new XZCompressorInputStream(in, actualDecompressConcatenated);
             }
 
             if (LZMA.equalsIgnoreCase(name)) {
-                if (! LZMAUtils.isLZMACompressionAvailable()) {
+                if (!LZMAUtils.isLZMACompressionAvailable()) {
                     throw new CompressorException("LZMA compression is not available");
                 }
                 return new LZMACompressorInputStream(in);

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/f05101e2/src/test/java/org/apache/commons/compress/MockEvilInputStream.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/MockEvilInputStream.java b/src/test/java/org/apache/commons/compress/MockEvilInputStream.java
index 884cf50..9c03a21 100644
--- a/src/test/java/org/apache/commons/compress/MockEvilInputStream.java
+++ b/src/test/java/org/apache/commons/compress/MockEvilInputStream.java
@@ -1,20 +1,22 @@
-package org.apache.commons.compress;/*
- * 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
+/*
+ * 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.
+ * 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;
 
 import java.io.IOException;
 import java.io.InputStream;

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/f05101e2/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java b/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
index 3fafa5d..ff8010f 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
@@ -230,11 +230,13 @@ public class ArchiveStreamFactoryTest {
     @Test
     public void testDetect() throws Exception {
         for (String extension : new String[]{
+                ArchiveStreamFactory.AR,
                 ArchiveStreamFactory.ARJ,
                 ArchiveStreamFactory.CPIO,
                 ArchiveStreamFactory.DUMP,
-                //TODO-- figure out how to differentiate btwn JAR and ZIP
+                // Compress doesn't know how to detect JARs, see COMPRESS-91
  //               ArchiveStreamFactory.JAR,
+                ArchiveStreamFactory.SEVEN_Z,
                 ArchiveStreamFactory.TAR,
                 ArchiveStreamFactory.ZIP
         }) {

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/f05101e2/src/test/java/org/apache/commons/compress/compressors/DetectCompressorTestCase.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/compressors/DetectCompressorTestCase.java b/src/test/java/org/apache/commons/compress/compressors/DetectCompressorTestCase.java
index 8ccf579..67abcd3 100644
--- a/src/test/java/org/apache/commons/compress/compressors/DetectCompressorTestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/DetectCompressorTestCase.java
@@ -128,6 +128,10 @@ public final class DetectCompressorTestCase {
         assertEquals(CompressorStreamFactory.PACK200, detect("bla.pack"));
         assertEquals(CompressorStreamFactory.XZ, detect("bla.tar.xz"));
         assertEquals(CompressorStreamFactory.DEFLATE, detect("bla.tar.deflatez"));
+        assertEquals(CompressorStreamFactory.LZ4_FRAMED, detect("bla.tar.lz4"));
+        assertEquals(CompressorStreamFactory.LZMA, detect("bla.tar.lzma"));
+        assertEquals(CompressorStreamFactory.SNAPPY_FRAMED, detect("bla.tar.sz"));
+        assertEquals(CompressorStreamFactory.Z, detect("bla.tar.Z"));
 
         try {
             CompressorStreamFactory.detect(new BufferedInputStream(new ByteArrayInputStream(new byte[0])));