code: public static <T> CloseableIterator<T> chain(final Iterator<? extends CloseableIterator<? extends T>> iterator) {
          requireNonNull(iterator);
          return new CloseableIterator<T>() {
              CloseableIterator<? extends T> curr = emptyIterator();
  
              @Override
              public void close() {
                  //Close the current one then close all the others
                  if (curr != null)
                      curr.closeQuietly();
  
                  while (iterator.hasNext())
                      iterator.next().closeQuietly();
  
              }
  
              @Override
              public boolean hasNext() {
                  //autoclose will close when the iterator is exhausted
                  while (!curr.hasNext() && iterator.hasNext())
                      curr = autoClose(iterator.next());
  
                  return curr.hasNext();
              }
  
              @Override
              public T next() {
                  if (hasNext())
                      return curr.next();
  
                  throw new NoSuchElementException();
              }
  
              @Override
              public void remove() {
                  curr.remove();
              }
          };
      }
docs: Combines multiple closeable iterators into a single closeable iterator. The returned
  closeable iterator iterates across the elements of each closeable iterator in {@code inputs}.
  The input iterators are not polled until necessary.
  <p/>
  As each closeable iterator is exhausted, it is closed before moving onto the next closeable
  iterator.  A call to close on the returned closeable iterator will quietly close all of
  the closeable iterators in {@code inputs} which have not been exhausted.