tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: [OT] Basic int/char conversion question
Date Thu, 01 Jan 2009 19:39:55 GMT
Caldarale, Charles R wrote:
>> From: Len Popp [mailto:len.popp@gmail.com]
>> Subject: Re: [OT] Basic int/char conversion question

I note with satisfaction that I'm not the only one laboring away on this 
day-after, but you're just all going a bit too fast for me and my 
growing but still limited Java knowledge.

I like the idea of wrapping this in an InputStreamReader, but how is 
this solving my problem ?
Suppose I do this :

String knownEncoding = "ISO-8859-1"; // or "ISO-8859-2"
InputStreamReader fromApp;
fromApp =  = new InputStreamReader(socket.getInputStream(), 
Charset.forName(knownEncoding));
int ic = 0;
StringBuffer buf = new StringBuffer(2000);
while((ic = fromApp.read()) != 26 && ic != -1) // hex 1A (SUB)
           buf.append((char)ic);

.. then I'm still appending the same char (really, byte) to my buffer, 
right ?

For example, suppose the byte in question is \xB5 on the fromApp stream.
Interpreted as iso-8859-1, this would be the character "micro", with 
Unicode codepoint U00B5, which I would thus append to the StringBuffer 
(which is, unless I am mistaken, composed of Unicode characters).
However, if the fromApp stream really was iso-8859-2, this same byte 
\xB5 should be interpreted as the Unicode codepoint U013E (LATIN SMALL 
LETTER L WITH CARON). ( ł )
But by doing
	buf.append((char) ic)
I am still interpreting ic as being, by platform default, ISO-8859-1, 
thus I am still appending the Unicode codepoint U00B5.
Not so ?

Or, can I / do I have to now also say :
char ic = 0;
while((ic = fromApp.read()) != 26 && ic != -1) // hex 1A (SUB)
           buf.append(ic);

??

In other words, in order to keep my changes and post-festivities 
headaches to a minimum, I would like to keep buf being a StringBuffer. 
So what I was really looking for was the correct alternative to
           buf.append((char) ic);
which would convert ic from an integer, to the appropriate Unicode 
character, taking into account the "knownEncoding" which I know.

Does that not exist ?

A cursory examination of the webapp code seems to show that the byte in 
question is only ever compared to either -1 or integers below 127, or 
characters in the lower ASCII range "A-Za-z".
But is
if (char == some-integer)
always valid as a replacement for
if (int == some-integer)
?



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message