M.J. Dance wrote:
Patricia Shanahan wrote:
What is the proper, undeprecated, replacement code for:
InputStream in = new StringBufferInputStream(someString);
There is no proper replacement. The line of code above is mixing two
superficially similar but inherently different things: bytes and
chars. Of course the two are related but, in order to fully describe
that relatinship, one needs additional information: character
encoding. Having that, one can getBytes() from a String and, using
those, create a ByteArrayInputStream.
The essential issue here is that Java (rightly so in my opinion)
associates direction with crossing the boundary between characters and
bytes. Going from character to bytes is only supported in the output
or writing direction. The implication being that conversion between
the two is associated with an external entity (a file, a server). The
assumption with Java is that once you have it as a character the
program itself should only deal with it as characters. It should only
be converted to bytes in order to send it outside of Java.
That is a fairly resonable way to do things in my opinion. In almost
all cases it is correct. There are some cases where you do want to go
the other way, but they are rare. And if they did support it, it would
probably be encouraging abuse by those that try to handle text data as
bytes which is just wrong.
Well. There are cases where you can't do without bytes. Cryptography,
digests, signing etc. all operate on bytes. And people do want to
encrypt, digest and/or sign text (t.i. a string of characters) from time