code: private ReadResultEntry collectCachedEntries(long initialOffset, ReadResult readResult,
                                                   ArrayList<ReadResultEntryContents> cachedEntries) {
          long expectedOffset = initialOffset;
          while (readResult.hasNext()) {
              ReadResultEntry entry = readResult.next();
              if (entry.getType() == Cache) {
                  Preconditions.checkState(entry.getStreamSegmentOffset() == expectedOffset,
                          "Data returned from read was not contiguous.");
                  ReadResultEntryContents content = entry.getContent().getNow(null);
                  expectedOffset += content.getLength();
                  cachedEntries.add(content);
              } else {
                  return entry;
              }
          }
          return null;
      }
docs: Reads all of the cachedEntries from the ReadResult and puts their content into the cachedEntries list.
  Upon encountering a non-cached entry, it stops iterating and returns it.