code: private static <T> List<T> fetchFromIter(BufferedIterator<T> iter, int fetch, int max_fetch) {
          final long t0 = System.currentTimeMillis();
          assert (max_fetch >= 1);
          if (fetch < 0 || fetch > max_fetch) fetch = max_fetch;
  
          final List<T> result = new ArrayList<>(fetch);
          for (int i = 0; i < fetch && !iter.atEnd(); ++i) {
              if (iter.nextAvail()) result.add(iter.next());
  
              // Decide if we should cut the fetch short.
              // We stop fetching more items if the time delay exceeds the deadline.
              final long tCur = System.currentTimeMillis();
              if (!result.isEmpty() && tCur - t0 >= MIN_REQUEST_DURATION.getMillis())
                  break;
              else if (tCur - t0 >= MAX_REQUEST_DURATION.getMillis())
                  break;
              else if (!iter.nextAvail()) {
                  // Block until next is available, or until deadline is exceeded.
                  try {
                      iter.waitAvail((t0 + MAX_REQUEST_DURATION.getMillis() - tCur), TimeUnit.MILLISECONDS);
                  } catch (InterruptedException ex) {
                      /* SKIP */
                  }
              }
          }
          return result;
      }
docs: Fetch up to a given amount of items from the iterator.
  
  @param <T> The type of elements in the iterator.
  @param iter The iterator supplying items.
  @param fetch The requested number of items to fetch (user supplied
  parameter).
  @param max_fetch The hard limit on how many items to fetch.
  @return A list with items fetched from the iterator.