@Override
    public void flush() throws IOException {
        // Register that we have started sending data
        connection.writeStarted();
        try {
            super.flush();
        }
        finally {
            // Register that we have finished sending data
            connection.writeFinished();
        }
    }
Flushes the underlying writer making sure that if the connection is dead then the thread
that is flushing does not end up in an endless wait.

@throws IOException if an I/O error occurs while flushing the writer.
xmppserver/src/main/java/org/jivesoftware/openfire/net/XMLSocketWriter.java