/** * Returns the appropriate {@link DataBuffer} representing the data to send, depending on the * configurable transfer type. * * @param req The initiating {@link RPCBlockReadRequest} * @param reader The {@link BlockReader} for the block to read * @param readLength The length, in bytes, of the data to read from the block * @return a {@link DataBuffer} representing the data * @throws IOException * @throws IllegalArgumentException */ private DataBuffer getDataBuffer(RPCBlockReadRequest req, BlockReader reader, long readLength) throws IOException, IllegalArgumentException { switch (mTransferType) { case MAPPED: ByteBuffer data = reader.read(req.getOffset(), (int) readLength); return new DataByteBuffer(data, readLength); case TRANSFER: // intend to fall through as TRANSFER is the default type. default: if (reader.getChannel() instanceof FileChannel) { return new DataFileChannel( (FileChannel) reader.getChannel(), req.getOffset(), readLength); } reader.close(); throw new IllegalArgumentException("Only FileChannel is supported!"); } }