Browse Source

use nio for decoding of names - merge from commons-compress rev 746933

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@746934 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
8264511a27
2 changed files with 23 additions and 3 deletions
  1. +14
    -0
      src/main/org/apache/tools/zip/ZipEncodingHelper.java
  2. +9
    -3
      src/main/org/apache/tools/zip/ZipFile.java

+ 14
- 0
src/main/org/apache/tools/zip/ZipEncodingHelper.java View File

@@ -168,4 +168,18 @@ abstract class ZipEncodingHelper {


return enc.canEncode(name); 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();
}
} }

+ 9
- 3
src/main/org/apache/tools/zip/ZipFile.java View File

@@ -551,9 +551,15 @@ public class ZipFile {
return new String(bytes); return new String(bytes);
} else { } else {
try { 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());
}
} }
} }
} }


Loading…
Cancel
Save