moop™ said:
Hi,
Why there is no output stream that maps output to a String object? I
wonder how diffcult or why it is no one out there for use.
I started quite a long thread by asking the dual of this question:
http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/de63a5dc2a5eea8d
The bottom line seems to be:
1. Direct conversion between stream and String is deprecated.
2. Conversion between String and Reader is supported, but conversion
between Reader and Stream always assumes the Reader is built on top of
the Stream, not the other way round, so it doesn't help.
3. Support for byte arrays is much more flexible.
4. Some people think one should not try to relates streams and strings,
even if it is the most direct solution to a real problem.
I ended up converting my String to a byte array, and then building an
input stream from the array.
I think the corresponding solution to your problem would be to use a
ByteArrayOutputStream, and use one of its toString methods to extract
the String data. Clunky, but about the best that is supported.
Patricia