If all buffered input has been consumed, read the next chunk into the buffer. NOTE : The last 128 character of consumed input is retained for debug output. @return true if new input is available; false if input is exhausted @throws UncheckedIOException if an I/O exception
()
| 122 | * @throws UncheckedIOException if an I/O exception is encountered |
| 123 | */ |
| 124 | private boolean fill() { |
| 125 | // do we need to fill the buffer? |
| 126 | while (filled == position + 1) { |
| 127 | try { |
| 128 | // free the buffer, keep only the chars to remember |
| 129 | int shift = filled - MEMORY_SIZE; |
| 130 | if (shift > 0) { |
| 131 | position -= shift; |
| 132 | filled -= shift; |
| 133 | |
| 134 | System.arraycopy(buffer, shift, buffer, 0, filled); |
| 135 | } |
| 136 | |
| 137 | // try to fill the buffer |
| 138 | int n = source.read(buffer, filled, buffer.length - filled); |
| 139 | |
| 140 | if (n == -1) { |
| 141 | // EOF reached |
| 142 | return false; |
| 143 | } else { |
| 144 | // n might be 0, the outer loop will handle this |
| 145 | filled += n; |
| 146 | } |
| 147 | } catch (IOException e) { |
| 148 | throw new UncheckedIOException(e.getMessage(), e); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return true; |
| 153 | } |
| 154 | } |