}
static void fill(final BufferArray bufferArray,
final int totalBufferSize, final DirectByteBufferRecord ioRecord) {
final Buffer buffers[] = bufferArray.getArray();
final int size = bufferArray.size();
int remaining = totalBufferSize;
for (int i = 0; i < size; i++) {
final Buffer buffer = buffers[i];
assert !buffer.isComposite();
final int bufferSize = buffer.remaining();
if (bufferSize == 0) {
continue;
} else if (buffer.isDirect()) {
ioRecord.finishBufferSlice();
ioRecord.putToArray(buffer.toByteBuffer());
} else {
ByteBuffer currentDirectBufferSlice = ioRecord.getDirectBufferSlice();
if (currentDirectBufferSlice == null) {
final ByteBuffer directByteBuffer = ioRecord.getDirectBuffer();
currentDirectBufferSlice =
directByteBuffer == null
? ioRecord.allocate(remaining)
: ioRecord.sliceBuffer();
ioRecord.putToArray(currentDirectBufferSlice);
}
final int oldLim = currentDirectBufferSlice.limit();
currentDirectBufferSlice.limit(currentDirectBufferSlice.position() + bufferSize);
buffer.get(currentDirectBufferSlice);
currentDirectBufferSlice.limit(oldLim);
}
remaining -= bufferSize;
}