I'm creating a small library to read over each line of a text file and format it in a certain way, making each line available using Java 8 streams. This is similar to Files.lines(...)
in the standard jdk.
I wanted to make the API as simple to use as possible, so ideally the stream would close itself after usage. ie. The user would not have to explicitly use a try-with-resources around the stream, unlike for example Files.lines (Why is Files.lines (and similar Streams) not automatically closed?).
To do so I can force the stream to call its own .close
method just before running any of its terminal operations.
My question is: Is this a good idea? If not why? If yes, is this a reasonable approach?
Chers