git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@746934 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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(); | |||||
} | |||||
} | } |
@@ -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()); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||