protected void writeDeclaration() throws IOException {
        String encoding = format.getEncoding();

        // Only print of declaration is not suppressed
        if (! format.isSuppressDeclaration()) {
            // Assume 1.0 version
            if (encoding.equals("UTF8")) {
                writer.write("<?xml version=\"1.0\"");
                if (!format.isOmitEncoding()) {
                    writer.write(" encoding=\"UTF-8\"");
                }
                writer.write("?>");
            } else {
                writer.write("<?xml version=\"1.0\"");
                if (! format.isOmitEncoding()) {
                    writer.write(" encoding=\"" + encoding + "\"");
                }
                writer.write("?>");
            }
            if (format.isNewLineAfterDeclaration()) {
                println();
            }
        }
    }
<p>
This will write the declaration to the given Writer.
  Assumes XML version 1.0 since we don't directly know.
</p>
@throws IOException if the declaration could not be written
xmppserver/src/main/java/org/jivesoftware/util/XMLWriter.java