Process additional characters from the stream. When a line separator is found the contents of the line and the line separator itself are passed to the abstract {@link #handleLine} method. @param cbuf the character buffer to process @param off the offset into the buffer @param len the number of char
(char[] cbuf, int off, int len)
| 50 | * @see #finish |
| 51 | */ |
| 52 | protected void add(char[] cbuf, int off, int len) throws IOException { |
| 53 | int pos = off; |
| 54 | if (sawReturn && len > 0) { |
| 55 | // Last call to add ended with a CR; we can handle the line now. |
| 56 | if (finishLine(cbuf[pos] == '\n')) { |
| 57 | pos++; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | int start = pos; |
| 62 | for (int end = off + len; pos < end; pos++) { |
| 63 | switch (cbuf[pos]) { |
| 64 | case '\r': |
| 65 | line.append(cbuf, start, pos - start); |
| 66 | sawReturn = true; |
| 67 | if (pos + 1 < end) { |
| 68 | if (finishLine(cbuf[pos + 1] == '\n')) { |
| 69 | pos++; |
| 70 | } |
| 71 | } |
| 72 | start = pos + 1; |
| 73 | break; |
| 74 | |
| 75 | case '\n': |
| 76 | line.append(cbuf, start, pos - start); |
| 77 | finishLine(true); |
| 78 | start = pos + 1; |
| 79 | break; |
| 80 | |
| 81 | default: |
| 82 | // do nothing |
| 83 | } |
| 84 | } |
| 85 | line.append(cbuf, start, off + len - start); |
| 86 | } |
| 87 | |
| 88 | /** Called when a line is complete. */ |
| 89 | @CanIgnoreReturnValue |