Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create an InputStream from a Document or Node

Tags:

java

xml

xstream

How can I create an InputStream object from a XML Document or Node object to be used in xstream? I need to replace the ??? with some meaningful code. Thanks.

Document doc = getDocument(); InputStream is = ???; MyObject obj = (MyObject) xstream.fromXML(is); 
like image 255
Mike Pone Avatar asked May 14 '09 18:05

Mike Pone


People also ask

What is document input stream?

To avoid downloading a document multiple times, we cache the document locally using an abstraction called a Document Input Stream (DIS). A DIS is an input stream that caches the entire contents of the document read from the internet. It also provides methods to re-read the document.

What is InputStream in Java example?

Java InputStream 's are used for reading byte based data, one byte at a time. Here is a Java InputStream example which reads all the bytes from a file: InputStream inputstream = new FileInputStream("c:\\data\\input-text. txt"); int data = inputstream.


1 Answers

ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Source xmlSource = new DOMSource(doc); Result outputTarget = new StreamResult(outputStream); TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget); InputStream is = new ByteArrayInputStream(outputStream.toByteArray()); 
like image 123
Gary Kephart Avatar answered Oct 08 '22 09:10

Gary Kephart