code: @Override
      public final void endDocument() throws IllegalStateException, IOException {
  
          // Check state
          if (_state != XMLEventListenerStates.START_TAG_OPEN && _state != XMLEventListenerStates.WITHIN_ELEMENT && _state != XMLEventListenerStates.AFTER_ROOT_ELEMENT) {
              throw new IllegalStateException("getState() == " + _state);
          }
  
          // Close all open elements
          close();
  
          // Flush the output stream
          _out.flush();
  
          // Finally change the state
          _state = XMLEventListenerStates.DOCUMENT_ENDED;
  
          // State has changed, check
          checkInvariants();
      }
docs: Finishes the XML output. All open elements will be closed and the
  underlying output stream will be flushed using {@link #getWriter()}.
  {@link java.io.Writer#flush() flush()}.
  <p />
  After calling this method, the state is changed to {@link #DOCUMENT_ENDED}, so that no more
  output can be written until this outputter is reset.
  
  @throws IllegalStateException if <code>getState() != {@link #START_TAG_OPEN} &amp;&amp; getState() !=
  {@link #WITHIN_ELEMENT} &amp;&amp; getState() != {@link #AFTER_ROOT_ELEMENT}</code>.
  @throws IOException           if an I/O error occurs; this will set the state to {@link #ERROR_STATE}.