Java SAXParser - keep InputStream open

I have BufferedInputStreamone from which I want to parse the XML with SAXParser, but then reuse it again (e.g.. mark(int)And reset()). However, this thread is closed in the method parse(). Is there any way to say SAXParserto leave it open? The last resort is to wrap this stream in a non-contact stream.

Thank.

+3
source share
2 answers

How about something like:

class WontCloseBufferedInputStream extends BufferedInputStream {
  public void close () {
    // Do nothing.
  }

  public void reallyClose() {
    super.close ();
  }
}
+5
source

You can pass an InputSource object, not an InputStream object in SAXParser

code example

SAXParser parser = // saxpaser object
        InputSource isource = new InputSource();
        InputStream istream = //your inputstream
        isource.setByteStream(istream);
        parser.parse(isource, handler);
-2
source

Source: https://habr.com/ru/post/1695895/


All Articles