in client-tez/src/main/java/org/apache/tez/runtime/library/common/sort/buffer/WriteBuffer.java [224:266]
public void write(byte[] b, int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if ((off < 0)
|| (off > b.length)
|| (len < 0)
|| ((off + len) > b.length)
|| ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
if (buffers.isEmpty()) {
buffers.add(new WrappedBuffer((int) maxSegmentSize));
}
int bufferNum = (int) ((currentOffset + len) / maxSegmentSize);
for (int i = 0; i < bufferNum; i++) {
buffers.add(new WrappedBuffer((int) maxSegmentSize));
}
int index = currentIndex;
int offset = currentOffset;
int srcPos = 0;
while (len > 0) {
int copyLength = 0;
if (offset + len >= maxSegmentSize) {
copyLength = (int) (maxSegmentSize - offset);
currentOffset = 0;
} else {
copyLength = len;
currentOffset += len;
}
System.arraycopy(b, srcPos, buffers.get(index).getBuffer(), offset, copyLength);
offset = 0;
srcPos += copyLength;
index++;
len -= copyLength;
dataLength += copyLength;
}
currentIndex += bufferNum;
}