I use the follwing wrapper for the InputStream to prevent the parser from closing the original stream:
private static class InputStreamWrapper extends InputStream {
private InputStream input;
public InputStreamWrapper(InputStream input) {
this.input = input;
}
@Override
public int read() throws IOException {
return input.read();
}
// Must be overriden for better performance
@Override
public int read(byte[] b, int off, int len) throws IOException {
return input.read(b, off, len);
}
@Override
public void close() {
}
}
The wrapper is used like saxParser.parse(new InputStreamWrapper(input), handler).
Putting the InputStream in an InputSource does not help. This is done internally by the SAX parser.