INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

character decoding

character decoding

(OP)
I'm receiving data through a socket....

socket = new Socket(server, port);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));


This is coming from a remote server that I don't control.
Special characters are encoded, and if I print them out to the console they appear as diamond question marks.  

If I telnet to the server and view the data it appears strange:
If I tell the server to send me 棥¿ÄÅüÇ, it displays in a telnet session as 棥¿Ã
                             Ã
üÃ


What can I do to make these special characters show up correctly?


 

RE: character decoding

Quote:

What can I do to make these special characters show up correctly?
Use the same characterset to display them, as the server used to encode them with? Ask the developer/admin of the server app what characterset is to be expected.

RE: character decoding

(OP)
I found out that certain data is sent UTF8 encoded, and other data is not.  

I know how to do this:

Charset charset = Charset.forName("UTF-8");
CharsetDecoder decoder = charset.newDecoder();
socket = new Socket(server, port);
in = new BufferedReader(new InputStreamReader(socket.getInputStream(), decoder));

This works fine for the UTF-8 encoded bytes.

But the problem is, when the non-utf8 bytes comes through, and it contains weird chars, I get this:

java.nio.charset.MalformedInputException: Input length = 1
Exited whiel loop
    at java.nio.charset.CoderResult.throwException(Unknown Source)
    at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
    at sun.nio.cs.StreamDecoder.read(Unknown Source)
    at java.io.InputStreamReader.read(Unknown Source)
    at java.io.BufferedReader.fill(Unknown Source)
    at java.io.BufferedReader.readLine(Unknown Source)
    at java.io.BufferedReader.readLine(Unknown Source)
    at chatfoo.ClientCode.receive(ClientCode.java:148)
    at chatfoo.ClientCode.connect(ClientCode.java:117)
    at chatfoo.ThreadHelper.run(ThreadHelper.java:19)
    at java.lang.Thread.run(Unknown Source)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close