Skip to content

Commit e46b57c

Browse files
author
Frank Natividad
committed
Update download requester pays sample
1 parent 8f77925 commit e46b57c

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import java.net.URL;
6767
import java.nio.ByteBuffer;
6868
import java.nio.file.Path;
69+
import java.nio.file.Paths;
6970
import java.util.HashMap;
7071
import java.util.LinkedList;
7172
import java.util.List;
@@ -1125,20 +1126,19 @@ public void downloadFileUsingRequesterPays(String projectId, String bucketName,
11251126
// String srcFilename = "file.txt";
11261127

11271128
// The path to which the file should be downloaded
1128-
// String destFilePath = "/local/path/to/file.txt";
1129+
// Path destFilePath = Paths.get("/local/path/to/file.txt");
11291130

11301131
// Instantiate a Google Cloud Storage client
11311132
Storage storage = StorageOptions.getDefaultInstance().getService();
11321133

1134+
// Set billing project
11331135
BlobSourceOption option = BlobSourceOption.userProject(projectId);
11341136

1135-
// read blob in a single pass
1136-
byte[] readBytes = storage.readAllBytes(bucketName, srcFilename, option);
1137+
// Get specific file from specified bucket
1138+
Blob blob = BlobId.of(bucketName, srcFilename);
11371139

1138-
// write out to file
1139-
PrintStream out = new PrintStream(new FileOutputStream(destFilePath.toFile()));
1140-
out.write(readBytes);
1141-
out.close();
1140+
// Download file to specified path
1141+
blob.downloatTo(destFilePath, option);
11421142
// [END storage_download_file_requester_pays]
11431143
}
11441144
}

0 commit comments

Comments
 (0)