Author: bodewig
Date: Sun Aug  9 06:59:25 2009
New Revision: 802496

URL: http://svn.apache.org/viewvc?rev=802496&view=rev
Log:
incomplete interface extraction refactoring

Added:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ArStreamFactory.java
   (with props)
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CpioStreamFactory.java
   (with props)
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/EntryHelper.java
   (with props)
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/StreamFactory.java
   (with props)
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/TarStreamFactory.java
   (with props)
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java
   (with props)
Modified:
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArResource.java
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioResource.java
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarResource.java
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unar.java
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Uncpio.java
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Untar.java
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java

Modified: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArResource.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArResource.java?rev=802496&r1=802495&r2=802496&view=diff
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArResource.java
 (original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArResource.java
 Sun Aug  9 06:59:25 2009
@@ -23,10 +23,9 @@
 import java.util.Date;
 
 import org.apache.tools.ant.types.Resource;
+import org.apache.ant.compress.util.ArStreamFactory;
 import org.apache.commons.compress.archivers.ArchiveEntry;
-import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.ar.ArArchiveEntry;
-import org.apache.commons.compress.archivers.ar.ArArchiveInputStream;
 
 /**
  * A Resource representation of an entry in a ar archive.
@@ -40,6 +39,7 @@
      * Default constructor.
      */
     public ArResource() {
+        super(new ArStreamFactory());
     }
 
     /**
@@ -49,7 +49,7 @@
      * @param e the ArEntry.
      */
     public ArResource(File a, ArArchiveEntry e) {
-        super(a, e);
+        super(new ArStreamFactory(), a, e);
     }
 
     /**
@@ -59,7 +59,7 @@
      * @param e the ArEntry.
      */
     public ArResource(Resource a, ArArchiveEntry e) {
-        super(a, e);
+        super(new ArStreamFactory(), a, e);
     }
 
     /**
@@ -91,15 +91,6 @@
         }
     }
 
-    protected ArchiveInputStream getArchiveStream(InputStream is)
-        throws IOException {
-        return new ArArchiveInputStream(is);
-    }
-
-    protected Date getLastModified(ArchiveEntry entry) {
-        return new Date(((ArArchiveEntry) entry).getLastModified() * 1000);
-    }
-
     protected int getMode(ArchiveEntry e) {
         return ((ArArchiveEntry) e).getMode();
     }

Modified: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java?rev=802496&r1=802495&r2=802496&view=diff
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java
 (original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java
 Sun Aug  9 06:59:25 2009
@@ -29,6 +29,8 @@
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.resources.ArchiveResource;
 import org.apache.tools.ant.util.FileUtils;
+import org.apache.ant.compress.util.EntryHelper;
+import org.apache.ant.compress.util.StreamFactory;
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
 
@@ -37,10 +39,14 @@
  */
 public abstract class CommonsCompressArchiveResource extends ArchiveResource {
 
+    private String encoding;
+    private final StreamFactory factory;
+
     /**
      * Default constructor.
      */
-    public CommonsCompressArchiveResource() {
+    protected CommonsCompressArchiveResource(StreamFactory factory) {
+        this.factory = factory;
     }
 
     /**
@@ -49,8 +55,10 @@
      * @param a the archive as File.
      * @param e the ArchiveEntry.
      */
-    public CommonsCompressArchiveResource(File a, ArchiveEntry e) {
+    protected CommonsCompressArchiveResource(StreamFactory factory, File a,
+                                             ArchiveEntry e) {
         super(a, true);
+        this.factory = factory;
         setEntry(e);
     }
 
@@ -60,16 +68,31 @@
      * @param a the archive as Resource.
      * @param e the ArchiveEntry.
      */
-    public CommonsCompressArchiveResource(Resource a, ArchiveEntry e) {
+    protected CommonsCompressArchiveResource(StreamFactory factory, Resource a,
+                                             ArchiveEntry e) {
         super(a, true);
+        this.factory = factory;
         setEntry(e);
     }
 
     /**
-     * Provides an ArchiveInputStream to a given archive.
+     * Set the encoding to use with the zipfile.
+     * @param enc the String encoding.
      */
-    protected abstract ArchiveInputStream getArchiveStream(InputStream is)
-        throws IOException;
+    public void setEncoding(String enc) {
+        checkAttributesAllowed();
+        encoding = enc;
+    }
+
+    /**
+     * Get the encoding to use with the zipfile.
+     * @return String encoding.
+     */
+    public String getEncoding() {
+        return isReference()
+            ? ((CommonsCompressArchiveResource) getCheckedRef()).getEncoding()
+            : encoding;
+    }
 
     /**
      * Return an InputStream for reading the contents of this Resource.
@@ -83,7 +106,8 @@
         }
         Resource archive = getArchive();
         final ArchiveInputStream i =
-            getArchiveStream(new 
BufferedInputStream(archive.getInputStream()));
+            factory.getArchiveStream(new 
BufferedInputStream(archive.getInputStream()),
+                                     getEncoding());
         ArchiveEntry ae = null;
         while ((ae = i.getNextEntry()) != null) {
             if (ae.getName().equals(getName())) {
@@ -126,7 +150,8 @@
         Resource archive = getArchive();
         ArchiveInputStream i = null;
         try {
-            i = getArchiveStream(archive.getInputStream());
+            i = factory.getArchiveStream(archive.getInputStream(),
+                                         getEncoding());
             ArchiveEntry ae = null;
             while ((ae = i.getNextEntry()) != null) {
                 if (ae.getName().equals(getName())) {
@@ -150,11 +175,6 @@
      */
     protected abstract int getMode(ArchiveEntry e);
 
-    /**
-     * Determines the last modified time for the given entry.
-     */
-    protected abstract Date getLastModified(ArchiveEntry entry);
-
     protected void setEntry(ArchiveEntry e) {
         if (e == null) {
             setExists(false);
@@ -162,7 +182,7 @@
         }
         setName(e.getName());
         setExists(true);
-        setLastModified(getLastModified(e).getTime());
+        setLastModified(EntryHelper.getLastModified(e).getTime());
         setDirectory(e.isDirectory());
         setSize(e.getSize());
         setMode(getMode(e));

Modified: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioResource.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioResource.java?rev=802496&r1=802495&r2=802496&view=diff
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioResource.java
 (original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioResource.java
 Sun Aug  9 06:59:25 2009
@@ -23,10 +23,9 @@
 import java.util.Date;
 
 import org.apache.tools.ant.types.Resource;
+import org.apache.ant.compress.util.CpioStreamFactory;
 import org.apache.commons.compress.archivers.ArchiveEntry;
-import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.cpio.CpioArchiveEntry;
-import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;
 
 /**
  * A Resource representation of an entry in a cpio archive.
@@ -40,6 +39,7 @@
      * Default constructor.
      */
     public CpioResource() {
+        super(new CpioStreamFactory());
     }
 
     /**
@@ -49,7 +49,7 @@
      * @param e the CpioEntry.
      */
     public CpioResource(File a, CpioArchiveEntry e) {
-        super(a, e);
+        super(new CpioStreamFactory(), a, e);
     }
 
     /**
@@ -59,7 +59,7 @@
      * @param e the CpioEntry.
      */
     public CpioResource(Resource a, CpioArchiveEntry e) {
-        super(a, e);
+        super(new CpioStreamFactory(), a, e);
     }
 
     /**
@@ -91,15 +91,6 @@
         }
     }
 
-    protected ArchiveInputStream getArchiveStream(InputStream is)
-        throws IOException {
-        return new CpioArchiveInputStream(is);
-    }
-
-    protected Date getLastModified(ArchiveEntry entry) {
-        return new Date(((CpioArchiveEntry) entry).getTime() * 1000);
-    }
-
     protected int getMode(ArchiveEntry e) {
         return (int) ((CpioArchiveEntry) e).getMode();
     }

Modified: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarResource.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarResource.java?rev=802496&r1=802495&r2=802496&view=diff
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarResource.java
 (original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarResource.java
 Sun Aug  9 06:59:25 2009
@@ -23,10 +23,9 @@
 import java.util.Date;
 
 import org.apache.tools.ant.types.Resource;
+import org.apache.ant.compress.util.TarStreamFactory;
 import org.apache.commons.compress.archivers.ArchiveEntry;
-import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
-import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
 
 /**
  * A Resource representation of an entry in a tar archive.
@@ -42,6 +41,7 @@
      * Default constructor.
      */
     public TarResource() {
+        super(new TarStreamFactory());
     }
 
     /**
@@ -51,7 +51,7 @@
      * @param e the TarEntry.
      */
     public TarResource(File a, TarArchiveEntry e) {
-        super(a, e);
+        super(new TarStreamFactory(), a, e);
     }
 
     /**
@@ -61,7 +61,7 @@
      * @param e the TarEntry.
      */
     public TarResource(Resource a, TarArchiveEntry e) {
-        super(a, e);
+        super(new TarStreamFactory(), a, e);
     }
 
     /**
@@ -115,15 +115,6 @@
         }
     }
 
-    protected ArchiveInputStream getArchiveStream(InputStream is)
-        throws IOException {
-        return new TarArchiveInputStream(is);
-    }
-
-    protected Date getLastModified(ArchiveEntry entry) {
-        return ((TarArchiveEntry) entry).getModTime();
-    }
-
     protected int getMode(ArchiveEntry e) {
         return ((TarArchiveEntry) e).getMode();
     }

Modified: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java?rev=802496&r1=802495&r2=802496&view=diff
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
 (original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
 Sun Aug  9 06:59:25 2009
@@ -30,10 +30,10 @@
 import org.apache.tools.ant.types.Reference;
 import org.apache.tools.ant.util.FileUtils;
 
+import org.apache.ant.compress.util.ZipStreamFactory;
+
 import org.apache.commons.compress.archivers.ArchiveEntry;
-import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
-import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.apache.commons.compress.archivers.zip.ZipExtraField;
 import org.apache.commons.compress.archivers.zip.ZipFile;
 
@@ -42,13 +42,13 @@
  */
 public class ZipResource extends CommonsCompressArchiveResource {
 
-    private String encoding;
     private ZipExtraField[] extras;
 
     /**
      * Default constructor.
      */
     public ZipResource() {
+        super(new ZipStreamFactory());
     }
 
     /**
@@ -59,7 +59,7 @@
      * @param e the ZipEntry.
      */
     public ZipResource(File z, String enc, ZipArchiveEntry e) {
-        super(z, e);
+        super(new ZipStreamFactory(), z, e);
         setEncoding(enc);
     }
 
@@ -71,7 +71,7 @@
      * @param e the ZipEntry.
      */
     public ZipResource(Resource z, String enc, ZipArchiveEntry e) {
-        super(z, e);
+        super(new ZipStreamFactory(), z, e);
         setEncoding(enc);
     }
 
@@ -87,7 +87,7 @@
      * Set the zipfile that holds this ZipResource.
      * @param z the zipfile as a Resource.
      */
-    public void setZipfile(Resource z) {
+    public void setZipResource(Resource z) {
         addConfigured(z);
     }
 
@@ -101,29 +101,11 @@
     }
 
     /**
-     * Set the encoding to use with the zipfile.
-     * @param enc the String encoding.
-     */
-    public void setEncoding(String enc) {
-        checkAttributesAllowed();
-        encoding = enc;
-    }
-
-    /**
-     * Get the encoding to use with the zipfile.
-     * @return String encoding.
-     */
-    public String getEncoding() {
-        return isReference()
-            ? ((ZipResource) getCheckedRef()).getEncoding() : encoding;
-    }
-
-    /**
      * Overrides the super version.
      * @param r the Reference to set.
      */
     public void setRefid(Reference r) {
-        if (encoding != null) {
+        if (getEncoding() != null) {
             throw tooManyAttributes();
         }
         super.setRefid(r);
@@ -206,15 +188,6 @@
         }
     }
 
-    protected ArchiveInputStream getArchiveStream(InputStream is)
-        throws IOException {
-        return new ZipArchiveInputStream(is, getEncoding(), true);
-    }
-
-    protected Date getLastModified(ArchiveEntry entry) {
-        return new Date(((ZipArchiveEntry) entry).getTime());
-    }
-
     protected int getMode(ArchiveEntry e) {
         return ((ZipArchiveEntry) e).getUnixMode();
     }

Modified: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java?rev=802496&r1=802495&r2=802496&view=diff
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java
 (original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java
 Sun Aug  9 06:59:25 2009
@@ -25,6 +25,9 @@
 import java.io.InputStream;
 import java.util.Date;
 
+import org.apache.ant.compress.util.EntryHelper;
+import org.apache.ant.compress.util.StreamFactory;
+
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.Expand;
@@ -46,6 +49,12 @@
  * <p>File permissions will not be restored on extracted files.</p>
  */
 public abstract class ExpandBase extends Expand {
+    private final StreamFactory factory;
+
+    protected ExpandBase(StreamFactory factory) {
+        this.factory = factory;
+    }
+
     /**
      * No encoding support in general.
      * @param encoding not used
@@ -105,24 +114,20 @@
         }
     }
 
-    protected abstract ArchiveInputStream getArchiveStream(InputStream is)
-        throws IOException;
-
-    protected abstract Date getLastModified(ArchiveEntry entry);
-
     private void expandStream(String name, InputStream stream, File dir)
         throws IOException {
         ArchiveInputStream is = null;
         try {
             FileNameMapper mapper = getMapper();
             log("Expanding: " + name + " into " + dir, Project.MSG_INFO);
-            is = getArchiveStream(new BufferedInputStream(stream));
+            is = factory.getArchiveStream(new BufferedInputStream(stream),
+                                          getEncoding());
             boolean empty = true;
             ArchiveEntry ent = null;
             while ((ent = is.getNextEntry()) != null) {
                 empty = false;
                 extractFile(FileUtils.getFileUtils(), null, dir, is,
-                            ent.getName(), getLastModified(ent),
+                            ent.getName(), EntryHelper.getLastModified(ent),
                             ent.isDirectory(), mapper);
             }
             if (empty && getFailOnEmptyArchive()) {

Modified: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unar.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unar.java?rev=802496&r1=802495&r2=802496&view=diff
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unar.java
 (original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unar.java
 Sun Aug  9 06:59:25 2009
@@ -18,27 +18,13 @@
 
 package org.apache.ant.compress.taskdefs;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-
-import org.apache.commons.compress.archivers.ArchiveEntry;
-import org.apache.commons.compress.archivers.ArchiveInputStream;
-import org.apache.commons.compress.archivers.ar.ArArchiveEntry;
-import org.apache.commons.compress.archivers.ar.ArArchiveInputStream;
+import org.apache.ant.compress.util.ArStreamFactory;
 
 /**
  * Unar a file.
  */
 public class Unar extends ExpandBase {
-    protected ArchiveInputStream getArchiveStream(InputStream is)
-        throws IOException {
-        return new ArArchiveInputStream(is);
-    }
-
-    protected Date getLastModified(ArchiveEntry entry) {
-        /* TODO - revisit */
-        return new Date(((ArArchiveEntry) entry).getLastModified() * 1000);
+    public Unar() {
+        super(new ArStreamFactory());
     }
-
 }

Modified: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Uncpio.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Uncpio.java?rev=802496&r1=802495&r2=802496&view=diff
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Uncpio.java
 (original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Uncpio.java
 Sun Aug  9 06:59:25 2009
@@ -18,26 +18,13 @@
 
 package org.apache.ant.compress.taskdefs;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-
-import org.apache.commons.compress.archivers.ArchiveEntry;
-import org.apache.commons.compress.archivers.ArchiveInputStream;
-import org.apache.commons.compress.archivers.cpio.CpioArchiveEntry;
-import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;
+import org.apache.ant.compress.util.CpioStreamFactory;
 
 /**
  * Uncpio a file.
  */
 public class Uncpio extends ExpandBase {
-    protected ArchiveInputStream getArchiveStream(InputStream is)
-        throws IOException {
-        return new CpioArchiveInputStream(is);
-    }
-
-    protected Date getLastModified(ArchiveEntry entry) {
-        return new Date(((CpioArchiveEntry) entry).getTime() * 1000);
+    public Uncpio() {
+        super(new CpioStreamFactory());
     }
-
 }

Modified: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Untar.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Untar.java?rev=802496&r1=802495&r2=802496&view=diff
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Untar.java
 (original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Untar.java
 Sun Aug  9 06:59:25 2009
@@ -18,26 +18,13 @@
 
 package org.apache.ant.compress.taskdefs;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-
-import org.apache.commons.compress.archivers.ArchiveEntry;
-import org.apache.commons.compress.archivers.ArchiveInputStream;
-import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
-import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.ant.compress.util.TarStreamFactory;
 
 /**
  * Untar a file.
  */
 public class Untar extends ExpandBase {
-    protected ArchiveInputStream getArchiveStream(InputStream is)
-        throws IOException {
-        return new TarArchiveInputStream(is);
-    }
-
-    protected Date getLastModified(ArchiveEntry entry) {
-        return ((TarArchiveEntry) entry).getModTime();
+    public Untar() {
+        super(new TarStreamFactory());
     }
-
 }

Modified: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java?rev=802496&r1=802495&r2=802496&view=diff
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java
 (original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java
 Sun Aug  9 06:59:25 2009
@@ -24,10 +24,9 @@
 import java.util.Date;
 import java.util.Enumeration;
 
-import org.apache.commons.compress.archivers.ArchiveEntry;
-import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.ant.compress.util.ZipStreamFactory;
+
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
-import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.apache.commons.compress.archivers.zip.ZipFile;
 
 import org.apache.tools.ant.BuildException;
@@ -40,12 +39,13 @@
  */
 public class Unzip extends ExpandBase {
 
+    public Unzip() {
+        super(new ZipStreamFactory());
+    }
+
     public void setEncoding(String encoding) {
         internalSetEncoding(encoding);
     }
-    public void setScanForUnicodeExtraFields(boolean b) {
-        internalSetScanForUnicodeExtraFields(b);
-    }
 
     // overridden in order to take advantage of ZipFile
     protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
@@ -58,8 +58,7 @@
                                      getLocation());
         }
         try {
-            zf = new ZipFile(srcF, getEncoding(),
-                             getScanForUnicodeExtraFields());
+            zf = new ZipFile(srcF, getEncoding(), true);
             boolean empty = true;
             Enumeration e = zf.getEntries();
             while (e.hasMoreElements()) {
@@ -83,14 +82,4 @@
         }
     }
 
-    protected ArchiveInputStream getArchiveStream(InputStream is)
-        throws IOException {
-        return new ZipArchiveInputStream(is, getEncoding(),
-                                         getScanForUnicodeExtraFields());
-    }
-
-    protected Date getLastModified(ArchiveEntry entry) {
-        return new Date(((ZipArchiveEntry) entry).getTime());
-    }
-
 }

Added: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ArStreamFactory.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ArStreamFactory.java?rev=802496&view=auto
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ArStreamFactory.java
 (added)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ArStreamFactory.java
 Sun Aug  9 06:59:25 2009
@@ -0,0 +1,39 @@
+/*
+ *  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.
+ *
+ */
+
+package org.apache.ant.compress.util;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.ar.ArArchiveInputStream;
+
+public class ArStreamFactory implements StreamFactory {
+
+    /**
+     * @param stream the stream to read from, should be buffered
+     * @param encoding the encoding of the entry names, ignored
+     */
+    public ArchiveInputStream getArchiveStream(InputStream stream,
+                                               String encoding)
+        throws IOException {
+        return new ArArchiveInputStream(stream);
+    }
+
+}
\ No newline at end of file

Propchange: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ArStreamFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CpioStreamFactory.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CpioStreamFactory.java?rev=802496&view=auto
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CpioStreamFactory.java
 (added)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CpioStreamFactory.java
 Sun Aug  9 06:59:25 2009
@@ -0,0 +1,39 @@
+/*
+ *  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.
+ *
+ */
+
+package org.apache.ant.compress.util;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;
+
+public class CpioStreamFactory implements StreamFactory {
+
+    /**
+     * @param stream the stream to read from, should be buffered
+     * @param encoding the encoding of the entry names, ignored
+     */
+    public ArchiveInputStream getArchiveStream(InputStream stream,
+                                               String encoding)
+        throws IOException {
+        return new CpioArchiveInputStream(stream);
+    }
+
+}
\ No newline at end of file

Propchange: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/CpioStreamFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/EntryHelper.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/EntryHelper.java?rev=802496&view=auto
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/EntryHelper.java
 (added)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/EntryHelper.java
 Sun Aug  9 06:59:25 2009
@@ -0,0 +1,61 @@
+/*
+ *  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.
+ *
+ */
+
+package org.apache.ant.compress.util;
+
+import java.util.Date;
+
+import org.apache.tools.ant.BuildException;
+
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ar.ArArchiveEntry;
+import org.apache.commons.compress.archivers.cpio.CpioArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+
+/**
+ * Helper methods that gloss over API differences between the
+ * ArchiveEntry implementations of Apache Commons Compress 1.0.
+ */
+public class EntryHelper {
+    private EntryHelper() {}
+
+    /**
+     * Can be replaced with entry.getLastModifiedDate in ACC 1.1
+     */
+    public static Date getLastModified(ArchiveEntry entry) {
+        if (entry == null) {
+            throw new IllegalArgumentException("entry must not be null.");
+        }
+
+        if (entry instanceof ArArchiveEntry) {
+            return new Date(((ArArchiveEntry) entry).getLastModified() * 1000);
+        }
+        if (entry instanceof CpioArchiveEntry) {
+            return new Date(((CpioArchiveEntry) entry).getTime() * 1000);
+        }
+        if (entry instanceof TarArchiveEntry) {
+            return ((TarArchiveEntry) entry).getModTime();
+        }
+        if (entry instanceof ZipArchiveEntry) {
+            return new Date(((ZipArchiveEntry) entry).getTime());
+        }
+        throw new BuildException("archive entry " + entry.getClass()
+                                 + " is not supported.");
+    }
+}
\ No newline at end of file

Propchange: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/EntryHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/StreamFactory.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/StreamFactory.java?rev=802496&view=auto
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/StreamFactory.java
 (added)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/StreamFactory.java
 Sun Aug  9 06:59:25 2009
@@ -0,0 +1,40 @@
+/*
+ *  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.
+ *
+ */
+
+package org.apache.ant.compress.util;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+
+/**
+ * Creates input streams for the supported archive formats.
+ */
+public interface StreamFactory {
+
+    /**
+     * @param stream the stream to read from, should be buffered
+     * @param encoding the encoding of the entry names, ignored by all
+     * formats except zip
+     */
+    public ArchiveInputStream getArchiveStream(InputStream stream,
+                                               String encoding)
+        throws IOException;
+
+}
\ No newline at end of file

Propchange: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/StreamFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/TarStreamFactory.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/TarStreamFactory.java?rev=802496&view=auto
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/TarStreamFactory.java
 (added)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/TarStreamFactory.java
 Sun Aug  9 06:59:25 2009
@@ -0,0 +1,39 @@
+/*
+ *  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.
+ *
+ */
+
+package org.apache.ant.compress.util;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+
+public class TarStreamFactory implements StreamFactory {
+
+    /**
+     * @param stream the stream to read from, should be buffered
+     * @param encoding the encoding of the entry names, ignored
+     */
+    public ArchiveInputStream getArchiveStream(InputStream stream,
+                                               String encoding)
+        throws IOException {
+        return new TarArchiveInputStream(stream);
+    }
+
+}
\ No newline at end of file

Propchange: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/TarStreamFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java?rev=802496&view=auto
==============================================================================
--- 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java
 (added)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java
 Sun Aug  9 06:59:25 2009
@@ -0,0 +1,39 @@
+/*
+ *  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.
+ *
+ */
+
+package org.apache.ant.compress.util;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
+
+public class ZipStreamFactory implements StreamFactory {
+
+    /**
+     * @param stream the stream to read from, should be buffered
+     * @param encoding the encoding of the entry names
+     */
+    public ArchiveInputStream getArchiveStream(InputStream stream,
+                                               String encoding)
+        throws IOException {
+        return new ZipArchiveInputStream(stream, encoding, true);
+    }
+
+}
\ No newline at end of file

Propchange: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to