< prev index next >
src/java.base/share/classes/java/io/BufferedReader.java
Print this page
@@ -1,7 +1,7 @@
/*
- * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -300,26 +300,29 @@
* of a line feed ('\n'), a carriage return ('\r'), a carriage return
* followed immediately by a line feed, or by reaching the end-of-file
* (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
* stream has been reached without reading any characters
*
* @see java.io.LineNumberReader#readLine()
*
* @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 (;;) {
if (nextChar >= nChars)
@@ -342,10 +345,11 @@
charLoop:
for (i = nextChar; i < nChars; i++) {
c = cb[i];
if ((c == '\n') || (c == '\r')) {
+ if (term != null) term[0] = true;
eol = true;
break charLoop;
}
}
@@ -387,11 +391,11 @@
* @throws IOException If an I/O error occurs
*
* @see java.nio.file.Files#readAllLines
*/
public String readLine() throws IOException {
- return readLine(false);
+ return readLine(false, null);
}
/**
* Skips characters.
*
< prev index next >