Skip to content

Commit 2c89979

Browse files
1 parent 8c2946d commit 2c89979

File tree

4 files changed

+25
-33
lines changed

4 files changed

+25
-33
lines changed

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-storage/tree/
389389
| Upload Kms Encrypted Object | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/UploadKmsEncryptedObject.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/UploadKmsEncryptedObject.java) |
390390
| Upload Object | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/UploadObject.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/UploadObject.java) |
391391
| Upload Object From Memory | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/UploadObjectFromMemory.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/UploadObjectFromMemory.java) |
392+
| Allow Divide And Conquer Download | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/transfermanager/AllowDivideAndConquerDownload.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/transfermanager/AllowDivideAndConquerDownload.java) |
393+
| Allow Parallel Composite Upload | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/transfermanager/AllowParallelCompositeUpload.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/transfermanager/AllowParallelCompositeUpload.java) |
392394
| Download Bucket | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/transfermanager/DownloadBucket.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/transfermanager/DownloadBucket.java) |
393395
| Download Many | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/transfermanager/DownloadMany.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/transfermanager/DownloadMany.java) |
394396
| Upload Directory | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/transfermanager/UploadDirectory.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/transfermanager/UploadDirectory.java) |

‎samples/snippets/src/main/java/com/example/storage/transfermanager/AllowDivideAndConquerDownload.java

+17-17
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@
2525
import com.google.cloud.storage.transfermanager.TransferManagerConfig;
2626
import java.nio.file.Path;
2727
import java.util.List;
28+
2829
class AllowDivideAndConquerDownload {
2930

30-
public static void divideAndConquerDownloadAllowed(List<BlobInfo> blobs,
31-
String bucketName, Path destinationDirectory) {
32-
TransferManager transferManager = TransferManagerConfig.newBuilder()
33-
.setAllowDivideAndConquer(true)
34-
.build()
35-
.getService();
36-
ParallelDownloadConfig parallelDownloadConfig = ParallelDownloadConfig.newBuilder()
37-
.setBucketName(bucketName)
38-
.setDownloadDirectory(destinationDirectory)
39-
.build();
40-
List<DownloadResult> results = transferManager
41-
.downloadBlobs(blobs, parallelDownloadConfig)
42-
.getDownloadResults();
31+
public static void divideAndConquerDownloadAllowed(
32+
List<BlobInfo> blobs, String bucketName, Path destinationDirectory) {
33+
TransferManager transferManager =
34+
TransferManagerConfig.newBuilder().setAllowDivideAndConquer(true).build().getService();
35+
ParallelDownloadConfig parallelDownloadConfig =
36+
ParallelDownloadConfig.newBuilder()
37+
.setBucketName(bucketName)
38+
.setDownloadDirectory(destinationDirectory)
39+
.build();
40+
List<DownloadResult> results =
41+
transferManager.downloadBlobs(blobs, parallelDownloadConfig).getDownloadResults();
4342

4443
for (DownloadResult result : results) {
45-
System.out.println("Download of " + result.getInput().getName()
46-
+ " completed with status "
47-
+ result.getStatus());
44+
System.out.println(
45+
"Download of "
46+
+ result.getInput().getName()
47+
+ " completed with status "
48+
+ result.getStatus());
4849
}
49-
5050
}
5151
}
5252
// [END storage_transfer_manager_download_chunks_concurrently]

‎samples/snippets/src/main/java/com/example/storage/transfermanager/AllowParallelCompositeUpload.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ class AllowParallelCompositeUpload {
3030

3131
public static void parallelCompositeUploadAllowed(String bucketName, List<Path> files)
3232
throws IOException {
33-
TransferManager transferManager = TransferManagerConfig
34-
.newBuilder()
35-
.setAllowDivideAndConquer(true)
36-
.build()
37-
.getService();
33+
TransferManager transferManager =
34+
TransferManagerConfig.newBuilder().setAllowDivideAndConquer(true).build().getService();
3835
ParallelUploadConfig parallelUploadConfig =
3936
ParallelUploadConfig.newBuilder().setBucketName(bucketName).build();
4037
List<UploadResult> results =

‎samples/snippets/src/test/java/com/example/storage/transfermanager/ITTransferManagerSamples.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,12 @@
2525
import com.google.cloud.storage.testing.RemoteStorageHelper;
2626
import com.google.cloud.testing.junit4.StdOutCaptureRule;
2727
import com.google.common.collect.ImmutableList;
28-
import com.google.common.collect.ImmutableSet;
2928
import java.io.File;
3029
import java.io.IOException;
31-
import java.nio.ByteBuffer;
32-
import java.nio.channels.SeekableByteChannel;
33-
import java.nio.file.Files;
34-
import java.nio.file.OpenOption;
3530
import java.nio.file.Path;
36-
import java.nio.file.StandardOpenOption;
3731
import java.util.Arrays;
3832
import java.util.Collections;
3933
import java.util.List;
40-
import java.util.Set;
4134
import org.junit.BeforeClass;
4235
import org.junit.Rule;
4336
import org.junit.Test;
@@ -125,16 +118,16 @@ public void downloadFiles() {
125118
@Test
126119
public void uploadAllowPCU() throws IOException {
127120
File tmpFile = tmpDirectory.newFile("fileDirUpload.txt");
128-
AllowParallelCompositeUpload
129-
.parallelCompositeUploadAllowed(BUCKET, Collections.singletonList(tmpFile.toPath()));
121+
AllowParallelCompositeUpload.parallelCompositeUploadAllowed(
122+
BUCKET, Collections.singletonList(tmpFile.toPath()));
130123
String snippetOutput = stdOutCaptureRule.getCapturedOutputAsUtf8String();
131124
assertThat(snippetOutput.contains("fileDirUpload.txt")).isTrue();
132125
}
133126

134127
@Test
135128
public void downloadAllowDivideAndConquer() {
136-
AllowDivideAndConquerDownload
137-
.divideAndConquerDownloadAllowed(blobs, BUCKET,tmp.getRoot().toPath());
129+
AllowDivideAndConquerDownload.divideAndConquerDownloadAllowed(
130+
blobs, BUCKET, tmp.getRoot().toPath());
138131
String snippetOutput = stdOutCaptureRule.getCapturedOutputAsUtf8String();
139132
assertThat(snippetOutput.contains("blob1")).isTrue();
140133
assertThat(snippetOutput.contains("blob2")).isTrue();

0 commit comments

Comments
 (0)