public static < R > CloseableIterator < R > iterator ( BaseStream < R , Stream < R > > stream ) { Iterator < R > iterator = stream . iterator ( ) ; if ( iterator instanceof CloseableIterator ) { return ( CloseableIterator < R > ) iterator ; } return new StreamToCloseableIterator <> ( stream , iterator ) ; }
Creates a closeable iterator that when closed will close the underlying stream as well