public static List<CloudBlobMetadata> capMetadataListBySize(List<CloudBlobMetadata> originalList, long size) {
    long totalSize = 0;
    List<CloudBlobMetadata> cappedList = new ArrayList<>();
    for (CloudBlobMetadata metadata : originalList) {
      // Cap results at max size
      if (totalSize + metadata.getSize() > size) {
        if (cappedList.isEmpty()) {
          // We must add at least one regardless of size
          cappedList.add(metadata);
        }
        break;
      }
      cappedList.add(metadata);
      totalSize += metadata.getSize();
    }
    return cappedList;
  }
Utility to cap specified {@link CloudBlobMetadata} list by specified size of its blobs.
Always returns at least one metadata object irrespective of size.
@param originalList List of {@link CloudBlobMetadata}.
@param size total size of metadata's blobs.
@return {@link List} of {@link CloudBlobMetadata} capped by size.
ambry-cloud/src/main/java/com/github/ambry/cloud/CloudBlobMetadata.java