Sending multibyte characters through a stream

Skip to first unread message

Mar 19, 2007, 5:02:51 PM3/19/07
I have a Firefox extension that opens a socket to a Java program. When
I attempt to send back the html content of a page that contains
multibyte characters, I lose the encoding information, and the
multibyte characters become garbled on the Java side. Ideally, I'd
like to be able to send the data back to Java encoded in UTF-8
regardless of the encoding of the page.

Currently I'm using an instance of nsIBinaryOutputStream and calling
write(msg, msg.length) to send the string through the socket.

I have been unable to setup a nsIConverterOutputStream, or pretty much
any of the localization interfaces properly to handle the conversion
to UTF-8.

Any help on this would be greatly appreciated.


Mar 19, 2007, 5:38:19 PM3/19/07

nsIBinaryOutputStream::writeUtf8Z sounds like what you'd want (assuming
no embedded null bytes). You're calling nsIOutputStream::write(string,
unsigned long) (which nsIBinaryOutputStream inherits), and that takes
(non-Unicode) chars. If you're JavaScript, that means that xpconnect
needs to lossily convert your Unicode strings.

You can also try using nsIScriptableUnicodeConverter to convert your
Unicode (UTF16, actually) strings to UTF8.

(follow-up set to m.d.extensions)


mook dot moz plus stuff at gmail yadayada

Reply all
Reply to author
0 new messages