@Override public void completed(Integer result, ClientSession attachment) { super.completed(result, attachment); // check if we have some leftover to write if (writeBuf.hasRemaining()) { channel.write(writeBuf, attachment, this); } else { // The queue is empty, this encoder is done writing.set(false); writeBuf.clear(); } }