Skip to content

Commit

Permalink
Enable skip methods on retrying inputstreams
Browse files Browse the repository at this point in the history
Currently we have a number of input streams that specifically override
the skip() method disabling the ability to skip bytes. In each case the
skip implementation works as we have properly implemented the
read(byte[]) methods used to discard bytes. However, we appear to have
disabled it as it would be possible to retry from the end of a skip if
there is a failure in the middle. At this time, that optimization is not
really necessary, however, we sporadically used skip so it would be nice
for the IS to support the method. This commit enables the super.skip()
and adds a comment about future optimizations.
  • Loading branch information
Tim-Brooks committed May 24, 2023
1 parent 1a1dcd9 commit 468cd71
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,6 @@ public void close() {
}
}

@Override
public long skip(long n) {
throw new UnsupportedOperationException("skip is not supported");
}

private void releaseByteBuf(ByteBuf buf) {
ReferenceCountUtil.safeRelease(buf);
this.byteBuf = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ public void close() throws IOException {
}

@Override
public long skip(long n) {
throw new UnsupportedOperationException("GoogleCloudStorageRetryingInputStream does not support seeking");
public long skip(long n) throws IOException {
// This could be optimized on a failure by re-opening stream directly to the preferred location. However, it is rarely called,
// so for now we will rely on the default implementation which just discards bytes by reading.
return super.skip(n);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ private void maybeAbort(S3ObjectInputStream stream) {
}

@Override
public long skip(long n) {
throw new UnsupportedOperationException("S3RetryingInputStream does not support seeking");
public long skip(long n) throws IOException {
// This could be optimized on a failure by re-opening stream directly to the preferred location. However, it is rarely called,
// so for now we will rely on the default implementation which just discards bytes by reading.
return super.skip(n);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ public int read(byte[] b, int off, int len) throws IOException {
}

@Override
public long skip(long n) {
throw new UnsupportedOperationException("RetryingHttpInputStream does not support seeking");
public long skip(long n) throws IOException {
// This could be optimized on a failure by re-opening stream directly to the preferred location. However, it is rarely called,
// so for now we will rely on the default implementation which just discards bytes by reading.
return super.skip(n);
}

@Override
Expand Down

0 comments on commit 468cd71

Please sign in to comment.