Hi Burca,

It doesn't sound like the third party app uses UTF-8 - you just need to specify the ISO-8859-1 encoding when creating your decoder, not UTF-8.

CharBuffer decode = Charset.forName("ISO-8859-1").decode(ByteBuffer.wrap(new byte[] {(byte)220}));
       System.out.println(decode);

Brad.

Burca Ciprian wrote:
I understand all these. The problem is that this is the way the data comes
to me from a 3rd party application, with encoded DC hexa. This sample app I
just created it in order to show my problem. Any ideas?
-----Original Message-----
From: Raman Gupta [mailto:[EMAIL PROTECTED] Sent: Monday, November 05, 2007 9:08 PM
To: [email protected]
Subject: Re: Encoder error

Burca Ciprian wrote:
I receive from a 3rd party application a message containing a hexa char "DC". When I try to decode, I get an error. The character should be Ü. Here is a simple application that shows my problem:

You need to be consistent with your encodings. You specified a UTF-8
decoder, but the DC encoding for Ü is not UTF-8, its ISO-8859-1 (and several
others: http://www.eki.ee/letter/chardata.cgi?ucode=00dc). The
UTF-8 encoding is C39C.

The foolproof way to create the String with that character that avoids
potential issues with javac using default platform encodings -- see
native2ascii):

String s2 = "\u00dc";
byte[] b2 = s2.getBytes("UTF-8");

Cheers,
Raman Gupta


Reply via email to