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
()
| 267 | * @throws UncheckedIOException if an I/O exception is encountered |
| 268 | */ |
| 269 | private boolean fill() { |
| 270 | if (source == null) { |
| 271 | // String-backed input is fully buffered on construction. |
| 272 | return filled > position + 1; |
| 273 | } |
| 274 | |
| 275 | // do we need to fill the buffer? |
| 276 | while (filled == position + 1) { |
| 277 | try { |
| 278 | // free the buffer, keep only the chars to remember |
| 279 | int shift = filled - MEMORY_SIZE; |
| 280 | if (shift > 0) { |
| 281 | position -= shift; |
| 282 | filled -= shift; |
| 283 | |
| 284 | System.arraycopy(buffer, shift, buffer, 0, filled); |
| 285 | } |
| 286 | |
| 287 | // try to fill the buffer |
| 288 | int n = source.read(buffer, filled, buffer.length - filled); |
| 289 | |
| 290 | if (n == -1) { |
| 291 | // EOF reached |
| 292 | return false; |
| 293 | } else { |
| 294 | // n might be 0, the outer loop will handle this |
| 295 | filled += n; |
| 296 | } |
| 297 | } catch (IOException e) { |
| 298 | throw new UncheckedIOException(e.getMessage(), e); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | return true; |
| 303 | } |
| 304 | } |