hg: lambda/lambda/jdk: Add BufferedReader.lines

Brian Goetz brian.goetz at oracle.com
Sun Nov 11 15:39:58 PST 2012


I'm not really sure what to do with your comment.  Are you arguing that, 
because someone could use it in a leaky way, we should not add it to the 
JDK?

Here's a totally safe idiom where it adds a lot of value:

try (reader = new BR(new FR(file))) {
     reader.lines()
           .filter(e -> !startsWith("#"))
           .map(e -> e.toUpperCase())
           .forEach(...);
}

It would be a shame to take it away from everyone just because it can be 
misused.

What are you suggesting?


On 11/11/2012 6:35 PM, Ricky Clarkson wrote:
> BufferedReader.lines() seems like the kind of method likely to cause
> resource leaks; if I use it and create a Stream<String> and then return
> that to my caller, I can't close the BufferedReader in the same place I
> create it, and my caller cannot close the BufferedReader either.
>
>
> On Sun, Nov 11, 2012 at 8:24 PM, Arne Siegel
> <v.a.ammodytes at googlemail.com <mailto:v.a.ammodytes at googlemail.com>> wrote:
>
>     Hi Brian,
>
>     nice utility function, though I don't think you got the if statement
>     in next() right.
>
>     @Override
>     public String next() {
>          if (nextLine == null || hasNext()) {
>              try {
>                  return nextLine;
>     ...
>
>     Better keep it simple:
>     ...
>          if (hasNext()) {
>     ...
>
>     Arne Siegel
>
>
>     On 11 Nov 2012 at 22:50, brian.goetz at oracle.com
>     <mailto:brian.goetz at oracle.com> wrote:
>
>      > Changeset: 94d64473e8e6
>      > Author:    briangoetz
>      > Date:      2012-11-11 17:44 -0500
>      > URL: http://hg.openjdk.java.net/lambda/lambda/jdk/rev/94d64473e8e6
>      >
>      > Add BufferedReader.lines
>      >
>      > ! src/share/classes/java/io/BufferedReader.java
>      > ! src/share/classes/java/io/Reader.java
>      > + src/share/classes/java/io/UncheckedIOException.java
>      >
>      >
>
>
>
>


More information about the lambda-dev mailing list