in src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java [475:504]
private long skipInternal(final long n) throws IOException {
assert stateChangeLock.isLocked();
waitForAsyncReadComplete();
if (isEndOfStream()) {
return 0;
}
if (available() >= n) {
// we can skip from the internal buffers
int toSkip = (int) n;
// We need to skip from both active buffer and read ahead buffer
toSkip -= activeBuffer.remaining();
assert toSkip > 0; // skipping from activeBuffer already handled.
activeBuffer.position(0);
activeBuffer.flip();
readAheadBuffer.position(toSkip + readAheadBuffer.position());
swapBuffers();
// Trigger async read to emptied read ahead buffer.
readAsync();
return n;
}
final int skippedBytes = available();
final long toSkip = n - skippedBytes;
activeBuffer.position(0);
activeBuffer.flip();
readAheadBuffer.position(0);
readAheadBuffer.flip();
final long skippedFromInputStream = in.skip(toSkip);
readAsync();
return skippedBytes + skippedFromInputStream;
}