Stream is AutoCloseable, Stream.onClose

Henry Jen henry.jen at
Thu Jun 20 12:28:39 PDT 2013

On 06/20/2013 08:17 AM, Paul Sandoz wrote:
> Hi,
> Having another go at this...
> The current solution of resource management for Stream is poor (as previously mentioned):
> 1) CloseableStream/DelegatingStream add a lot of API surface area.

If we can get rid of at least DelegatingStream would be a win.

> 2) Operations on CloseableStream do not return a CloseableStream.
> 3) try-with-resources always needs to be used with the CloseableStream since the Stream itself has no closeable semantics.

Right, currently it just require any operation on Stream to be in TWR block,

try (CloseableStream cs = ...) {
	Stream s = cs.xxxx

I can see a nested TWR block, one for each CloseableStream produced in
the process.

> 4) Stream.concat fails to propagate the closing

A TWR is required for the top level call to obtain the CloseableStream,
and do any operation to that Stream in the block.

Unfortunately, no way we can enforce close(as we dropped the throwing
checked exception on close method). But at least a CloseableStream is an
obvious hint for developer that the Stream need to be closed.


More information about the lambda-libs-spec-observers mailing list