in hadoop-api-shim/src/main/java/org/apache/hadoop/fs/shim/impl/FSDataInputStreamShimImpl.java [325:346]
private synchronized int fallbackByteBufferRead(long position, ByteBuffer buf)
throws IOException {
int len = buf.remaining();
// position to return to.
if (buf.hasArray()) {
ByteBuffer tmp = buf.duplicate();
tmp.limit(tmp.position() + len);
tmp = tmp.slice();
int read = read(position, tmp.array(), tmp.position(), len);
buf.position(buf.position() + read);
return read;
} else {
// only read up to the temp buffer; caller gets to
// ask for more if it they want it
int bufferSize = Math.min(len, TEMPORARY_BUFFER);
byte[] byteArray = new byte[bufferSize];
int read = read(position, byteArray, 0, bufferSize);
buf.put(byteArray, 0, bufferSize);
return read;
}
}