ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r746934 - in /ant/core/trunk/src/main/org/apache/tools/zip: ./ AbstractUnicodeExtraField.java ExtraFieldUtils.java UnicodeCommentExtraField.java UnicodePathExtraField.java ZipEncodingHelper.java ZipFile.java
Date Mon, 23 Feb 2009 09:08:13 GMT
Author: bodewig
Date: Mon Feb 23 09:08:11 2009
New Revision: 746934

URL: http://svn.apache.org/viewvc?rev=746934&view=rev
Log:
use nio for decoding of names - merge from commons-compress rev 746933

Modified:
    ant/core/trunk/src/main/org/apache/tools/zip/   (props changed)
    ant/core/trunk/src/main/org/apache/tools/zip/AbstractUnicodeExtraField.java   (props changed)
    ant/core/trunk/src/main/org/apache/tools/zip/ExtraFieldUtils.java   (props changed)
    ant/core/trunk/src/main/org/apache/tools/zip/UnicodeCommentExtraField.java   (props changed)
    ant/core/trunk/src/main/org/apache/tools/zip/UnicodePathExtraField.java   (props changed)
    ant/core/trunk/src/main/org/apache/tools/zip/ZipEncodingHelper.java   (contents, props
changed)
    ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java   (contents, props changed)

Propchange: ant/core/trunk/src/main/org/apache/tools/zip/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Feb 23 09:08:11 2009
@@ -0,0 +1 @@
+/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip:746933

Propchange: ant/core/trunk/src/main/org/apache/tools/zip/AbstractUnicodeExtraField.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb 23 09:08:11 2009
@@ -1 +1,2 @@
 /ant/core/trunk/src/main/org/apache/tools/zip/AbstractUnicodeExtraField.java:738844,739300,741089
+/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/AbstractUnicodeExtraField.java:746933

Propchange: ant/core/trunk/src/main/org/apache/tools/zip/ExtraFieldUtils.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb 23 09:08:11 2009
@@ -1 +1 @@
-/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java:745528
+/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java:745528,746933

Propchange: ant/core/trunk/src/main/org/apache/tools/zip/UnicodeCommentExtraField.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb 23 09:08:11 2009
@@ -1 +1,2 @@
 /ant/core/trunk/src/main/org/apache/tools/zip/UnicodeCommentExtraField.java:738844,739300,741089
+/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnicodeCommentExtraField.java:746933

Propchange: ant/core/trunk/src/main/org/apache/tools/zip/UnicodePathExtraField.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb 23 09:08:11 2009
@@ -1 +1,2 @@
 /ant/core/trunk/src/main/org/apache/tools/zip/UnicodePathExtraField.java:738844,739300,741089
+/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnicodePathExtraField.java:746933

Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipEncodingHelper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipEncodingHelper.java?rev=746934&r1=746933&r2=746934&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/zip/ZipEncodingHelper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/zip/ZipEncodingHelper.java Mon Feb 23 09:08:11
2009
@@ -168,4 +168,18 @@
 
         return enc.canEncode(name);
     }
+
+    /**
+     * Decode a filename or a comment from a byte array.
+     * 
+     * @param name The filename or comment.
+     * @param encoding A valid encoding name. The standard zip
+     *                 encoding is <code>"CP437"</code>,
+     *                 <code>"UTF-8"</code> is supported in ZIP file
+     *                 version <code>6.3</code> or later.
+     */
+    static final String decodeName(byte[] name, String encoding) {
+        Charset cs = Charset.forName(encoding);
+        return cs.decode(ByteBuffer.wrap(name)).toString();
+    }
 }

Propchange: ant/core/trunk/src/main/org/apache/tools/zip/ZipEncodingHelper.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb 23 09:08:11 2009
@@ -1 +1,2 @@
 /ant/core/trunk/src/main/org/apache/tools/zip/ZipEncodingHelper.java:738844,739300,741089
+/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java:746933

Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java?rev=746934&r1=746933&r2=746934&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java Mon Feb 23 09:08:11 2009
@@ -551,9 +551,15 @@
             return new String(bytes);
         } else {
             try {
-                return new String(bytes, enc);
-            } catch (UnsupportedEncodingException uee) {
-                throw new ZipException(uee.getMessage());
+                return ZipEncodingHelper.decodeName(bytes, encoding);
+            } catch (java.nio.charset.UnsupportedCharsetException ex) {
+                // Java 1.4's NIO doesn't recognize a few names that
+                // String.getBytes does
+                try {
+                    return new String(bytes, enc);
+                } catch (UnsupportedEncodingException uee) {
+                    throw new ZipException(uee.getMessage());
+                }
             }
         }
     }

Propchange: ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb 23 09:08:11 2009
@@ -1 +1 @@
-/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java:745920
+/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java:745920,746933



Mime
View raw message