diff options
| author | Brian Burkhalter <bpb@openjdk.org> | 2020-08-05 11:40:07 -0700 |
|---|---|---|
| committer | Brian Burkhalter <bpb@openjdk.org> | 2020-08-05 11:40:07 -0700 |
| commit | 3ea5fdc9ac2825a30dbd21aaa64aa6ce800d97ce (patch) | |
| tree | 99ad3529224c434ff2b13793a1bf8754deecd4e8 /src/java.base/share/classes/java/io/BufferedReader.java | |
| parent | 339016a0f2cbbbbc3560e50c6726e14afbf547f6 (diff) | |
| download | openjdk-3ea5fdc9ac2825a30dbd21aaa64aa6ce800d97ce.tar.gz openjdk-3ea5fdc9ac2825a30dbd21aaa64aa6ce800d97ce.zip | |
8235792: LineNumberReader.getLineNumber() behavior is inconsistent with respect to EOF
Reviewed-by: alanb, darcy, rriggs
Diffstat (limited to 'src/java.base/share/classes/java/io/BufferedReader.java')
| -rw-r--r-- | src/java.base/share/classes/java/io/BufferedReader.java | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/java.base/share/classes/java/io/BufferedReader.java b/src/java.base/share/classes/java/io/BufferedReader.java index 6825dc530e9..25ceaf3f25c 100644 --- a/src/java.base/share/classes/java/io/BufferedReader.java +++ b/src/java.base/share/classes/java/io/BufferedReader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -302,6 +302,8 @@ public class BufferedReader extends Reader { * (EOF). * * @param ignoreLF If true, the next '\n' will be skipped + * @param term Output: Whether a line terminator was encountered + * while reading the line; may be {@code null}. * * @return A String containing the contents of the line, not including * any line-termination characters, or null if the end of the @@ -311,13 +313,14 @@ public class BufferedReader extends Reader { * * @throws IOException If an I/O error occurs */ - String readLine(boolean ignoreLF) throws IOException { + String readLine(boolean ignoreLF, boolean[] term) throws IOException { StringBuilder s = null; int startChar; synchronized (lock) { ensureOpen(); boolean omitLF = ignoreLF || skipLF; + if (term != null) term[0] = false; bufferLoop: for (;;) { @@ -344,6 +347,7 @@ public class BufferedReader extends Reader { for (i = nextChar; i < nChars; i++) { c = cb[i]; if ((c == '\n') || (c == '\r')) { + if (term != null) term[0] = true; eol = true; break charLoop; } @@ -389,7 +393,7 @@ public class BufferedReader extends Reader { * @see java.nio.file.Files#readAllLines */ public String readLine() throws IOException { - return readLine(false); + return readLine(false, null); } /** |
