private static @NotNull Document loadDocumentUsingStaX(@NotNull InputStream stream) throws JDOMException, IOException {
    try {
      XMLStreamReader2 xmlStreamReader = StaxFactory.createXmlStreamReader(stream, null);
      try {
        return SafeStAXStreamBuilderKt.buildJdomDocument(xmlStreamReader);
      }
      finally {
        xmlStreamReader.close();
      }
    }
    catch (XMLStreamException | UncheckedStreamException | IllegalNameException e) {
      throw new JDOMException(e.getMessage(), e);
    }
    finally {
      stream.close();
    }
  }
private static @NotNull Document loadDocumentUsingStaX(@NotNull InputStream stream)