Hi all,
I am trying to encode a String with the content, "Gratulerer! Du har n \u00e5" into norwegian, the \u00e5 which should be replaced by a "å" . I have tried the following,
public static String doEncode(String text) throws IOException{
return new String(text.getBytes(),"ISO-8859-1");
}
public static String doEncode(String text) throws IOException{
CharsetEncoder charSetEncode = Charset.forName("ISO-8859-1").newEncoder();
charSetEncode.reset();
ByteBuffer buffer = ByteBuffer.allocate(text.length());
charSetEncode.encode(CharBuffer.wrap(text.toCharArray()), buffer, true);
return new String(buffer.array());
}
both the above methods return the following, "Gratulerer! Du har n å"
If i replaced ISO-8859-1 with UTF8, I get "Gratulerer! Du har n å"
I run the program with a -Dfile.encoding=UTF8, jvm option so as to emulate the default encoding of glassfish. if the same option were set to use ISO8859_1, i get the expected behavior, but since UTF8 is a superset of ISO8859_1, I was hoping to get the same result. I am not permitted to change the encoding of glassfish, since certain other things on the UI get falsely displayed.
thanks,
vijai