--- old/src/share/classes/java/util/stream/BaseStream.java 2013-07-10 14:11:42.811135634 -0700 +++ new/src/share/classes/java/util/stream/BaseStream.java 2013-07-10 14:11:42.623135637 -0700 @@ -24,6 +24,7 @@ */ package java.util.stream; +import java.util.MayHoldCloseableResource; import java.util.Iterator; import java.util.Spliterator; @@ -35,7 +36,8 @@ * @param type of stream implementing {@code BaseStream} * @since 1.8 */ -public interface BaseStream> { +public interface BaseStream> + extends MayHoldCloseableResource { /** * Returns an iterator for the elements of this stream. * @@ -103,4 +105,18 @@ * @return an unordered stream */ S unordered(); + + /** + * Returns an equivalent stream with an additional close handler. Close + * handlers are run when the {@link MayHoldCloseableResource#close()} method + * is called on the stream, and are executed in the order they were + * added. All close handlers are run, even if earlier close handlers throw + * exceptions. If any close handler throws an exception, the first + * exception thrown will be relayed to the caller of {@code close()}, with + * any remaining exceptions added to that exception as suppressed exceptions. + * + * @param closeHandler A task to execute when the stream is closed + * @return a stream with a handler that is run if the stream is closed + */ + S onClose(Runnable closeHandler); }