public static < E > Stream < E > stream ( CloseableIterator < E > iterator , boolean parallel , long size , int characteristics ) { Stream < E > stream = StreamSupport . stream ( Spliterators . spliterator ( iterator , size , characteristics ) , parallel ) ; stream . onClose ( iterator :: close ) ; return stream ; }
Creates a stream that when closed will also close the underlying iterator