wood burning stoves 2.0*
The moose likes Java in General and the fly likes obtaining InputStream/Reader from OutputStream/Writer to read the content Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "obtaining InputStream/Reader from OutputStream/Writer to read the content" Watch "obtaining InputStream/Reader from OutputStream/Writer to read the content" New topic
Author

obtaining InputStream/Reader from OutputStream/Writer to read the content

Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
Hi
I want to get the input stream/reader from an outputstream/writer.
I am using XSLT transformer to generate HTML from XML using a XSLT.
hereis the code:

How do I get th oputput of the transform method in a String? I am passing a StreamResult object which wraps a OutputStream. The StreamResult object also can wrap a Writer. Now how do I obtain the content of the OutputStream or Writer? I think i will need to use a InputStream or a Reader from which i can obtain the data as String by using read(..) method. Am i right? If that is so, how do I obtain the InputStream or a Reader from the OutputStream or Writer?
many thanks in advance
Tanveer
[ June 30, 2005: Message edited by: Tanveer Rameez ]

Author of JPhotoBrush Pro (www.jphotobrushpro.com)
Detlev Beutner
Ranch Hand

Joined: Jul 13, 2001
Posts: 76
Hi Tanveer,

you can use a ByteArrayOutputStream as the wrapped OutputStream, and afterwards, call toString on the baos.

Hope it helps
Detlev
[ June 29, 2005: Message edited by: Detlev Beutner ]
Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
hi
Thanks for the reply. Yes, that is a good away. I found another way of doing it too:


The StringWriter is a Writer and getbuffer gives the data written to that writer.

cheers
Tanveer
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: obtaining InputStream/Reader from OutputStream/Writer to read the content
 
Similar Threads
XSLT 2.o : to Use <matches> tag
java xslt & output xml files
XML to html Conversion
Java XML parser to parse the XML file
XML to HTML Conversion using JAX-P, XSLT Processor