diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/ChunkedDownloadCallable.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/ChunkedDownloadCallable.java index 88c013a24a..f64e042be3 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/ChunkedDownloadCallable.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/ChunkedDownloadCallable.java @@ -58,9 +58,10 @@ final class ChunkedDownloadCallable implements Callable { @Override public DownloadSegment call() { long bytesCopied = -1L; - try (ReadChannel rc = storage.reader(originalBlob.getBlobId(), opts)) { - FileChannel wc = - FileChannel.open(destPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE); + try (ReadChannel rc = storage.reader(originalBlob.getBlobId(), opts); + FileChannel wc = + FileChannel.open(destPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE)) { + rc.setChunkSize(0); rc.seek(startPosition); rc.limit(endPosition); wc.position(startPosition); diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/DirectDownloadCallable.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/DirectDownloadCallable.java index 0c7ec86a47..f2c8ba1776 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/DirectDownloadCallable.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/DirectDownloadCallable.java @@ -52,14 +52,15 @@ public DownloadResult call() { Path path = TransferManagerUtils.createDestPath(parallelDownloadConfig, originalBlob); long bytesCopied = -1L; try (ReadChannel rc = - storage.reader( - BlobId.of(parallelDownloadConfig.getBucketName(), originalBlob.getName()), opts)) { - FileChannel wc = - FileChannel.open( - path, - StandardOpenOption.WRITE, - StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING); + storage.reader( + BlobId.of(parallelDownloadConfig.getBucketName(), originalBlob.getName()), opts); + FileChannel wc = + FileChannel.open( + path, + StandardOpenOption.WRITE, + StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING)) { + rc.setChunkSize(0); bytesCopied = ByteStreams.copy(rc, wc); if (originalBlob.getSize() != null) { if (bytesCopied != originalBlob.getSize()) {