Originally posted by Brian Cole:
Well, do you know how you want to convert the 16-bit chars returned by the reader into 8-bit bytes?
Deciding on that is the hard part, but you shouldn't have to use any sun internal classes. possibilities:
strip off the highest 8 bits: just cast from char to byteconvert each char to two bytes (you'll have to choose which endian)use a specific Charset: use CharsetEncoder or String.getBytes()
Code is out there if you look. For example, this one seems to use String.getBytes(charsetName).
Well that was why I posted this here, since this is not a simple issue; some characters can be represented using a single byte, while some others need two bytes. Therefore, options 1 and 2 are not good. As for CharsetEncoder, this is an abstract class without any known subclasses, and since I'm not that good at encoding I can't really write a subclass myself.
I also though about using Strings, but didn't want to use that yet because it would require a lot of new
String objects. I've checked the code of the ReaderInputStream on Koders.com and guess that's the way to go.
For the GZIP situation you mention, it would be best to just read the data with an InputStream to begin with.
Well if I could I certainly would have. The problem is, sometimes you can't use an InputStream because some other API only returns a Reader.
I guess I'll base my code on the Koders.com example. Thanks for the link.
[ November 14, 2007: Message edited by: Rob Prime ]