views:

44

answers:

2

not java specific, but when I say OutputStream os = sock.getOutputStream(); is there a way to determine stream's encoding charset? or do I have to know encoding charset ahead of time to properly read it? This is for arbitrary socket connection.

A: 

Streams do not have associated charsets. They just pass around arbitrary data. You have to know the data's charset ahead of time in order to interpret the data.

Remy Lebeau - TeamB
A: 

There is ways to detect text encoding, for example web browsers do that.
This is an implementation in Python(Universal Encoding Detector) that might give you some help.
Edit:
Here is one for java: http://jchardet.sourceforge.net/
Edit2:
Here is another SO question: http://stackoverflow.com/questions/90838

Jens Granlund