@Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        if (ch == null || ch.length == 0 || length <= 0) {
            return;
        }

        try {
            /*
             * we can't use the writeString method here because it's possible
             * we don't receive all characters at once and calling writeString
             * would cause unwanted spaces to be added in between these chunks
             * of character arrays.
             */
            String string = new String(ch, start, length);

            if (escapeText) {
                string = escapeElementEntities(string);
            }

            if (format.isTrimText()) {
                if ((lastOutputNodeType == Node.TEXT_NODE) && !charactersAdded) {
                    writer.write(" ");
                } else if (charactersAdded && Character.isWhitespace(lastChar)) {
                    writer.write(lastChar);
                }

                String delim = "";
                StringTokenizer tokens = new StringTokenizer(string);
                while (tokens.hasMoreTokens()) {
                    writer.write(delim);
                    writer.write(tokens.nextToken());
                    delim = " ";
                }
            } else {
                writer.write(string);
            }

            charactersAdded = true;
            lastChar = ch[start + length - 1];
            lastOutputNodeType = Node.TEXT_NODE;

            super.characters(ch, start, length);
        }
        catch (IOException e) {
            handleException(e);
        }
    }
<p>Writes the closing tag of an {@link Element}</p>

@param element <code>Element</code> to output.
@throws IOException if the element could not be written
xmppserver/src/main/java/org/jivesoftware/util/XMLWriter.java