ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1154124 - in /ant/antlibs/compress/trunk/src/main/org/apache/ant/compress: taskdefs/ArchiveBase.java taskdefs/Zip.java util/FileAwareArchiveStreamFactory.java util/ZipStreamFactory.java
Date Fri, 05 Aug 2011 08:32:40 GMT
Author: bodewig
Date: Fri Aug  5 08:32:40 2011
New Revision: 1154124

URL: http://svn.apache.org/viewvc?rev=1154124&view=rev
Log:
ZipArchiveOutputStream knows some tricks if it is writing to a file - take advantage of it

Added:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/FileAwareArchiveStreamFactory.java
      - copied, changed from r1154107, ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ArchiveStreamFactory.java
Modified:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java?rev=1154124&r1=1154123&r2=1154124&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
Fri Aug  5 08:32:40 2011
@@ -42,6 +42,7 @@ import org.apache.ant.compress.resources
 import org.apache.ant.compress.resources.ZipResource;
 import org.apache.ant.compress.util.ArchiveStreamFactory;
 import org.apache.ant.compress.util.EntryHelper;
+import org.apache.ant.compress.util.FileAwareArchiveStreamFactory;
 
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
@@ -59,6 +60,7 @@ import org.apache.tools.ant.types.Enumer
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.ResourceCollection;
 import org.apache.tools.ant.types.resources.ArchiveResource;
+import org.apache.tools.ant.types.resources.FileProvider;
 import org.apache.tools.ant.types.resources.FileResource;
 import org.apache.tools.ant.types.resources.MappedResource;
 import org.apache.tools.ant.types.resources.Resources;
@@ -513,11 +515,21 @@ public abstract class ArchiveBase extend
         ArchiveOutputStream out = null;
         Set addedDirectories = new HashSet();
         try {
-            out =
-                factory.getArchiveStream(new BufferedOutputStream(getDest()
-                                                                  .getOutputStream()),
-                                         Expand.NATIVE_ENCODING.equals(getEncoding())
-                                         ? null : getEncoding());
+            String enc = Expand.NATIVE_ENCODING.equals(getEncoding())
+                ? null : getEncoding();
+            if (factory instanceof FileAwareArchiveStreamFactory
+                && getDest().as(FileProvider.class) != null) {
+                FileProvider p =
+                    (FileProvider) getDest().as(FileProvider.class);
+                FileAwareArchiveStreamFactory f =
+                    (FileAwareArchiveStreamFactory) factory;
+                out = f.getArchiveOutputStream(p.getFile(), enc);
+            } else {
+                out =
+                    factory.getArchiveStream(new BufferedOutputStream(getDest()
+                                                                      .getOutputStream()),
+                                             enc);
+            }
             for (Iterator i = src.iterator(); i.hasNext(); ) {
                 ResourceWithFlags r = (ResourceWithFlags) i.next();
 

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java?rev=1154124&r1=1154123&r2=1154124&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java Fri Aug
 5 08:32:40 2011
@@ -18,6 +18,7 @@
 
 package org.apache.ant.compress.taskdefs;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.HashMap;
@@ -53,12 +54,15 @@ public class Zip extends ArchiveBase {
                     ZipArchiveOutputStream o =
                         (ZipArchiveOutputStream) super.getArchiveStream(stream,
                                                                         encoding);
-                    o.setLevel(level);
-                    o.setComment(comment);
-                    o.setFallbackToUTF8(fallBackToUTF8);
-                    o.setUseLanguageEncodingFlag(useLanguageEncodingFlag);
-                    o.setCreateUnicodeExtraFields(createUnicodeExtraFields
-                                                  .getPolicy());
+                    configure(o);
+                    return o;
+                }
+                public ArchiveOutputStream getArchiveOutputStream(File f,
+                                                                  String encoding)
+                    throws IOException {
+                    ZipArchiveOutputStream o = (ZipArchiveOutputStream)
+                        super.getArchiveOutputStream(f, encoding);
+                    configure(o);
                     return o;
                 }
             });
