code: public void detach() throws IOException {
          if (closed) {
              throw new IllegalStateException("Reader is closed.");
          }
  
          for (Element element = reader.readElement();
                  element != null; element = reader.readElement()) {
              buffer.add(element);
          }
  
          reader.close();
          sourceClosed = true;
      }
docs: Detaches this stream from the underlying stream by buffering every
  element.
  <P>This method ensures that all elements from the underlying stream
  have been read and stored in the internal buffer. The underlying
  stream is then closed, but this stream is kept open.</p>
  <p>This stream should still be closed using {@link #close()} once
  no longer needed.</p>
  @throws IOException if reading fails.
  @throws IllegalStateException if the stream is closed.