tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier>
Subject [OT] Basic int/char conversion question
Date Thu, 01 Jan 2009 16:13:51 GMT

This has nothing specific to Tomcat, it's just a problem I'm having as a 
non-java expert in modifying an exiting webapp.
I hope someone on this list can answer quickly, or send me to the 
appropriate place to find out.  I have tried to find, but get somewhat 
lost in the Java docs.

Problem :
an existing webapp reads from a socket connected to an external program.
The input stream is created as follows :
fromApp = socket.getInputStream();
The read is as follows :
StringBuffer buf = new StringBuffer(2000);
int ic;
while((ic = != 26 && ic != -1) // hex 1A (SUB)

This is wrong, because it assumes that the input stream is always in an 
8-bit default platform encoding, which it isn't.

How do I do this correctly, assuming that I do know that the incoming 
stream is an 8-bit stream (like iso-8859-x), and I do know which 8-bit 
encoding is being used (such as iso-8859-1 or iso-8859-2) ?
I cannot change the InputStream into something else, because there are a 
zillion other places where this webapp tests on the read byte's value, 

I mean, to append correctly to "buf" what was read in the "int", knowing 
that the proper encoding (charset) of "fromApp" is "X", how do I write 
this ?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message