private void tryWrite() {
        if (this.writeQueue.size() == 0)
            return;

        Iterator<Writer> it = this.writeQueue.iterator();
        while (it.hasNext()) {
            Writer writer = it.next();
            if (writer.channel.isConnectionPending()) {
                try {
                    if (!writer.channel.finishConnect())
                        continue;
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
            }
            try {
                if (!writer.headerWritten) {
                    generateHeader(writer.buffer.remaining());
                    writer.channel.write(headBuffer);
                    if (headBuffer.remaining() == 0)
                        writer.headerWritten = true;
                    else
                        assert (headBuffer.position() == 0); // assume haven't written anything
                }
                writer.channel.write(writer.buffer);

                if (writer.buffer.remaining() == 0)
                    this.writeQueue.remove(writer);
            } catch (IOException e) {
                e.printStackTrace();
                continue;
            }
        }
    }