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
  • 730,956
  • 141
  • 904
  • 1,278
woky
  • 4,686
  • 9
  • 36
  • 44

2 Answers2

8

How about something like:

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

  public void reallyClose() {
    super.close ();
  }
}
OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213
-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
  • 53,011
  • 55
  • 178
  • 243