public static String asUnclosedStream(final Document document) {
        if (!document.getRootElement().getName().equals("stream")) {
            throw new IllegalArgumentException("Document's root element is expected to be named 'stream', but was named '" + document.getRootElement().getName() + "'");
        }

        final OutputFormat format = new OutputFormat();
        format.setEncoding(document.getXMLEncoding());
        format.setNewLineAfterDeclaration(!XMPP_STREAM_SUPPRESS_NEWLINE_AFTER_XML_DECLARATION.getValue());
        format.setSuppressDeclaration(XMPP_STREAM_SUPPRESS_XML_DECLARATION.getValue());

        try {
            final StringWriter out = new StringWriter();
            org.dom4j.io.XMLWriter writer = new XMLWriter(out, format);
            writer.write(document);
            writer.flush();

            // Strip closing root tag.
            final String result = out.toString();
            return result.substring(0, result.lastIndexOf("</stream:stream>"));
        } catch (IOException e) {
            throw new RuntimeException("IOException while generating textual representation: ", e);
        }
    }
Formats the XML document, that is required to have a root element named 'stream', as a string. This method will
strip the closing 'stream' tag from the string prior to returning it.

@param document The document for which to return a string representation
@return the string-representation of the document
@throws IllegalArgumentException when the document's root element is not named 'stream'
xmppserver/src/main/java/org/jivesoftware/util/StringUtils.java