+ @SuppressWarnings("unchecked")
+ @Override
+ public <C extends Closeable> C open(Class<C> clss) throws IOException, IllegalArgumentException {
+ if (InputStream.class.isAssignableFrom(clss)) {
+ PipedOutputStream out = new PipedOutputStream();
+ ForkJoinPool.commonPool().execute(() -> {
+ try {
+ Source source = new DOMSource(element);
+ Result result = new StreamResult(out);
+ provider.getTransformerFactory().newTransformer().transform(source, result);
+ out.flush();
+ out.close();
+ } catch (TransformerException | IOException e) {
+ throw new RuntimeException("Cannot read " + getPath(), e);
+ }
+ });
+ return (C) new PipedInputStream(out);
+ }
+ return super.open(clss);
+ }
+
+ @Override
+ public int getSiblingIndex() {
+ Node curr = element.getPreviousSibling();
+ int count = 1;
+ while (curr != null) {
+ if (curr instanceof Element) {
+ if (Objects.equals(curr.getNamespaceURI(), element.getNamespaceURI())
+ && Objects.equals(curr.getLocalName(), element.getLocalName())) {
+ count++;
+ }
+ }
+ curr = curr.getPreviousSibling();
+ }
+ return count;
+ }
+