@ Override public Document fromInputStream ( InputStream stream , Charset encoding ) throws IOException { try { DocumentBuilder builder = factory . newDocumentBuilder ( ) ; InputSource is = new InputSource ( stream ) ; if ( encoding == null ) { is . setEncoding ( Charsets . UTF_8 . name ( ) ) ; } else { is . setEncoding ( encoding . name ( ) ) ; } return builder . parse ( is ) ; //NOSONAR The used factory is not exposed to XXE. } catch ( ParserConfigurationException | SAXException e ) { throw new IOException ( "Cannot parse the given XML document" , e ) ; } }
Builds a new XML Document from the given input stream . The stream is not closed by this method and so you must close it .