问题
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.
回答1:
How about something like:
class WontCloseBufferedInputStream extends BufferedInputStream {
public void close () {
// Do nothing.
}
public void reallyClose() {
super.close ();
}
}
回答2:
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);
来源:https://stackoverflow.com/questions/8341680/java-saxparser-keep-inputstream-open