commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1358626 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
Date Sat, 07 Jul 2012 19:34:12 GMT
Author: bodewig
Date: Sat Jul  7 19:34:11 2012
New Revision: 1358626

URL: http://svn.apache.org/viewvc?rev=1358626&view=rev
Log:
COMPRESS-192 add an encoding option to ArchiveStreamFactory for zip and tar.  Based on patch
by Jukka Zitting

Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1358626&r1=1358625&r2=1358626&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Sat Jul  7 19:34:11 2012
@@ -44,6 +44,11 @@ The <action> type attribute can be add,u
   <body>
     <release version="1.5" date="not released, yet"
              description="Release 1.5">
+      <action type="update" date="2012-07-07" issue="COMPRESS-192"
+              due-to="Jukka Zitting">
+        ArchiveStreamFactory has a setting for file name encoding that
+        sets up encoding for ZIP and TAR streams.
+      </action>
       <action type="fix" date="2012-07-07" issue="COMPRESS-191"
               due-to="Jukka Zitting">
         ArchiveStreamFactory's tar stream detection created false

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java?rev=1358626&r1=1358625&r2=1358626&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
Sat Jul  7 19:34:11 2012
@@ -105,6 +105,33 @@ public class ArchiveStreamFactory {
     public static final String ZIP = "zip";
 
     /**
+     * Entry encoding, null for the default.
+     */
+    private String entryEncoding = null;
+
+    /**
+     * Returns the encoding to use for zip and tar files, or null for
+     * the default.
+     *
+     * @return entry encoding, or null
+     * @since 1.5
+     */
+    public String getEntryEncoding() {
+        return entryEncoding;
+    }
+
+    /**
+     * Sets the encoding to use for zip and tar files. Use null for
+     * the default.
+     *
+     * @return entryEncoding entry encoding, or null
+     * @since 1.5
+     */
+    public void setEntryEncoding(String entryEncoding) {
+        this.entryEncoding = entryEncoding;
+    }
+
+    /**
      * Create an archive input stream from an archiver name and an input stream.
      * 
      * @param archiverName the archive name, i.e. "ar", "zip", "tar", "jar", "dump" or "cpio"
@@ -129,10 +156,18 @@ public class ArchiveStreamFactory {
             return new ArArchiveInputStream(in);
         }
         if (ZIP.equalsIgnoreCase(archiverName)) {
-            return new ZipArchiveInputStream(in);
+            if (entryEncoding != null) {
+                return new ZipArchiveInputStream(in, entryEncoding);
+            } else {
+                return new ZipArchiveInputStream(in);
+            }
         }
         if (TAR.equalsIgnoreCase(archiverName)) {
-            return new TarArchiveInputStream(in);
+            if (entryEncoding != null) {
+                return new TarArchiveInputStream(in, entryEncoding);
+            } else {
+                return new TarArchiveInputStream(in);
+            }
         }
         if (JAR.equalsIgnoreCase(archiverName)) {
             return new JarArchiveInputStream(in);
@@ -170,10 +205,18 @@ public class ArchiveStreamFactory {
             return new ArArchiveOutputStream(out);
         }
         if (ZIP.equalsIgnoreCase(archiverName)) {
-            return new ZipArchiveOutputStream(out);
+            ZipArchiveOutputStream zip = new ZipArchiveOutputStream(out);
+            if (entryEncoding != null) {
+                zip.setEncoding(entryEncoding);
+            }
+            return zip;
         }
         if (TAR.equalsIgnoreCase(archiverName)) {
-            return new TarArchiveOutputStream(out);
+            if (entryEncoding != null) {
+                return new TarArchiveOutputStream(out, entryEncoding);
+            } else {
+                return new TarArchiveOutputStream(out);
+            }
         }
         if (JAR.equalsIgnoreCase(archiverName)) {
             return new JarArchiveOutputStream(out);
@@ -210,7 +253,11 @@ public class ArchiveStreamFactory {
             int signatureLength = in.read(signature);
             in.reset();
             if (ZipArchiveInputStream.matches(signature, signatureLength)) {
-                return new ZipArchiveInputStream(in);
+                if (entryEncoding != null) {
+                    return new ZipArchiveInputStream(in, entryEncoding);
+                } else {
+                    return new ZipArchiveInputStream(in);
+                }
             } else if (JarArchiveInputStream.matches(signature, signatureLength)) {
                 return new JarArchiveInputStream(in);
             } else if (ArArchiveInputStream.matches(signature, signatureLength)) {
@@ -234,7 +281,11 @@ public class ArchiveStreamFactory {
             signatureLength = in.read(tarheader);
             in.reset();
             if (TarArchiveInputStream.matches(tarheader, signatureLength)) {
-                return new TarArchiveInputStream(in);
+                if (entryEncoding != null) {
+                    return new TarArchiveInputStream(in, entryEncoding);
+                } else {
+                    return new TarArchiveInputStream(in);
+                }
             }
             // COMPRESS-117 - improve auto-recognition
             if (signatureLength >= 512) {
@@ -257,4 +308,5 @@ public class ArchiveStreamFactory {
 
         throw new ArchiveException("No Archiver found for the stream signature");
     }
+
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java?rev=1358626&r1=1358625&r2=1358626&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
Sat Jul  7 19:34:11 2012
@@ -129,7 +129,16 @@ public class ZipArchiveInputStream exten
     private static final long TWO_EXP_32 = ZIP64_MAGIC + 1;
 
     public ZipArchiveInputStream(InputStream inputStream) {
-        this(inputStream, ZipEncodingHelper.UTF8, true);
+        this(inputStream, ZipEncodingHelper.UTF8);
+    }
+
+    /**
+     * @param encoding the encoding to use for file names, use null
+     * for the platform's default encoding
+     * @since 1.5
+     */
+    public ZipArchiveInputStream(InputStream inputStream, String encoding) {
+        this(inputStream, encoding, true);
     }
 
     /**



Mime
View raw message