src/java.base/share/classes/java/io/BufferedReader.java
changeset 58089 e64fec9f1773
parent 47216 71c04702a3d5
child 58242 94bb65cb37d3
equal deleted inserted replaced
58088:e2de6e166880 58089:e64fec9f1773
     1 /*
     1 /*
     2  * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   300      * of a line feed ('\n'), a carriage return ('\r'), a carriage return
   300      * of a line feed ('\n'), a carriage return ('\r'), a carriage return
   301      * followed immediately by a line feed, or by reaching the end-of-file
   301      * followed immediately by a line feed, or by reaching the end-of-file
   302      * (EOF).
   302      * (EOF).
   303      *
   303      *
   304      * @param      ignoreLF  If true, the next '\n' will be skipped
   304      * @param      ignoreLF  If true, the next '\n' will be skipped
       
   305      * @param      term      Output: Whether a line terminator was encountered
       
   306      *                       while reading the line; may be {@code null}.
   305      *
   307      *
   306      * @return     A String containing the contents of the line, not including
   308      * @return     A String containing the contents of the line, not including
   307      *             any line-termination characters, or null if the end of the
   309      *             any line-termination characters, or null if the end of the
   308      *             stream has been reached without reading any characters
   310      *             stream has been reached without reading any characters
   309      *
   311      *
   310      * @see        java.io.LineNumberReader#readLine()
   312      * @see        java.io.LineNumberReader#readLine()
   311      *
   313      *
   312      * @exception  IOException  If an I/O error occurs
   314      * @exception  IOException  If an I/O error occurs
   313      */
   315      */
   314     String readLine(boolean ignoreLF) throws IOException {
   316     String readLine(boolean ignoreLF, boolean[] term) throws IOException {
   315         StringBuffer s = null;
   317         StringBuffer s = null;
   316         int startChar;
   318         int startChar;
   317 
   319 
   318         synchronized (lock) {
   320         synchronized (lock) {
   319             ensureOpen();
   321             ensureOpen();
   320             boolean omitLF = ignoreLF || skipLF;
   322             boolean omitLF = ignoreLF || skipLF;
       
   323             if (term != null) term[0] = false;
   321 
   324 
   322         bufferLoop:
   325         bufferLoop:
   323             for (;;) {
   326             for (;;) {
   324 
   327 
   325                 if (nextChar >= nChars)
   328                 if (nextChar >= nChars)
   342 
   345 
   343             charLoop:
   346             charLoop:
   344                 for (i = nextChar; i < nChars; i++) {
   347                 for (i = nextChar; i < nChars; i++) {
   345                     c = cb[i];
   348                     c = cb[i];
   346                     if ((c == '\n') || (c == '\r')) {
   349                     if ((c == '\n') || (c == '\r')) {
       
   350                         if (term != null) term[0] = true;
   347                         eol = true;
   351                         eol = true;
   348                         break charLoop;
   352                         break charLoop;
   349                     }
   353                     }
   350                 }
   354                 }
   351 
   355 
   387      * @exception  IOException  If an I/O error occurs
   391      * @exception  IOException  If an I/O error occurs
   388      *
   392      *
   389      * @see java.nio.file.Files#readAllLines
   393      * @see java.nio.file.Files#readAllLines
   390      */
   394      */
   391     public String readLine() throws IOException {
   395     public String readLine() throws IOException {
   392         return readLine(false);
   396         return readLine(false, null);
   393     }
   397     }
   394 
   398 
   395     /**
   399     /**
   396      * Skips characters.
   400      * Skips characters.
   397      *
   401      *