src/share/classes/java/util/stream/Stream.java

Print this page
rev 7962 : 8017513: Support for closeable streams
8022237: j.u.s.BaseStream.onClose() has an issue in implementation or requires spec clarification
8022572: Same exception instances thrown from j.u.stream.Stream.onClose() handlers are not listed as suppressed
Summary: BaseStream implements AutoCloseable; Remove CloseableStream and DelegatingStream
Reviewed-by:
Contributed-by: brian.goetz@oracle.com

*** 889,899 **** /** * Creates a lazy concatenated {@code Stream} whose elements are all the * elements of a first {@code Stream} succeeded by all the elements of the * second {@code Stream}. The resulting stream is ordered if both * of the input streams are ordered, and parallel if either of the input ! * streams is parallel. * * @param <T> The type of stream elements * @param a the first stream * @param b the second stream to concatenate on to end of the first * stream --- 889,900 ---- /** * Creates a lazy concatenated {@code Stream} whose elements are all the * elements of a first {@code Stream} succeeded by all the elements of the * second {@code Stream}. The resulting stream is ordered if both * of the input streams are ordered, and parallel if either of the input ! * streams is parallel. When the resulting stream is closed, the close ! * handlers for both input streams is invoked. * * @param <T> The type of stream elements * @param a the first stream * @param b the second stream to concatenate on to end of the first * stream
*** 904,914 **** Objects.requireNonNull(b); @SuppressWarnings("unchecked") Spliterator<T> split = new Streams.ConcatSpliterator.OfRef<>( (Spliterator<T>) a.spliterator(), (Spliterator<T>) b.spliterator()); ! return StreamSupport.stream(split, a.isParallel() || b.isParallel()); } /** * A mutable builder for a {@code Stream}. This allows the creation of a * {@code Stream} by generating elements individually and adding them to the --- 905,916 ---- Objects.requireNonNull(b); @SuppressWarnings("unchecked") Spliterator<T> split = new Streams.ConcatSpliterator.OfRef<>( (Spliterator<T>) a.spliterator(), (Spliterator<T>) b.spliterator()); ! Stream<T> stream = StreamSupport.stream(split, a.isParallel() || b.isParallel()); ! return stream.onClose(Streams.composedClose(a, b)); } /** * A mutable builder for a {@code Stream}. This allows the creation of a * {@code Stream} by generating elements individually and adding them to the