G
Gordon Beaton
I have a .c program using jni and sending and receiving messages via
jms. All seems to work well, except for 1 problem.
If I embed some binary bytes (e.g. 0x00,0x01,0x02,0x03,0x04) in the
middle of the buffer,
[...]
Then in the c program I get a "jstring" object back from Java via
the the CallObjectMethod and then do a "GetStringUTFChars" to
convert the jstring to the char * .c string. It seems that the
binary 0x00 is changed to 0xc080.
Don't assume that your binary data can be treated as though it were
text, which it isn't. Strings and binary data are different animals.
Unless you have good reason to, you shouldn't be converting between
them. And when you do, you should almost always specify what encoding
to use. For example, see the API documentation for the String
constructor that takes a byte array and a character encoding, and the
String method getBytes(encoding).
Realize too that UTF is not the same thing as ASCII or Latin1, or
whatever you were expecting to find in the char*.
Anyone know what is the correct way to do this?
To do *what*?
/gordon