converting an outputstream to an inputstream

Hi all,How can I convert an outputStream to an InputStream?Thanks in advance,Asaf
[109 byte] By [asaf.lahava] at [2007-10-3 2:50:27]
# 1
> How can I convert an outputStream to an InputStream?Not at all. How do you convert a sink to a spring? What are you trying to do?
CeciNEstPasUnProgrammeura at 2007-7-14 20:39:17 > top of Java-index,Java Essentials,Java Programming...
# 2

i have this function which is running an XSL transformation. As you can see, this function returns an outputStream.

/**

* use this function to perform an XSL transformation

* @param source

* input stream pointing to an XML document

* @param xslStream

* input stream pointing to an XSL document

* @return

* output stream pointing to the transformation result

* @throws TransformerException

*/

public static OutputStream transform(InputStream source, InputStream xslStream) throws TransformerException {

//Create a transform factory instance.

TransformerFactory tfactory = TransformerFactory.newInstance();

//Create a transformer for the style sheet.

Transformer transformer =

tfactory.newTransformer(new StreamSource(xslStream));

//result stream

OutputStream output = new ByteArrayOutputStream();

//Transform the source XML to OutputStream.

transformer.transform(new StreamSource(source),

new StreamResult(output));

return output;

}

What i'm trying to do, is load the transformed output into an xml document. in order to achieve this, i need to provide an InputStream.

asaf.lahava at 2007-7-14 20:39:17 > top of Java-index,Java Essentials,Java Programming...
# 3
Why do you need an InputStream to write to a document?
CeciNEstPasUnProgrammeura at 2007-7-14 20:39:17 > top of Java-index,Java Essentials,Java Programming...
# 4

> How can I convert an outputStream to an InputStream?

If you think about this a bit more you can conclude that reads from an

input stream can block when there is no input available (yet). If you're

using one single thread for both your reads and writes you'll notice that

trouble is imminent.

Please rethink your problem and most likely you'll find a decent workaround.

Otherwise consider the PipedOutputStream and PipedInputStream.

kind regards,

Jos

JosAHa at 2007-7-14 20:39:17 > top of Java-index,Java Essentials,Java Programming...
# 5
Thanks....I appreciate the explanation
asaf.lahava at 2007-7-14 20:39:17 > top of Java-index,Java Essentials,Java Programming...
# 6

> What i'm trying to do, is load the transformed output

> into an xml document. in order to achieve this, i

> need to provide an InputStream.

Do you mean that you're trying to create a DOM (org.w3c.Document) from the transformation? In that case, you want to use a DOMResult instead of a StreamResult

kdgregorya at 2007-7-14 20:39:17 > top of Java-index,Java Essentials,Java Programming...