I need to repeatedly read from an InputStream. The stream is from reading some XML from a web service request. I’d like to keep the XML in memory so I may parse the stream multiple times, and ultimately trash the XML at some later time.
What can I wrap the InputStream in so I may access it multiple times?
I need to repeatedly read from an InputStream. The stream is from reading some
Share
Assuming you’re reading in a well-structured XML document, why not parse the document a single time using a DOM parser (for example,
javax.xml.parsers.DocumentBuilder)?This will provide you with an in-memory representation of the XML document in a structured format. If you use a parser like
DocumentBuilder, you can subsequently fetch various parts of the structured data using the methodsNodelikegetElementsByTagName, etc.