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