From cf777fcaa578ebeace11dff3b75e774c9874c9a9 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 13 Nov 2015 18:50:28 +0100 Subject: [PATCH] Fix setting ContentRange to inclusive positions --- .../src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java index b1e188f1d1fb..a033ed635d2d 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java @@ -60,6 +60,7 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; +import com.google.common.primitives.Ints; import com.google.gcloud.storage.StorageException; import com.google.gcloud.storage.StorageOptions; @@ -415,7 +416,7 @@ public byte[] read(StorageObject from, Map options, long position, in .setIfGenerationMatch(IF_GENERATION_MATCH.getLong(options)) .setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(options)); MediaHttpDownloader downloader = req.getMediaHttpDownloader(); - downloader.setContentRange(position, (int) position + bytes); + downloader.setContentRange(position, Ints.checkedCast(position + bytes - 1)); downloader.setDirectDownloadEnabled(true); ByteArrayOutputStream output = new ByteArrayOutputStream(); req.executeMediaAndDownloadTo(output);