ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1204135 - in /ant/antlibs/compress/trunk/src: main/org/apache/ant/compress/taskdefs/ main/org/apache/ant/compress/util/ tests/antunit/ tests/resources/
Date Sun, 20 Nov 2011 07:13:32 GMT
Author: bodewig
Date: Sun Nov 20 07:13:31 2011
New Revision: 1204135

URL: http://svn.apache.org/viewvc?rev=1204135&view=rev
Log:
support uncompressing resources that hold multiple concatenated streams for formats that support
it

Added:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CompressorWithConcatenatedStreamsFactory.java
      - copied, changed from r1204133, ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CompressorStreamFactory.java
    ant/antlibs/compress/trunk/src/tests/resources/multiple.bz2
      - copied unchanged from r1204133, commons/proper/compress/trunk/src/test/resources/multiple.bz2
    ant/antlibs/compress/trunk/src/tests/resources/multiple.gz
      - copied unchanged from r1204133, commons/proper/compress/trunk/src/test/resources/multiple.gz
    ant/antlibs/compress/trunk/src/tests/resources/multiple.xz
      - copied unchanged from r1204133, commons/proper/compress/trunk/src/test/resources/multiple.xz
Modified:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/BZip2StreamFactory.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/GZipStreamFactory.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/XZStreamFactory.java
    ant/antlibs/compress/trunk/src/tests/antunit/bunzip2-test.xml
    ant/antlibs/compress/trunk/src/tests/antunit/gunzip-test.xml
    ant/antlibs/compress/trunk/src/tests/antunit/unpack200-test.xml
    ant/antlibs/compress/trunk/src/tests/antunit/unxz-test.xml

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java?rev=1204135&r1=1204134&r2=1204135&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java Sun
Nov 20 07:13:31 2011
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.ant.compress.util.CompressorStreamFactory;
+import org.apache.ant.compress.util.CompressorWithConcatenatedStreamsFactory;
 import org.apache.ant.compress.util.StreamHelper;
 import org.apache.commons.compress.compressors.CompressorInputStream;
 import org.apache.commons.compress.utils.IOUtils;
@@ -40,6 +41,7 @@ public abstract class UnpackBase extends
 
     private final String defaultExtension;
     private CompressorStreamFactory factory;
