code: public static <T> CloseableIterable<T> autoClose(final CloseableIterable<? extends T> iterable) {
          requireNonNull(iterable);
          return new FluentCloseableIterable<T>() {
              @Override
              protected void doClose() {
                  iterable.close();
              }
  
              @Override
              protected Iterator<T> retrieveIterator() {
                  //autoclose iterator when it is exhausted.
                  return CloseableIterators.autoClose(
                          CloseableIterators.wrap(iterable.iterator(), iterable)
                  );
              }
          };
      }
docs: Autoclose the {@code iterable} when its iterator is exhausted or if an exception is thrown.
  <p/>
  Note that when using this method the order of calls matters. {@code limit()} is an example of one method which can
  prevent the completion of an iterator.  For instance limit(autoClose(iterable), 1) will not close the
  resource if there is more than 1 element, but autoClose(limit(iterable, 1)) will close the underlying
  resource.