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-
()
| 69 | */ |
| 70 | |
| 71 | @CanIgnoreReturnValue // to skip a line |
| 72 | public String readLine() throws IOException { |
| 73 | while (lines.peek() == null) { |
| 74 | cbuf.clear(); |
| 75 | // The default implementation of Reader#read(CharBuffer) allocates a |
| 76 | // temporary char[], so we call Reader#read(char[], int, int) instead. |
| 77 | |
| 78 | int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); |
| 79 | if (read == -1) { |
| 80 | lineBuf.finish(); |
| 81 | break; |
| 82 | } |
| 83 | lineBuf.add(buf, 0, read); |
| 84 | } |
| 85 | return lines.poll(); |
| 86 | } |
| 87 | } |