[JDEV] unicode client in java

Edwin van Ouwerkerk Moria edwin at cadwal.org
Thu Oct 4 05:44:15 CDT 2001


On Wed, 3 Oct 2001, David Rainville wrote:

>     I'm developping a java client for jabber but sometimes it disconnects. I
> discovered that it was because I don't support unicode ... how can I arrange
> this? ( or support it ) in Java?

Heh. Recently been bitten by this problem myself 8-) Anyway, Unicode is
natively supported in/used by Java. What you're sending across the wire is
quite another thing: Depending on how you are writing data
to the socket, a few things may be going wrong:

If you're using an OutputStream (i.e. sending raw bytes obtained by
calling String.getBytes()), make sure that everything you send is
XML-safe - i.e. no un-encoded <, >, & etc. in the message, and encode all
'international' characters.

If you are using a PrintWriter or somesuch, make sure you have selected
the right encoding (use OutputStreamWriter.setEncoding("UTF8")). If you
don't, Java will select a 'default encoding' based on your platform. That
could result in you sending non-XML-safe stuff, and the server will drop
your connection when it receives invalid XML.

Processing received XML is exactly the other way around: for byte[], use
String(byte[],"UTF8"). If you're using InputStreamReaders, set the
encoding to UTF8 (new InputStreamReader(InputStream,"UTF8"))

-- 
CU,
  Edwin
 --
He who has imagination without learning has wings but no feet.




More information about the JDev mailing list