i have a problem with pathname strings from File objects. they appear
to be in a weird encoding which results in me being unable to
transcode them to other charsets and transfer them using
OpenSoundControl. the problem arises with characters not in the lower
7 bit of standard ascii, for example umlauts. like the following:
java.awt.FileDialog fd = new java.awt.FileDialog( new java.awt.Frame
() );
fd.show();
final String fileName = fd.getFile();
final java.nio.ByteBuffer bb3 = java.nio.ByteBuffer.wrap
( fileName.getBytes() );
printHexOn( System.out, bb3 );
... running this and choosing a file 'รค.aif' (ä.aif) from the
finder results in:
0000 61 3f 2e 61 69 66 |a?.aif|
even the length of the string is 6 not 5. the system default charset
is MacRoman, so the a-umlaut should come out as 0x8A . if i use a
regular java string "\u00E4.aif", it gets converted correctly:
strangely, i can store the files in my preferences (using
java.util.prefs.Preferences and the values are retrieved using
file.getAbsolutePath()) and recall them without problems. i even can
create File objects again from these preferences and i can open the
files (only i cannot transmit the filename over network as i cannot
convert to one of the 8-bit charsets). also if i display the file
names in a JTextField, the umlauts are shown correctly.
in fact, if i dump my plist file, the strings are either stored with
one byte per character if no umlauts are contained, or in the "weird"
unknown encoding with two bytes per character - probably UTF-16, but
with a wrong encoding of a-umlaut which is represented as four bytes
61 03 08 00 :
i tired to use specific charsets for decoding (like fileName.getBytes
( "ISO-8859-1" ), fileName.getBytes( "UTF-8", ...), no luck, i always
end up with umlauts appearing as two bytes a-?, o-?, u-? etc.
is this a bug of the apple implementation of File ? what is that
weird character set that represents a-umlaut as (char) 0x61 + (char)
0x308 and why can't i transcode it ? Is there a workaround to
eventually get iso-latin-1 or utf-8 or whatever strings which
preserve my umlauts from File objects?
public static void printHexOn( PrintStream stream, ByteBuffer b )
{
final int lim = b.limit(); // len = b.limit() - off;
final byte[] txt = new byte[ 74 ];
int i, j, k, n, m;
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden