private OutputStream createOutputStream() {
        return new OutputStream() {
            @Override
            public synchronized void write(int b) throws IOException {
                outAppData.put((byte) b);
                outAppData.flip();
                doWrite(outAppData);
                outAppData.clear();
            }

            @Override
            public synchronized void write(byte[] bytes, int off, int len) throws IOException {
                outAppData = resizeApplicationBuffer(bytes.length);
                outAppData.put(bytes, off, len);
                outAppData.flip();
                doWrite(outAppData);
                outAppData.clear();
            }
        };
    }
<code>TLSWrapper</code> is a TLS wrapper for connections requiring TLS protocol.
xmppserver/src/main/java/org/jivesoftware/openfire/net/TLSStreamWriter.java