4

I've a BufferedInputStream from which I want to parse XML with SAXParser but then reuse it again (eg. mark(int) & reset()). However this stream is closed in parse() method. Is it possible to somehow tell SAXParser to leave it open? The last resort is to wrap this stream with un-closeable stream.

Thank you.

Jonathan Leffler
  • 698,132
  • 130
  • 858
  • 1,229
woky
  • 4,497
  • 9
  • 34
  • 43

2 Answers2

8

How about something like:

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

  public void reallyClose() {
    super.close ();
  }
}
OldCurmudgeon
  • 62,806
  • 15
  • 115
  • 208
-1

You can pass InputSource object rather than InputStream object to SAXParser

sample code

SAXParser parser = // saxpaser object
        InputSource isource = new InputSource();
        InputStream istream = //your inputstream
        isource.setByteStream(istream);
        parser.parse(isource, handler);
Sunil Kumar Sahoo
  • 51,611
  • 53
  • 174
  • 242