/** Parses a DOM from the given XML input stream. */ public static Document parseDOM(InputStream is) throws ParserConfigurationException, SAXException, IOException { final InputStream in = is.markSupported() ? is : new BufferedInputStream(is); checkUTF8(in); // Java XML factories are not declared to be thread safe DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder db = factory.newDocumentBuilder(); db.setErrorHandler(new ParserErrorHandler()); return db.parse(in); }
/** * Parses a DOM from the given XML input stream. * * @param is the {@link InputStream} containing XML * @return a {@link Document} representing the XML * @throws ParserConfigurationException if the XML parser cannot be created * @throws SAXException if there is an error parsing the XML * @throws IOException if there is an error reading from the stream */ public static Document parseDOM(InputStream is) throws ParserConfigurationException, SAXException, IOException { final InputStream in = is.markSupported() ? is : new BufferedInputStream(is); checkUTF8(in); // Java XML factories are not declared to be thread safe DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder db = factory.newDocumentBuilder(); db.setErrorHandler(new ParserErrorHandler()); return db.parse(in); }