static <V>  List<V> toList(ClosableIterator<V> iterator) {
    Preconditions.checkNotNull(iterator);

    List<V> values = new ArrayList<>();
    try {
      while (iterator.hasNext()) {
        values.add(iterator.next());
      }
    } finally {
        iterator.close();
    }
    return Collections.unmodifiableList(values);
  }
Returns an unmodifiable list of all elements in the provided iterator.
The iterator is guaranteed to be closed after its execution.

@param iterator the provided iterator.
@param <V> the type of elements in the iterator
@return a list of all elements returned by the iterator
samza-core/src/main/java/org/apache/samza/operators/impl/WindowOperatorImpl.java