* @see org.rssowl.core.interpreter.ISAXParser#parse(java.io.InputStream)
*/
public Document parse(InputStream inS) throws ParserException {
Document document = null;
Exception ex = null;
SAXBuilder builder = getBuilder();
/* Set a Mark to support a 2d Run */
KeepAliveInputStream keepAliveIns = new KeepAliveInputStream(inS);
keepAliveIns.mark(0);
/* First Run - Try with Documents own Encoding */
try {
document = builder.build(keepAliveIns);
} catch (JDOMException e) {
ex = e;
} catch (IOException e) {
ex = e;
}
/* Second Run - Try with Platform Default Encoding */
if (ex instanceof JDOMParseException) {
/* Try to reset the Stream to 0 */
boolean reset = false;
try {
keepAliveIns.reset();
reset = true;
} catch (IOException e) {
/* Reset Failed, do not override previous exception */
}
/* In case reset-operation was successfull */
if (reset) {
try {
document = builder.build(new InputStreamReader(keepAliveIns));
} catch (JDOMException e) {
ex = e;
} catch (IOException e) {
ex = e;
}