Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.cloud.storage.Hasher.UncheckedChecksumMismatchException;
import com.google.cloud.storage.ResponseContentLifecycleHandle.ChildRef;
import com.google.cloud.storage.Retrying.Retrier;
import java.util.OptionalLong;
import com.google.cloud.storage.UnbufferedReadableByteChannelSession.UnbufferedReadableByteChannel;
import com.google.common.base.Suppliers;
import com.google.protobuf.ByteString;
Expand Down Expand Up @@ -91,7 +92,9 @@ final class GapicUnbufferedReadableByteChannel
this.result = result;
this.read = read;
this.req = req;
this.hasher = hasher;
this.hasher = (req.getReadOffset() == 0)
? new CumulativeHasher(hasher, 0, req.getReadLimit() <= 0 ? OptionalLong.empty() : OptionalLong.of(req.getReadLimit()))
: hasher;
this.fetchOffset = new AtomicLong(req.getReadOffset());
this.blobOffset = req.getReadOffset();
this.retrier = retrier;
Expand Down Expand Up @@ -174,6 +177,7 @@ public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
}
if (take == EOF_MARKER) {
complete = true;
validateCumulativeChecksum();
break;
}

Expand Down Expand Up @@ -311,6 +315,18 @@ private IOException createError(String message) throws IOException {
return new IOException(message, cause);
}

private void validateCumulativeChecksum() throws IOException {
if (hasher instanceof CumulativeHasher) {
CumulativeHasher cumulativeHasher = (CumulativeHasher) hasher;
try {
cumulativeHasher.validateCumulativeChecksum(metadata);
} catch (UncheckedCumulativeChecksumMismatchException exception) {
throw new IOException(StorageException.coalesce(exception));
}
}
}


private final class ReadObjectObserver extends StateCheckingResponseObserver<ReadObjectResponse> {

private final SettableApiFuture<Void> open = SettableApiFuture.create();
Expand Down
Loading
Loading