|
26 | 26 | import com.google.cloud.storage.Storage.BucketTargetOption;
|
27 | 27 | import com.google.cloud.storage.spi.StorageRpc;
|
28 | 28 | import com.google.common.base.Function;
|
| 29 | +import com.google.common.collect.ImmutableList; |
29 | 30 | import com.google.common.collect.Lists;
|
30 | 31 | import com.google.common.collect.Sets;
|
31 | 32 |
|
32 | 33 | import java.io.IOException;
|
33 | 34 | import java.io.InputStream;
|
34 | 35 | import java.io.ObjectInputStream;
|
35 | 36 | import java.io.Serializable;
|
36 |
| -import java.util.ArrayList; |
37 | 37 | import java.util.Arrays;
|
38 |
| -import java.util.Collections; |
39 | 38 | import java.util.List;
|
40 | 39 | import java.util.Objects;
|
41 | 40 | import java.util.Set;
|
@@ -609,19 +608,28 @@ public Blob get(String blob, BlobGetOption... options) {
|
609 | 608 | * @throws StorageException upon failure
|
610 | 609 | */
|
611 | 610 | 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()); |
625 | 633 | }
|
626 | 634 |
|
627 | 635 | /**
|
|
0 commit comments