-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

André,

André Warnier wrote:
> 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 = fromApp.read()) != 26 && ic != -1) // hex 1A (SUB)
>            buf.append((char)ic);
> 
> This is wrong, because it assumes that the input stream is always in an
> 8-bit default platform encoding, which it isn't.

Does it?

The only assumption I see here is that the byte code 0x1a has a special
meaning. Since ASCII is usually the lowest common denominator for
character encodings, is this a bad assumption?

> 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,
> numerically.

I like Chuck's suggestion to use an InputStreamReader because the
interfaces are (at least accidentally) the same, at least for the method
in question. I'm not sure how you would modify an entire application to
"fix" this code everywhere, though.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAklr6QEACgkQ9CaO5/Lv0PBYDQCgk0iWAsuvSlujYJRCiWerrHXg
lFIAnio6Qts6FMg1lWZZvNSkqvNLY70p
=z+yg
-----END PGP SIGNATURE-----

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

Reply via email to