|
26 | 26 | import com.google.cloud.storage.Blob; |
27 | 27 | import com.google.cloud.storage.BlobId; |
28 | 28 | import com.google.cloud.storage.BlobInfo; |
| 29 | +import com.google.cloud.storage.Bucket; |
29 | 30 | import com.google.cloud.storage.CopyWriter; |
30 | 31 | import com.google.cloud.storage.Storage; |
31 | 32 | import com.google.cloud.storage.Storage.BlobGetOption; |
|
34 | 35 | import com.google.cloud.storage.StorageOptions; |
35 | 36 | import com.google.common.annotations.VisibleForTesting; |
36 | 37 | import com.google.common.base.MoreObjects; |
37 | | -import com.google.common.base.Strings; |
38 | 38 | import com.google.common.collect.AbstractIterator; |
39 | 39 | import com.google.common.net.UrlEscapers; |
40 | 40 | import com.google.common.primitives.Ints; |
@@ -915,6 +915,35 @@ public CloudStorageFileSystemProvider withNoUserProject() { |
915 | 915 | return new CloudStorageFileSystemProvider("", this.storageOptions); |
916 | 916 | } |
917 | 917 |
|
| 918 | + /** |
| 919 | + * Returns the project that is assigned to this provider. |
| 920 | + */ |
| 921 | + public String getProject() { |
| 922 | + initStorage(); |
| 923 | + return storage.getOptions().getProjectId(); |
| 924 | + } |
| 925 | + |
| 926 | + /** |
| 927 | + * Lists the project's buckets. But use the one in CloudStorageFileSystem. |
| 928 | + * |
| 929 | + * <p>Example of listing buckets, specifying the page size and a name prefix. |
| 930 | + * <pre> {@code |
| 931 | + * String prefix = "bucket_"; |
| 932 | + * Page<Bucket> buckets = provider.listBuckets(BucketListOption.prefix(prefix)); |
| 933 | + * Iterator<Bucket> bucketIterator = buckets.iterateAll(); |
| 934 | + * while (bucketIterator.hasNext()) { |
| 935 | + * Bucket bucket = bucketIterator.next(); |
| 936 | + * // do something with the bucket |
| 937 | + * } |
| 938 | + * }</pre> |
| 939 | + * |
| 940 | + * @throws StorageException upon failure |
| 941 | + */ |
| 942 | + Page<Bucket> listBuckets(Storage.BucketListOption... options) { |
| 943 | + initStorage(); |
| 944 | + return storage.list(options); |
| 945 | + } |
| 946 | + |
918 | 947 | private IOException asIoException(StorageException oops) { |
919 | 948 | // RPC API can only throw StorageException, but CloudStorageFileSystemProvider |
920 | 949 | // can only throw IOException. Square peg, round hole. |
|
0 commit comments