RFR: 8358533: Improve performance of java.io.Reader.readAllLines

Markus KARG duke at openjdk.org
Thu Jun 19 11:18:06 UTC 2025


On Wed, 18 Jun 2025 16:45:33 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> I think we should treat "\r\n" as a single line terminator? for example
>> 
>>  "hello\r\nworld".lines().forEach(line -> out.format("[%s]\n", line));
>> =>
>> [hello]
>> [world]
>> 
>> instead of (the current impl)
>> 
>> [hello]
>> []
>> [world]
>> 
>> or I misread the impl?
>
>> I think we should treat "\r\n" as a single line terminator?
> 
> You are correct: that needs to be fixed:
> 
> jshell> Reader r = new StringReader("hello\r\nworld")
> r ==> java.io.StringReader at 480bdb19
> 
> jshell> r.readAllLines()
> $3 ==> [hello, , world]
> 
> Thanks for the catch!

`Scanner` seems to scan for even more characters: https://github.com/openjdk/jdk/blob/c4fb00a7be51c7a05a29d3d57d787feb5c698ddf/src/java.base/share/classes/java/util/Scanner.java#L490

Would it make sense to resemble this? Would it make sense to simply use `Scanner` directly? 🤔

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25863#discussion_r2156724736


More information about the core-libs-dev mailing list