Skip to content

Commit 1f9d220

Browse files
committed
---
yaml --- r: 7023 b: refs/heads/tswast-patch-1 c: cded234 h: refs/heads/master i: 7021: 3e0aeb6 7019: 729b252 7015: ba79eca 7007: 50bc246
1 parent 1c0a329 commit 1f9d220

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: d3224b38a07dbfd776b0818684bc21a5adcfeb64
60+
refs/heads/tswast-patch-1: cded23436465bb5fb1233eb5cd6740b4561357f9
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,20 @@ public Tuple<String, byte[]> read(StorageObject from, Map<Option, ?> options, lo
461461
public void write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length,
462462
boolean last) {
463463
try {
464+
if (length == 0 && !last) {
465+
return;
466+
}
464467
GenericUrl url = new GenericUrl(uploadId);
465468
HttpRequest httpRequest = storage.getRequestFactory().buildPutRequest(url,
466469
new ByteArrayContent(null, toWrite, toWriteOffset, length));
467470
long limit = destOffset + length;
468471
StringBuilder range = new StringBuilder("bytes ");
469-
range.append(destOffset).append('-').append(limit - 1).append('/');
472+
if (length == 0) {
473+
range.append('*');
474+
} else {
475+
range.append(destOffset).append('-').append(limit - 1);
476+
}
477+
range.append('/');
470478
if (last) {
471479
range.append(limit);
472480
} else {

branches/tswast-patch-1/gcloud-java-storage/src/test/java/com/google/gcloud/storage/it/ITStorageTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,29 @@ public void testReadAndWriteChannels() throws IOException {
823823
assertTrue(storage.delete(BUCKET, blobName));
824824
}
825825

826+
@Test
827+
public void testReadAndWriteChannelsWithDifferentFileSize() throws IOException {
828+
String blobNamePrefix = "test-read-and-write-channels-blob-";
829+
int[] blobSizes = {0, 700, 1024 * 256, 2 * 1024 * 1024, 4 * 1024 * 1024, 4 * 1024 * 1024 + 1};
830+
Random rnd = new Random();
831+
for (int blobSize : blobSizes) {
832+
String blobName = blobNamePrefix + blobSize;
833+
BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
834+
byte[] bytes = new byte[blobSize];
835+
rnd.nextBytes(bytes);
836+
try (WriteChannel writer = storage.writer(blob)) {
837+
writer.write(ByteBuffer.wrap(BLOB_BYTE_CONTENT));
838+
}
839+
ByteBuffer readBytes;
840+
try (ReadChannel reader = storage.reader(blob.blobId())) {
841+
readBytes = ByteBuffer.allocate(BLOB_BYTE_CONTENT.length);
842+
reader.read(readBytes);
843+
}
844+
assertArrayEquals(BLOB_BYTE_CONTENT, readBytes.array());
845+
assertTrue(storage.delete(BUCKET, blobName));
846+
}
847+
}
848+
826849
@Test
827850
public void testReadAndWriteCaptureChannels() throws IOException {
828851
String blobName = "test-read-and-write-capture-channels-blob";

0 commit comments

Comments
 (0)