buffer.limit(oldPos + bufferSize);
final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
final DirectByteBufferRecord ioRecord = DirectByteBufferRecord.get();
final BufferArray bufferArray = buffer.toBufferArray();
int written = 0;
fill(bufferArray, bufferSize, ioRecord);
ioRecord.finishBufferSlice();
final int arraySize = ioRecord.getArraySize();
try {
written = arraySize != 1
? flushByteBuffers(socketChannel, ioRecord.getArray(), 0, arraySize)
: flushByteBuffer(socketChannel, ioRecord.getArray()[0]);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (composite) write {1} bytes", new Object[]{
connection, written
});
}
} finally {
bufferArray.restore();
bufferArray.recycle();
ioRecord.release();
}
Buffers.setPositionLimit(buffer, oldPos + written, oldLim);
return written;