Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e104bde

Browse files
committed
Refactor storage batches to use StorageBatchRequest and BatchResult
1 parent e213176 commit e104bde

18 files changed

+1148
-1078
lines changed

gcloud-java-storage/src/main/java/com/google/cloud/storage/BatchRequest.java

Lines changed: 0 additions & 131 deletions
This file was deleted.

gcloud-java-storage/src/main/java/com/google/cloud/storage/BatchResponse.java

Lines changed: 0 additions & 162 deletions
This file was deleted.

gcloud-java-storage/src/main/java/com/google/cloud/storage/Bucket.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@
2626
import com.google.cloud.storage.Storage.BucketTargetOption;
2727
import com.google.cloud.storage.spi.StorageRpc;
2828
import com.google.common.base.Function;
29+
import com.google.common.collect.ImmutableList;
2930
import com.google.common.collect.Lists;
3031
import com.google.common.collect.Sets;
3132

3233
import java.io.IOException;
3334
import java.io.InputStream;
3435
import java.io.ObjectInputStream;
3536
import java.io.Serializable;
36-
import java.util.ArrayList;
3737
import java.util.Arrays;
38-
import java.util.Collections;
3938
import java.util.List;
4039
import java.util.Objects;
4140
import java.util.Set;
@@ -609,19 +608,28 @@ public Blob get(String blob, BlobGetOption... options) {
609608
* @throws StorageException upon failure
610609
*/
611610
public List<Blob> get(String blobName1, String blobName2, String... blobNames) {
612-
BatchRequest.Builder batch = BatchRequest.builder();
613-
batch.get(name(), blobName1);
614-
batch.get(name(), blobName2);
615-
for (String name : blobNames) {
616-
batch.get(name(), name);
617-
}
618-
List<Blob> blobs = new ArrayList<>(blobNames.length);
619-
BatchResponse response = storage.submit(batch.build());
620-
for (BatchResponse.Result<Blob> result : response.gets()) {
621-
BlobInfo blobInfo = result.get();
622-
blobs.add(blobInfo != null ? new Blob(storage, new BlobInfo.BuilderImpl(blobInfo)) : null);
623-
}
624-
return Collections.unmodifiableList(blobs);
611+
List<BlobId> blobIds = Lists.newArrayListWithCapacity(blobNames.length + 2);
612+
blobIds.add(BlobId.of(name(), blobName1));
613+
blobIds.add(BlobId.of(name(), blobName2));
614+
for (String blobName : blobNames) {
615+
blobIds.add(BlobId.of(name(), blobName));
616+
}
617+
return storage.get(blobIds);
618+
}
619+
620+
/**
621+
* Returns a list of requested blobs in this bucket. Blobs that do not exist are null.
622+
*
623+
* @param blobNames blobs to get
624+
* @return an immutable list of {@code Blob} objects
625+
* @throws StorageException upon failure
626+
*/
627+
public List<Blob> get(Iterable<String> blobNames) {
628+
ImmutableList.Builder<BlobId> builder = ImmutableList.builder();
629+
for (String blobName : blobNames) {
630+
builder.add(BlobId.of(name(), blobName));
631+
}
632+
return storage.get(builder.build());
625633
}
626634

627635
/**

0 commit comments

Comments
 (0)