Point lambdafications in java.io

Joe Bowbeer joe.bowbeer at gmail.com
Tue Jun 18 10:36:59 PDT 2013


I think that Stream and Input/Output Stream are different enough that I
find the word "Stream" in CloseableStream confusing.

For one thing, Stream is not a base class of InputStream and OutputStream,
as one might expect given the name.

What does moving AutoCloseable up to Stream mean?

It is the InputStream source that is Closeable, not the Stream of results?



On Tue, Jun 18, 2013 at 9:56 AM, Brian Goetz <brian.goetz at oracle.com> wrote:

> FWIW, the current implementation of CloseableStream doesn't do anything
> special for this case either.  Ideally such a construction would fail, but
> currently it does not with CloseableStream.  Is this defensible?  Is there
> a wording of the spec here that allows close() to only operate on external
> resources that the stream depends on, like files?
>
>
> On 6/18/2013 12:30 PM, Sam Pullara wrote:
>
>> I am very much in favor of a way to signal to the stream to relinquish
>> resources so that you don't have to exhaust it to ensure that it is cleaned
>> up. That said, without things like takeWhile() I'm not sure that there are
>> many cases where you can close the stream unless you are in an exception
>> state. What would be the semantics of something like this:
>>
>> Stream stream = list.stream();
>> stream.forEach(o -> stream.close());
>>
>> Sam
>>
>> On Jun 18, 2013, at 9:05 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
>>
>>  The libraries team added the following methods to java.io and java.nio,
>>> with discussion on corelibs-dev:
>>>
>>> In java.io.BufferedReader:
>>>   Stream<String> lines()
>>>
>>> In java.nio.Files, static methods for:
>>>
>>>   CloseableStream<Path> list(Path dir) throws IOException;
>>>
>>>   CloseableStream<Path> walk(Path start, int maxDepth,
>>> FileVisitOption... options) throws IOException
>>>
>>>   CloseableStream<Path> walk(Path start, FileVisitOption... options)
>>> throws IOException
>>>
>>>   CloseableStream<Path> find(Path start,
>>>                            int maxDepth,
>>>                            BiPredicate<Path, BasicFileAttributes>
>>> matcher,
>>>                            FileVisitOption... options)
>>>         throws IOException
>>>
>>>   CloseableStream<String> lines(Path path, Charset cs) throws IOException
>>>
>>>
>>> CloseableStream simply extends Stream and AutoCloseable, making it
>>> suitable for use with try-with-resources:
>>>
>>> public interface CloseableStream<T> extends Stream<T>, AutoCloseable {
>>>     void close();
>>> }
>>>
>>> Should we consider moving AutoCloseable up to Stream and friends, and
>>> get rid of CloseableStream?
>>>
>>>
>>


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