Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed ("\r\n"). @return a String containing the contents of the line, not including any line-
()
| 70 | * @throws IOException if an I/O error occurs |
| 71 | */ |
| 72 | @CanIgnoreReturnValue // to skip a line |
| 73 | public String readLine() throws IOException { |
| 74 | while (lines.peek() == null) { |
| 75 | cbuf.clear(); |
| 76 | // The default implementation of Reader#read(CharBuffer) allocates a |
| 77 | // temporary char[], so we call Reader#read(char[], int, int) instead. |
| 78 | int read = (reader != null) |
| 79 | ? reader.read(buf, 0, buf.length) |
| 80 | : readable.read(cbuf); |
| 81 | if (read == -1) { |
| 82 | lineBuf.finish(); |
| 83 | break; |
| 84 | } |
| 85 | lineBuf.add(buf, 0, read); |
| 86 | } |
| 87 | return lines.poll(); |
| 88 | } |
| 89 | } |