diff --git a/google-cloud-storage/clirr-ignored-differences.xml b/google-cloud-storage/clirr-ignored-differences.xml
index 1a35ed0f8..8aabcf10b 100644
--- a/google-cloud-storage/clirr-ignored-differences.xml
+++ b/google-cloud-storage/clirr-ignored-differences.xml
@@ -4,11 +4,11 @@
com/google/cloud/storage/Storage*
7012
- * downloadTo(com.google.cloud.storage.BlobId, java.io.OutputStream, com.google.cloud.storage.Blob$BlobSourceOption[])
+ * downloadTo(com.google.cloud.storage.BlobId, java.io.OutputStream, com.google.cloud.storage.Storage$BlobSourceOption[])
com/google/cloud/storage/Storage*
7012
- * downloadTo(com.google.cloud.storage.BlobId, java.nio.file.Path, com.google.cloud.storage.Blob$BlobSourceOption[])
+ * downloadTo(com.google.cloud.storage.BlobId, java.nio.file.Path, com.google.cloud.storage.Storage$BlobSourceOption[])
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java
index 6762d42f4..79167aec8 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java
@@ -36,7 +36,6 @@
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.net.URL;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.security.Key;
import java.util.Arrays;
@@ -227,11 +226,7 @@ static Storage.BlobGetOption[] toGetOptions(BlobInfo blobInfo, BlobSourceOption.
* @throws StorageException upon failure
*/
public void downloadTo(Path path, BlobSourceOption... options) {
- try (OutputStream outputStream = Files.newOutputStream(path)) {
- downloadTo(outputStream, options);
- } catch (IOException e) {
- throw new StorageException(e);
- }
+ storage.downloadTo(getBlobId(), path, BlobSourceOption.toSourceOptions(this, options));
}
/**
@@ -241,7 +236,7 @@ public void downloadTo(Path path, BlobSourceOption... options) {
* @param options
*/
public void downloadTo(OutputStream outputStream, BlobSourceOption... options) {
- storage.downloadTo(getBlobId(), outputStream, options);
+ storage.downloadTo(getBlobId(), outputStream, BlobSourceOption.toSourceOptions(this, options));
}
/**
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java
index b6705c74b..d27de9016 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java
@@ -2677,20 +2677,41 @@ Blob createFrom(
/**
* Downloads the given blob to the given path using specified blob read options.
*
+ *
{@code
+ * String bucketName = "my-unique-bucket";
+ * String blobName = "my-blob-name";
+ * BlobId blobId = BlobId.of(bucketName, blobName);
+ * Path destination = Paths.get("my-blob-destination.txt");
+ * downloadTo(blobId, destination);
+ * // do stuff with destination
+ * }
+ *
* @param blob
* @param path
* @param options
+ * @throws StorageException upon failure
*/
- void downloadTo(BlobId blob, Path path, Blob.BlobSourceOption... options);
+ void downloadTo(BlobId blob, Path path, BlobSourceOption... options);
/**
* Downloads the given blob to the given output stream using specified blob read options.
*
+ * {@code
+ * String bucketName = "my-unique-bucket";
+ * String blobName = "my-blob-name";
+ * BlobId blobId = BlobId.of(bucketName, blobName);
+ * Path destination = Paths.get("my-blob-destination.txt");
+ * try (OutputStream outputStream = Files.newOutputStream(path)) {
+ * downloadTo(blob, outputStream);
+ * // do stuff with destination
+ * }
+ * }
+ *
* @param blob
* @param outputStream
* @param options
*/
- void downloadTo(BlobId blob, OutputStream outputStream, Blob.BlobSourceOption... options);
+ void downloadTo(BlobId blob, OutputStream outputStream, BlobSourceOption... options);
/**
* Creates a blob and returns a channel for writing its content. By default any MD5 and CRC32C
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java
index 21f89b91a..bf372c881 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java
@@ -548,7 +548,7 @@ public ReadChannel reader(BlobId blob, BlobSourceOption... options) {
}
@Override
- public void downloadTo(BlobId blob, Path path, Blob.BlobSourceOption... options) {
+ public void downloadTo(BlobId blob, Path path, BlobSourceOption... options) {
try (OutputStream outputStream = Files.newOutputStream(path)) {
downloadTo(blob, outputStream, options);
} catch (IOException e) {
@@ -557,7 +557,7 @@ public void downloadTo(BlobId blob, Path path, Blob.BlobSourceOption... options)
}
@Override
- public void downloadTo(BlobId blob, OutputStream outputStream, Blob.BlobSourceOption... options) {
+ public void downloadTo(BlobId blob, OutputStream outputStream, BlobSourceOption... options) {
final CountingOutputStream countingOutputStream = new CountingOutputStream(outputStream);
final StorageObject pb = blob.toPb();
final Map requestOptions = optionMap(blob, options);
diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
index bf55915f0..d5aa1b6d4 100644
--- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
+++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
@@ -885,14 +885,14 @@ public void testGetBlobRawInput() throws IOException {
Path rawInputGzippedFile = File.createTempFile("rawinputgzippedfile", ".txt").toPath();
storage.downloadTo(
- blobId, rawInputGzippedFile, Blob.BlobSourceOption.shouldReturnRawInputStream(true));
+ blobId, rawInputGzippedFile, Storage.BlobSourceOption.shouldReturnRawInputStream(true));
assertArrayEquals(
Files.readAllBytes(gzippedFile.toPath()), Files.readAllBytes(rawInputGzippedFile));
Path unzippedFile = File.createTempFile("unzippedfile", ".txt").toPath();
storage.downloadTo(
- blobId, unzippedFile, Blob.BlobSourceOption.shouldReturnRawInputStream(false));
+ blobId, unzippedFile, Storage.BlobSourceOption.shouldReturnRawInputStream(false));
assertArrayEquals("hello world".getBytes(), Files.readAllBytes(unzippedFile));
}