Caldarale, Charles R wrote:
From: Konstantin Kolinko [mailto:knst.koli...@gmail.com]
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';
}
}
}
Once again, thank you all for all the information provided.
The real solution would be to rewrite that whole application (external
feeder program included), to make it take charset variations into
account. Better yet, it should all be rewritten to use Unicode and
UTF-8, and be done with it.
I don't have that option now, so I will use one of the techniques
provided, depending on what I find is easiest to implement here for the
specific limited problem at hand.
But I will preserve all your code snippets and tips, because this is all
extremely difficult to find in the Java documentation, at least from
this angle.
Once again, as I believe Chuck once wrote, when one knows how to phrase
the question, one probably has already 90% of the answer.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org