code: @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);
          }
      }
docs: Builds a new XML Document from the given input stream. The stream is not closed by this method,
  and so you must close it.
  
  @param stream   the input stream, must not be {@literal null}
  @param encoding the encoding, if {@literal null}, UTF-8 is used.
  @return the built document
  @throws java.io.IOException if the given stream is not a valid XML document,
  or if the given encoding is not supported.