changes as per review comments

This commit is contained in:
Ahmar Suhail 2022-03-15 15:39:09 +00:00
parent bd26dc86d6
commit c235a6eb92
2 changed files with 10 additions and 6 deletions

View File

@ -1179,14 +1179,16 @@ public long skip(final long n) throws IOException {
checkNotClosed();
streamStatistics.skipOperationStarted();
long targetPos = pos + n;
// target pos should be less than EOF
long targetPos = Math.min(contentLength, pos + n);
long bytesToSkip = targetPos - pos;
long skipped;
try {
lazySeek(targetPos, 1);
skipped = n;
skipped = bytesToSkip;
} catch (EOFException e) {
LOG.debug("Lazy seek failed, attempting default skip");
LOG.debug("Lazy seek failed, attempting default skip", e);
skipped = wrappedStream.skip(n);
if (skipped > 0) {

View File

@ -493,11 +493,13 @@ public void testSkip() throws Throwable {
in = openTestFile(S3AInputPolicy.Random, DEFAULT_READAHEAD_RANGE);
in.skip(_4K);
assertEquals("bytes skipped", _4K, in.skip(_4K));
// Skip within read ahead range, will not make a new get request
in.skip(_8K);
assertEquals("bytes skipped", _8K, in.skip(_8K));
// Skip outside read ahead range, should make a new get request
in.skip(_256K);
assertEquals("bytes skipped", _256K, in.skip(_256K));
IOStatistics ioStatistics = streamStatistics.getIOStatistics();