Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Set Encoding for StringReader ?

5,342 views
Skip to first unread message

Rene

unread,
Mar 13, 2000, 3:00:00 AM3/13/00
to
I realized that StringBufferInputStream is deprecated now. However,
StringReader has no way of setting the encoding, and I was unable to find
out, how to make a InputStreamReader from another Reader. So, what is the
proposed way to set the encoding for a string reader?

Funny enough, StringBufferInputStream was deprecated, because it does not
handle character conversion well, which is exactly the state I have now
without being able to set the encoding myself.

Rene

PS: This being a monster group, I'd appreciate a mail copy of any replies,
unless your policies prohibit it.


Jon Skeet

unread,
Mar 13, 2000, 3:00:00 AM3/13/00
to
[Posted and emailed]

mga...@gmx.de wrote:
> I realized that StringBufferInputStream is deprecated now. However,
> StringReader has no way of setting the encoding, and I was unable to find
> out, how to make a InputStreamReader from another Reader. So, what is the
> proposed way to set the encoding for a string reader?

There's no need. Readers are for *character* data, so you read a
character at a time. There's no conversion needed as it's constructed
with a Java String (unicode) and will read characters (unicode).



> Funny enough, StringBufferInputStream was deprecated, because it does not
> handle character conversion well, which is exactly the state I have now
> without being able to set the encoding myself.

That's because Streams are for bytes rather than characters.

When do you need to get the actual bytes? You can use String.getBytes()
to do the conversion in almost all cases I've seen.

> PS: This being a monster group, I'd appreciate a mail copy of any replies,
> unless your policies prohibit it.

Well, it's not *that* hard to set up most readers to just read the
headers, then you could easily find your own subject, but...

--
Jon Skeet - sk...@pobox.com
http://www.pobox.com/~skeet/

Rene

unread,
Mar 14, 2000, 3:00:00 AM3/14/00
to

Jon Skeet <sk...@pobox.com> schrieb in im Newsbeitrag:
MPG.13370714eee69a7a989f97@news...

> [Posted and emailed]
>
> mga...@gmx.de wrote:
> > I realized that StringBufferInputStream is deprecated now. However,
> > StringReader has no way of setting the encoding, and I was unable to
find
> > out, how to make a InputStreamReader from another Reader. So, what is
the
> > proposed way to set the encoding for a string reader?

I admit it's a foolish question (shame on me). What I needed was a way to
decode the clipboard content (where the string comes from). Sorry.

Rene


Dale King

unread,
Mar 15, 2000, 3:00:00 AM3/15/00
to Rene
What you actually probably want is to wrap a ByteArrayInputStream with
an InputStreamReader on which you set the encoding.

--
--- Dale King

0 new messages