My app default encoding is set to "UTF-8" (using -Dfile.encoding=UTF-8 on startup). When I use the String class method "getBytes(String charsetName)" with charset="ISO-8859-1", it appears that StringCoding.encode finally uses the default charset (UTF-8) instead of the given one (ISO-8859-1).
For an unknown reason, I can debug step by step on this method, but I'm not able to inspect inner elements value (only parameters which are named arg0, arg1 ...)
In java 1.6.10, StringCoding.encode is written :
static byte[] encode(String charsetName, char[] ca, int off, int len)
throws UnsupportedEncodingException
{
StringEncoder se = (StringEncoder)deref(encoder);
String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
if ((se == null) || !(csn.equals(se.requestedCharsetName())
|| csn.equals(se.charsetName()))) {
se = null;
try {
Charset cs = lookupCharset(csn);
if (cs != null)
se = new StringEncoder(cs, csn);
} catch (IllegalCharsetNameException x) {}
if (se == null)
throw new UnsupportedEncodingException (csn);
set(encoder, se);
}
return se.encode(ca, off, len);
}
With step by step debug, I never enter the if block and then no new StringEncoder with my ISO-8859-1 charset is created. Finally, the Charset.defaultCharset() method is called.
Any clues ? Thanks