@@ -158,6 +162,14 @@ public class Zip extends ArchiveBase {
         createUnicodeExtraFields = b;
     }
 
+    private void configure(ZipArchiveOutputStream o) {
+        o.setLevel(level);
+        o.setComment(comment);
+        o.setFallbackToUTF8(fallBackToUTF8);
+        o.setUseLanguageEncodingFlag(useLanguageEncodingFlag);
+        o.setCreateUnicodeExtraFields(createUnicodeExtraFields.getPolicy());
+    }
+
     /**
      * Policiy for creation of Unicode extra fields: never, always or
      * not-encodeable.

Copied: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/FileAwareArchiveStreamFactory.java
(from r1154107, ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ArchiveStreamFactory.java)
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/FileAwareArchiveStreamFactory.java?p2=ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/FileAwareArchiveStreamFactory.java&p1=ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ArchiveStreamFactory.java&r1=1154107&r2=1154124&rev=1154124&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ArchiveStreamFactory.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/FileAwareArchiveStreamFactory.java
Fri Aug  5 08:32:40 2011
@@ -18,35 +18,38 @@
 
 package org.apache.ant.compress.util;
 
-import java.io.InputStream;
+import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
 
 /**
- * Creates streams for the supported archive formats.
+ * Creates streams for the supported archive formats that may take
+ * advantage of writing to/reading from a file.
+ *
+ * @since Apache Compress Antlib 1.1
  */
-public interface ArchiveStreamFactory {
-
+public interface FileAwareArchiveStreamFactory extends ArchiveStreamFactory {
     /**
-     * @param stream the stream to read from, should be buffered
+     * @param file the file to read from
      * @param encoding the encoding of the entry names, ignored by all
      * formats except zip
      */
-    public ArchiveInputStream getArchiveStream(InputStream stream,
-                                               String encoding)
+    public ArchiveInputStream getArchiveInputStream(File file,
+                                                    String encoding)
         throws IOException;
 
 
     /**
-     * @param stream the stream to write to, should be buffered
+     * @param file the file to write to
      * @param encoding the encoding of the entry names, ignored by all
      * formats except zip
      */
-    public ArchiveOutputStream getArchiveStream(OutputStream stream,
-                                                String encoding)
+    public ArchiveOutputStream getArchiveOutputStream(File file,
+                                                      String encoding)
         throws IOException;
 
 }
\ No newline at end of file

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java?rev=1154124&r1=1154123&r2=1154124&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java
Fri Aug  5 08:32:40 2011
@@ -18,8 +18,11 @@
 
 package org.apache.ant.compress.util;
 
-import java.io.InputStream;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.apache.commons.compress.archivers.ArchiveInputStream;
@@ -27,7 +30,7 @@ import org.apache.commons.compress.archi
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
 
-public class ZipStreamFactory implements ArchiveStreamFactory {
+public class ZipStreamFactory implements FileAwareArchiveStreamFactory {
 
     /**
      * @param stream the stream to read from, should be buffered
@@ -50,4 +53,30 @@ public class ZipStreamFactory implements
         o.setEncoding(encoding);
         return o;
     }
+
+    /**
+     * @param file the file to read from
+     * @param encoding the encoding of the entry names, ignored by all
+     * formats except zip
+     */
+    public ArchiveInputStream getArchiveInputStream(File file,
+                                                    String encoding)
+        throws IOException {
+        return
+            getArchiveStream(new BufferedInputStream(new FileInputStream(file)),
+                             encoding);
+    }
+
+    /**
+     * @param file the file to write to
+     * @param encoding the encoding of the entry names, ignored by all
+     * formats except zip
+     */
+    public ArchiveOutputStream getArchiveOutputStream(File file,
+                                                      String encoding)
+        throws IOException {
+        ZipArchiveOutputStream o = new ZipArchiveOutputStream(file);
+        o.setEncoding(encoding);
+        return o;
+    }
 }
\ No newline at end of file



Mime
View raw message