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