code: public static <T> CloseableIterator<T> fromIterator(Iterator<T> iterator) {
          requireNonNull(iterator);
          if (iterator instanceof CloseableIterator) return (CloseableIterator<T>) iterator;
  
          return new CloseableIterator<T>() {
              @Override
              public void close() {
                  if (iterator instanceof AutoCloseable) {
                      try {
                          ((AutoCloseable) iterator).close();
                      } catch (RuntimeException re) {
                          throw re;
                      } catch (Exception e) {
                          throw new IllegalStateException(e);
                      }
                  }
              }
  
              @Override
              public boolean hasNext() {
                  return iterator.hasNext();
              }
  
              @Override
              public T next() {
                  return iterator.next();
              }
  
              @Override
              public void remove() {
                  iterator.remove();
              }
          };
      }
docs: Creates a {@link CloseableIterator} from a standard {@link Iterator}. If {@code iterator} is already
  a {@link CloseableIterator} it will simply be returned as is.