Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sending multibyte characters through a stream

5 views
Skip to first unread message

jmpi...@gmail.com

unread,
Mar 19, 2007, 5:02:51 PM3/19/07
to
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.

Mook

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

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)

HTH,

--
Mook
mook dot moz plus stuff at gmail yadayada

0 new messages