@Override
  public long writeTo(int index, WritableByteChannel channel, long relativeOffset, long maxSize) throws IOException {
    if (index >= readOptions.size()) {
      throw new IndexOutOfBoundsException("index " + index + " out of the messageset size " + readOptions.size());
    }
    BlobReadOptions options = readOptions.get(index);
    long sizeToRead = Math.min(maxSize, options.getMessageInfo().getSize() - relativeOffset);
    long written = 0;
    if (options.getPrefetchedDataRelativeOffset() == -1) {
      long startOffset = options.getOffset() + relativeOffset;
      logger.trace("Blob Message Read Set position {} count {}", startOffset, sizeToRead);
      written = options.getChannel().transferTo(startOffset, sizeToRead, channel);
    } else {
      ByteBuffer buf = options.getPrefetchedData().nioBuffer();
      long bufStartOffset = relativeOffset - options.getPrefetchedDataRelativeOffset();
      buf.limit((int) (bufStartOffset + sizeToRead));
      buf.position((int) (bufStartOffset));
      written = channel.write(buf);
    }
    logger.trace("Written {} bytes to the write channel from the file channel : {}", written, options.getFile());
    return written;
  }
An implementation of MessageReadSet that maintains a list of
offsets from the underlying file channel
ambry-store/src/main/java/com/github/ambry/store/StoreMessageReadSet.java