+    private boolean decompressConcatenated = false;
 
     protected UnpackBase(String defaultExtension,
                          CompressorStreamFactory factory) {
@@ -69,7 +71,24 @@ public abstract class UnpackBase extends
     }
 
     /**
-     * Implement the gunzipping.
+     * Whether to extract the whole resource if it contains multiple
+     * concatenated streams.
+     *
+     * <p>Defaults to false for backwards compatibility.</p>
+     *
+     * @since Apache Compress Antlib 1.2
+     */
+    public void setDecompressConcatenated(boolean b) {
+        if (!b || factory instanceof CompressorWithConcatenatedStreamsFactory) {
+            decompressConcatenated = b;
+        } else {
+            throw new BuildException("concatenated streams are not supported"
+                                     + "by this compression format.");
+        }
+    }
+
+    /**
+     * Implement the uncompression.
      */
     protected void extract() {
         if (source.lastModified() > dest.lastModified()) {
@@ -84,7 +103,14 @@ public abstract class UnpackBase extends
                 zIn = StreamHelper.getInputStream(factory, srcResource);
                 if (zIn == null) {
                     fis = srcResource.getInputStream();
+                    if (factory instanceof CompressorWithConcatenatedStreamsFactory) {
+                        CompressorWithConcatenatedStreamsFactory f
+                            = (CompressorWithConcatenatedStreamsFactory) factory;
+                        zIn = f.getCompressorStream(new BufferedInputStream(fis),
+                                                    decompressConcatenated);
+                    } else {
                     zIn = factory.getCompressorStream(new BufferedInputStream(fis));
+                    }
                 }
                 IOUtils.copy(zIn, out, BUFFER_SIZE);
             } catch (IOException ioe) {

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/BZip2StreamFactory.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/BZip2StreamFactory.java?rev=1204135&r1=1204134&r2=1204135&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/BZip2StreamFactory.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/BZip2StreamFactory.java
Sun Nov 20 07:13:31 2011
@@ -30,14 +30,28 @@ import org.apache.commons.compress.compr
 /**
  * Creates streams for the supported compression formats.
  */
-public class BZip2StreamFactory implements CompressorStreamFactory {
+public class BZip2StreamFactory implements CompressorWithConcatenatedStreamsFactory {
 
     /**
      * @param stream the stream to read from, should be buffered
      */
     public CompressorInputStream getCompressorStream(InputStream stream)
         throws IOException {
-        return new BZip2CompressorInputStream(stream);
+        return getCompressorStream(stream, false);
+    }
+
+    /**
+     * @param stream the stream to read from, should be buffered
+     * @param       decompressConcatenated
+     *                          if true, decompress until the end of the
+     *                          input; if false, stop after the first
+     *                          stream
+     * @since Apache Compress Antlib 1.2
+     */
+    public CompressorInputStream getCompressorStream(InputStream stream,
+                                                     boolean decompressConcatenated)
+        throws IOException {
+        return new BZip2CompressorInputStream(stream, decompressConcatenated);
     }
 
 

Copied: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CompressorWithConcatenatedStreamsFactory.java
(from r1204133, ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CompressorStreamFactory.java)
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CompressorWithConcatenatedStreamsFactory.java?p2=ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CompressorWithConcatenatedStreamsFactory.java&p1=ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CompressorStreamFactory.java&r1=1204133&r2=1204135&rev=1204135&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CompressorStreamFactory.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CompressorWithConcatenatedStreamsFactory.java
Sun Nov 20 07:13:31 2011
@@ -20,27 +20,25 @@ package org.apache.ant.compress.util;
 
 import java.io.InputStream;
 import java.io.IOException;
-import java.io.OutputStream;
 
 import org.apache.commons.compress.compressors.CompressorInputStream;
-import org.apache.commons.compress.compressors.CompressorOutputStream;
 
 /**
- * Creates streams for the supported compression formats.
+ * Creates input streams for the compression formats that support
+ * concatenated streams.
+ * @since Apache Compress Antlib 1.2
  */
-public interface CompressorStreamFactory {
+public interface CompressorWithConcatenatedStreamsFactory
+    extends CompressorStreamFactory {
 
     /**
      * @param stream the stream to read from, should be buffered
+     * @param       decompressConcatenated
+     *                          if true, decompress until the end of the
+     *                          input; if false, stop after the first
+     *                          stream
      */
-    public CompressorInputStream getCompressorStream(InputStream stream)
+    public CompressorInputStream getCompressorStream(InputStream stream,
+                                                     boolean decompressConcatenated)
         throws IOException;
-
-
-    /**
-     * @param stream the stream to write to, should be buffered
-     */
-    public CompressorOutputStream getCompressorStream(OutputStream stream)
-        throws IOException;
-
 }
\ No newline at end of file

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/GZipStreamFactory.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/GZipStreamFactory.java?rev=1204135&r1=1204134&r2=1204135&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/GZipStreamFactory.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/GZipStreamFactory.java
Sun Nov 20 07:13:31 2011
@@ -30,14 +30,28 @@ import org.apache.commons.compress.compr
 /**
  * Creates streams for the supported compression formats.
  */
-public class GZipStreamFactory implements CompressorStreamFactory {
+public class GZipStreamFactory implements CompressorWithConcatenatedStreamsFactory {
 
     /**
      * @param stream the stream to read from, should be buffered
      */
     public CompressorInputStream getCompressorStream(InputStream stream)
         throws IOException {
-        return new GzipCompressorInputStream(stream);
+        return getCompressorStream(stream, false);
+    }
+
+    /**
+     * @param stream the stream to read from, should be buffered
+     * @param       decompressConcatenated
+     *                          if true, decompress until the end of the
+     *                          input; if false, stop after the first
+     *                          stream
+     * @since Apache Compress Antlib 1.2
+     */
+    public CompressorInputStream getCompressorStream(InputStream stream,
+                                                     boolean decompressConcatenated)
+        throws IOException {
+        return new GzipCompressorInputStream(stream, decompressConcatenated);
     }
 
 

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/XZStreamFactory.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/XZStreamFactory.java?rev=1204135&r1=1204134&r2=1204135&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/XZStreamFactory.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/XZStreamFactory.java
Sun Nov 20 07:13:31 2011
@@ -31,16 +31,28 @@ import org.apache.commons.compress.compr
  * Creates streams for the supported compression formats.
  * @since Apache Compress Antlib 1.2
  */
-public class XZStreamFactory implements CompressorStreamFactory {
+public class XZStreamFactory implements CompressorWithConcatenatedStreamsFactory {
 
     /**
      * @param stream the stream to read from, should be buffered
      */
     public CompressorInputStream getCompressorStream(InputStream stream)
         throws IOException {
-        return new XZCompressorInputStream(stream);
+        return getCompressorStream(stream, false);
     }
 
+    /**
+     * @param stream the stream to read from, should be buffered
+     * @param       decompressConcatenated
+     *                          if true, decompress until the end of the
+     *                          input; if false, stop after the first
+     *                          stream
+     */
+    public CompressorInputStream getCompressorStream(InputStream stream,
+                                                     boolean decompressConcatenated)
+        throws IOException {
+        return new XZCompressorInputStream(stream, decompressConcatenated);
+    }
 
     /**
      * @param stream the stream to write to, should be buffered

Modified: ant/antlibs/compress/trunk/src/tests/antunit/bunzip2-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/bunzip2-test.xml?rev=1204135&r1=1204134&r2=1204135&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/bunzip2-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/bunzip2-test.xml Sun Nov 20 07:13:31 2011
@@ -65,4 +65,34 @@
                  dest="${output}/asf-logo-huge.tar" />
   </target>
 
+  <target name="testConcatenatedStreamsDefault"
+          depends="setUp">
+    <echo file="${output}/expected">a</echo>
+    <cmp:bunzip2 dest="${output}/actual">
+      <file file="../resources/multiple.bz2"/>
+    </cmp:bunzip2>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
+  <target name="testConcatenatedStreamsOnlyFirstStream"
+          depends="setUp">
+    <echo file="${output}/expected">a</echo>
+    <cmp:bunzip2 dest="${output}/actual" decompressconcatenated="false">
+      <file file="../resources/multiple.bz2"/>
+    </cmp:bunzip2>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
+  <target name="testConcatenatedStreamsAllStreams"
+          depends="setUp">
+    <echo file="${output}/expected">ab</echo>
+    <cmp:bunzip2 dest="${output}/actual" decompressconcatenated="true">
+      <file file="../resources/multiple.bz2"/>
+    </cmp:bunzip2>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
 </project>

Modified: ant/antlibs/compress/trunk/src/tests/antunit/gunzip-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/gunzip-test.xml?rev=1204135&r1=1204134&r2=1204135&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/gunzip-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/gunzip-test.xml Sun Nov 20 07:13:31 2011
@@ -69,4 +69,34 @@
                          actual="${output}/asf-logo.gif"/>
   </target>
 
+  <target name="testConcatenatedStreamsDefault"
+          depends="setUp">
+    <echo file="${output}/expected">a</echo>
+    <cmp:gunzip dest="${output}/actual">
+      <file file="../resources/multiple.gz"/>
+    </cmp:gunzip>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
+  <target name="testConcatenatedStreamsOnlyFirstStream"
+          depends="setUp">
+    <echo file="${output}/expected">a</echo>
+    <cmp:gunzip dest="${output}/actual" decompressconcatenated="false">
+      <file file="../resources/multiple.gz"/>
+    </cmp:gunzip>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
+  <target name="testConcatenatedStreamsAllStreams"
+          depends="setUp">
+    <echo file="${output}/expected">ab</echo>
+    <cmp:gunzip dest="${output}/actual" decompressconcatenated="true">
+      <file file="../resources/multiple.gz"/>
+    </cmp:gunzip>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
 </project>

Modified: ant/antlibs/compress/trunk/src/tests/antunit/unpack200-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/unpack200-test.xml?rev=1204135&r1=1204134&r2=1204135&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/unpack200-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/unpack200-test.xml Sun Nov 20 07:13:31 2011
@@ -77,4 +77,12 @@
        />
   </target>
 
+  <target name="testDoesntSupportConcatenatedStreams">
+    <au:expectfailure>
+      <cmp:unpack200 src="../resources/asf-logo.gif.pack"
+                     dest="${input}/test.zip"
+                     decompressconcatenated="true"/>
+    </au:expectfailure>
+  </target>
+
 </project>

Modified: ant/antlibs/compress/trunk/src/tests/antunit/unxz-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/unxz-test.xml?rev=1204135&r1=1204134&r2=1204135&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/unxz-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/unxz-test.xml Sun Nov 20 07:13:31 2011
@@ -62,4 +62,35 @@
                          actual="${output}/asf-logo.gif"/>
   </target>
 
+
+  <target name="testConcatenatedStreamsDefault"
+          depends="setUp">
+    <echo file="${output}/expected">a</echo>
+    <cmp:unxz dest="${output}/actual">
+      <file file="../resources/multiple.xz"/>
+    </cmp:unxz>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
+  <target name="testConcatenatedStreamsOnlyFirstStream"
+          depends="setUp">
+    <echo file="${output}/expected">a</echo>
+    <cmp:unxz dest="${output}/actual" decompressconcatenated="false">
+      <file file="../resources/multiple.xz"/>
+    </cmp:unxz>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
+  <target name="testConcatenatedStreamsAllStreams"
+          depends="setUp">
+    <echo file="${output}/expected">ab</echo>
+    <cmp:unxz dest="${output}/actual" decompressconcatenated="true">
+      <file file="../resources/multiple.xz"/>
+    </cmp:unxz>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
 </project>



Mime
View raw message