InputStreamReader and charsets

M

Mike Lischke

Hi all,

Currently I'm trying to read a text file into strings line-by-line thereby converting it to Unicode using the InputStreamReader class. However it can happen that the file I'm reading contains instructions how to read the following text part with regard to an encoding. So what I need would be a way to switch the current charset of the stream reader, which is not possible.

Does anybody have an idea how to read such files correctly?

Mike
 
R

Roedy Green

Currently I'm trying to read a text file into strings line-by-line thereby =
converting it to Unicode using the InputStreamReader class. However it can =
happen that the file I'm reading contains instructions how to read the =
following text part with regard to an encoding. So what I need would be a =
way to switch the current charset of the stream reader, which is not =
possible.

Does anybody have an idea how to read such files correctly?

you need to invent a new encoding, and write a decoder that has state.
It might then call on other decoders to do the bulk of the work.

How do you write a new encoder/decoder? See
http://mindprod.com/jgloss/encoding.html


how do you get it added into the official set? please tell me if you
find out.
 
J

jackie

how about create multiple String varibles for storing different segments of
the text.
Of course you need to convert each String variable to the appropriate
encoding scheme.

Hi all,

Currently I'm trying to read a text file into strings line-by-line thereby
converting it to Unicode using the InputStreamReader class. However it can
happen that the file I'm reading contains instructions how to read the
following text part with regard to an encoding. So what I need would be a
way to switch the current charset of the stream reader, which is not
possible.

Does anybody have an idea how to read such files correctly?

Mike
 
M

Mike Lischke

Roedy Green wrote
you need to invent a new encoding, and write a decoder that has state.
It might then call on other decoders to do the bulk of the work.

This is indeed an interesting idea. Thank you Roedy. I'll try that.

Mike
 
M

Mike Lischke

jackie wrote
how about create multiple String varibles for storing different segments of
the text.

The problem is I don't know in advance how long a segment is. I'm parsing the file content and at any time there can be a marker telling me to use a particular code page.

Mike
 
D

Dale King

Roedy Green wrote
This is indeed an interesting idea. Thank you Roedy. I'll try that.


Note that all this is only possible in a 1.4 or later VM. Before 1.4 there
was no support for custom encodings.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top