in src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java [495:528]
private long skipInternal(final long n) throws IOException {
if (!stateChangeLock.isLocked()) {
throw new IllegalStateException("Expected stateChangeLock to be locked");
}
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();
if (toSkip <= 0) { // skipping from activeBuffer already handled.
throw new IllegalStateException("Expected toSkip > 0, actual: " + toSkip);
}
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;
}