ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1154209 - in /ant/antlibs/compress/trunk/src/main/org/apache/ant/compress: taskdefs/PackBase.java taskdefs/UnpackBase.java util/FileAwareCompressorStreamFactory.java
Date Fri, 05 Aug 2011 13:41:22 GMT
Author: bodewig
Date: Fri Aug  5 13:41:21 2011
New Revision: 1154209

URL: http://svn.apache.org/viewvc?rev=1154209&view=rev
Log:
prepare for compressor streams that can take advantage of Files - Pack200 will be one once
Commons Compress 1.3 supports it

Added:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/FileAwareCompressorStreamFactory.java
      - copied, changed from r1154107, ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CompressorStreamFactory.java
Modified:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java?rev=1154209&r1=1154208&r2=1154209&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java Fri
Aug  5 13:41:21 2011
@@ -27,11 +27,13 @@ import java.util.Iterator;
 
 import org.apache.ant.compress.resources.CommonsCompressCompressorResource;
 import org.apache.ant.compress.util.CompressorStreamFactory;
+import org.apache.ant.compress.util.FileAwareCompressorStreamFactory;
 import org.apache.commons.compress.utils.IOUtils;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.FileProvider;
 import org.apache.tools.ant.types.resources.FileResource;
 import org.apache.tools.ant.types.resources.Resources;
 import org.apache.tools.ant.util.FileUtils;
@@ -185,8 +187,16 @@ public abstract class PackBase extends T
         OutputStream out = null;
         try {
             in = src.getInputStream();
+            if (factory instanceof FileAwareCompressorStreamFactory
+                && dest.as(FileProvider.class) != null) {
+                FileProvider p = (FileProvider) dest.as(FileProvider.class);
+                FileAwareCompressorStreamFactory f =
+                    (FileAwareCompressorStreamFactory) factory;
+                out =  f.getCompressorOutputStream(p.getFile());
+            } else {
             out =
                 factory.getCompressorStream(new BufferedOutputStream(dest.getOutputStream()));
+            }
             IOUtils.copy(in, out, BUFFER_SIZE);
         } catch (IOException e) {
             throw new BuildException("Error compressing " + src.getName()

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=1154209&r1=1154208&r2=1154209&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 Fri
Aug  5 13:41:21 2011
@@ -24,8 +24,10 @@ import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.ant.compress.util.CompressorStreamFactory;
+import org.apache.ant.compress.util.FileAwareCompressorStreamFactory;
 import org.apache.commons.compress.compressors.CompressorInputStream;
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.resources.FileProvider;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.taskdefs.Unpack;
 
@@ -65,8 +67,17 @@ public abstract class UnpackBase extends
             InputStream fis = null;
             try {
                 out = new FileOutputStream(dest);
+                if (factory instanceof FileAwareCompressorStreamFactory
+                    && srcResource.as(FileProvider.class) != null) {
+                    FileProvider p =
+                        (FileProvider) srcResource.as(FileProvider.class);
+                    FileAwareCompressorStreamFactory f =
+                        (FileAwareCompressorStreamFactory) factory;
+                    zIn =  f.getCompressorInputStream(p.getFile());
+                } else {
                 fis = srcResource.getInputStream();
                 zIn = factory.getCompressorStream(new BufferedInputStream(fis));
+                }
                 byte[] buffer = new byte[BUFFER_SIZE];
                 int count = 0;
                 do {

Copied: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/FileAwareCompressorStreamFactory.java
(from r1154107, 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/FileAwareCompressorStreamFactory.java?p2=ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/FileAwareCompressorStreamFactory.java&p1=ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CompressorStreamFactory.java&r1=1154107&r2=1154209&rev=1154209&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/FileAwareCompressorStreamFactory.java
Fri Aug  5 13:41:21 2011
@@ -18,29 +18,31 @@
 
 package org.apache.ant.compress.util;
 
-import java.io.InputStream;
+import java.io.File;
 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 streams for the supported compression formats that may take
+ * advantage of writing to/reading from a file.
+ *
+ * @since Apache Compress Antlib 1.1
  */
-public interface CompressorStreamFactory {
+public interface FileAwareCompressorStreamFactory {
 
     /**
-     * @param stream the stream to read from, should be buffered
+     * @param file the file to read from
      */
-    public CompressorInputStream getCompressorStream(InputStream stream)
+    public CompressorInputStream getCompressorInputStream(File file)
         throws IOException;
 
 
     /**
-     * @param stream the stream to write to, should be buffered
+     * @param file the file to write to
      */
-    public CompressorOutputStream getCompressorStream(OutputStream stream)
+    public CompressorOutputStream getCompressorOutputStream(File file)
         throws IOException;
 
 }
\ No newline at end of file



Mime
View raw message