/** {@inheritDoc} */
@Override public void copyBytes(IndexOutput out, long numBytes) throws IOException {
assert numBytes >= 0 : "numBytes=" + numBytes;
GridLuceneOutputStream gridOut = out instanceof GridLuceneOutputStream ? (GridLuceneOutputStream)out : null;
long left = numBytes;
while (left > 0) {
if (bufPosition == bufLength) {
++currBufIdx;
switchCurrentBuffer(true);
}
final int bytesInBuf = bufLength - bufPosition;
final int toCp = (int)(bytesInBuf < left ? bytesInBuf : left);
if (gridOut != null)
gridOut.writeBytes(currBuf + bufPosition, toCp);
else {
byte[] buff = new byte[toCp];
mem.readBytes(currBuf + bufPosition, buff);