> From: Konstantin Kolinko [mailto:[email protected]]
> Subject: Re: [OT] Basic int/char conversion question
>
> reset() is not implemented in InputStreamReader
Quite correct; sorry - the revised code would be this:
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.nio.charset.Charset;
public class Converter {
byte[] ba = new byte[1];
ByteArrayInputStream bais = new ByteArrayInputStream(ba);
InputStreamReader isr;
public Converter(String csName) {
isr = new InputStreamReader(bais, Charset.forName(csName));
}
public char convert(byte b) {
bais.reset();
ba[0] = b;
try {
return (char)isr.read();
} catch (IOException ioe) {
// This can't happen in our situation, but...
return '\0';
}
}
}
> Well, it serves the same purpose as TranslationTable class that
> I have provided earlier.
True, and yours should be more efficient, and could be easily modified to
create an instance for any given character set rather than using a static
table. I think the Converter class above is more easily adaptable to
multi-byte character sets should that ever be of interest.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you received
this in error, please contact the sender and delete the e-mail and its
attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]