• Post Reply Bookmark Topic Watch Topic
  • New Topic

charachter encoding

 
alexandros mouzakidis
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does any one know how can detect the character encoding from the string data that i am recieving from a stream and how can i transcode them to a specific encoding;
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, InputStream and OutputStream do not enforce any particular character encoding since they can be used to transfer arbitrary binary data. I think this means it is difficult to tell what character coding is used by an InputStream or OutputStream since they might not be used for text at all! On the other hand Readers and Writers are used specifically for text, so it makes more sense to talk about character encoding for Readers and Writers rather than for InputStreams and OutputStreams. Still, I don't see any way to tell what character encoding a particular Reader uses.

As for converting from one encoding to another, I see in the API docs that InputStreamReader and OutputStreamWriter both have constructors to specify a character set to use. This means that you can easily create an OutputStreamWriter for the particular encoding that you want to translate TO. However, without knowing which encoding is being used by the InputStream, I can't think of a way to create an InputStreamReader with the correct encoding. Can you provide some more details about what you are trying to do? Perhaps someone will have some other suggestions to accomplish your task without determining the character encoding.

Layne
 
alexandros mouzakidis
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i was talking about input stream i ment readers my mistake...
i just want to teke the encoding from web site that my application downloads and filter them
 
alexandros mouzakidis
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then encoding of a string can work too
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!