Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-munro committed Apr 15, 2022
1 parent 54805e9 commit 4936105
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions google-cloud-storage/clirr-ignored-differences.xml
Expand Up @@ -4,11 +4,11 @@
<difference>
<className>com/google/cloud/storage/Storage*</className>
<differenceType>7012</differenceType>
<method>* downloadTo(com.google.cloud.storage.BlobId, java.io.OutputStream, com.google.cloud.storage.Blob$BlobSourceOption[])</method>
<method>* downloadTo(com.google.cloud.storage.BlobId, java.io.OutputStream, com.google.cloud.storage.Storage$BlobSourceOption[])</method>
</difference>
<difference>
<className>com/google/cloud/storage/Storage*</className>
<differenceType>7012</differenceType>
<method>* downloadTo(com.google.cloud.storage.BlobId, java.nio.file.Path, com.google.cloud.storage.Blob$BlobSourceOption[])</method>
<method>* downloadTo(com.google.cloud.storage.BlobId, java.nio.file.Path, com.google.cloud.storage.Storage$BlobSourceOption[])</method>
</difference>
</differences>
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand Down
Expand Up @@ -2677,20 +2677,41 @@ Blob createFrom(
/**
* Downloads the given blob to the given path using specified blob read options.
*
* <pre>{@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
* }</pre>
*
* @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.
*
* <pre>{@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
* }
* }</pre>
*
* @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
Expand Down
Expand Up @@ -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) {
Expand All @@ -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<StorageRpc.Option, ?> requestOptions = optionMap(blob, options);
Expand Down
Expand Up @@ -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));
}
Expand Down

0 comments on commit 4936105

Please sign in to comment.