Re: Identifying resource-using streams

Timo Kinnunen timo.kinnunen at gmail.com
Wed Apr 23 16:56:21 UTC 2014


Hi, 


Thanks for these, it was fascinating seeing the similarities and differences in these approaches to the same problems and then comparing those to my take on Streams.


After polishing the README.md I too have released my version of Stream-wrappers as a library here: https://github.com/Overruler/SuperiorStreams 




I couldn’t help but include some thoughts on API design and language design there as well ��





-- 
Have a nice day,
Timo.

Sent from Windows Mail





From: Victor Nazarov
Sent: ‎Tuesday‎, ‎April‎ ‎22‎, ‎2014 ‎15‎:‎37
To: Peter Levart
Cc: Timo Kinnunen, lambda-dev at openjdk.java.net







On Mon, Apr 21, 2014 at 11:31 PM, Peter Levart <peter.levart at gmail.com> wrote:



On 04/21/2014 08:42 AM, Timo Kinnunen wrote:



almost all of the cases where I plan to use Streams involve reading the contents of directories, reading the contents of files or reading the contents of JAR files. All are cases where resources are involved and the processing too complicated to fit in a single method.



Using things like a Supplier<FileInputStream> it would be very easy to delay the resource acquisition so that it could happen inside the terminal method, making every terminal naturally responsible for releasing resources.

All of the above brings up another unfortunate feature of the API: a Stream is very close to being an immutable stateless builder for stream-like processing but it is neither immutable nor stateless.

If Stream was immutable and stateless then you would be able to reuse, rerun and combine Streams freely and all the processing would be happening in a single place, inside terminals. Because where else could it happen?


Hi,

Here's some ideas I played with while Streams API was still being developed:

    https://github.com/plevart/streamx

I have just updated it so that it compiles with released JDK 8 API.





Here is my take on stream library.



https://github.com/sviperll/chicory/tree/master/chicory-stream




Streams doesn't have close method, instread resources are aquired and released on every terminal operation. See the difinition of StreamableTextFile for example:




https://github.com/sviperll/chicory/blob/master/chicory-stream/src/main/java/org/github/sviperll/stream/StreamableTextFile.java





The only case when you required to manually close resource is when you use iterators. Stream provides openIterator method. See tests for example usage:




https://github.com/sviperll/chicory/blob/master/chicory-stream/src/test/java/org/github/sviperll/stream/StreamTest.java





--

Victor Nazarov


More information about the lambda-dev mailing list