@Override
  public long writeTo(int index, WritableByteChannel channel, long relativeOffset, long maxSize) throws IOException {
    validateIndex(index);
    long written = 0;
    BlobReadInfo blobReadInfo = blobReadInfoList.get(index);
    String blobIdStr = blobReadInfo.getBlobId().getID();

    try {
      // TODO: Need to refactor the code to avoid prefetching blobs for BlobInfo request,
      // or at least to prefetch only the header (requires CloudDestination enhancement)
      if (!blobReadInfo.isBlobDownloaded()) {
        blobReadInfo.downloadBlob(blobStore);
      }
      ByteBuf outputBuf = blobReadInfo.getBlobContent().duplicate();
      long sizeToRead = Math.min(maxSize, blobReadInfo.getBlobSize() - relativeOffset);
      outputBuf.setIndex((int) (relativeOffset), (int) (relativeOffset + sizeToRead));
      written = channel.write(outputBuf.nioBuffer());
    } catch (StoreException ex) {
      throw new IOException("Write of cloud blob " + blobIdStr + " failed", ex);
    }
    logger.trace("Downloaded {} bytes to the write channel from the cloud blob : {}", written, blobIdStr);
    return written;
  }
An implementation of {@code MessageReadSet} for cloud based storage
ambry-cloud/src/main/java/com/github/ambry/cloud/CloudMessageReadSet.java