|
64 | 64 | import java.net.URL; |
65 | 65 | import java.nio.ByteBuffer; |
66 | 66 | import java.nio.file.Path; |
67 | | -import java.util.Date; |
68 | | -import java.util.HashMap; |
69 | | -import java.util.LinkedList; |
70 | | -import java.util.List; |
71 | | -import java.util.Map; |
| 67 | +import java.util.*; |
72 | 68 | import java.util.concurrent.TimeUnit; |
73 | 69 |
|
74 | 70 | /** This class contains a number of snippets for the {@link Storage} interface. */ |
@@ -1126,6 +1122,44 @@ public Bucket setDefaultKmsKey(String bucketName, String kmsKeyName) throws Stor |
1126 | 1122 | return bucket; |
1127 | 1123 | } |
1128 | 1124 |
|
| 1125 | + /** Example of displaying Bucket metadata */ |
| 1126 | + public void getBucketMetadata(String bucketName) throws StorageException { |
| 1127 | + // [START storage_get_bucket_metadata] |
| 1128 | + Storage storage = StorageOptions.getDefaultInstance().getService(); |
| 1129 | + |
| 1130 | + // The name of a bucket, e.g. "my-bucket" |
| 1131 | + // String bucketName = "my-bucket"; |
| 1132 | + |
| 1133 | + // Select all fields |
| 1134 | + // Fields can be selected individually e.g. Storage.BucketField.NAME |
| 1135 | + Bucket bucket = storage.get(bucketName, BucketGetOption.fields(Storage.BucketField.values())); |
| 1136 | + |
| 1137 | + // Print bucket metadata |
| 1138 | + System.out.println("BucketName: " + bucket.getName()); |
| 1139 | + System.out.println("DefaultEventBasedHold: " + bucket.getDefaultEventBasedHold()); |
| 1140 | + System.out.println("DefaultKmsKeyName: " + bucket.getDefaultKmsKeyName()); |
| 1141 | + System.out.println("Id: " + bucket.getGeneratedId()); |
| 1142 | + System.out.println("IndexPage: " + bucket.getIndexPage()); |
| 1143 | + System.out.println("Location: " + bucket.getLocation()); |
| 1144 | + System.out.println("LocationType: " + bucket.getLocationType()); |
| 1145 | + System.out.println("Metageneration: " + bucket.getMetageneration()); |
| 1146 | + System.out.println("NotFoundPage: " + bucket.getNotFoundPage()); |
| 1147 | + System.out.println("RetentionEffectiveTime: " + bucket.getRetentionEffectiveTime()); |
| 1148 | + System.out.println("RetentionPeriod: " + bucket.getRetentionPeriod()); |
| 1149 | + System.out.println("RetentionPolicyIsLocked: " + bucket.retentionPolicyIsLocked()); |
| 1150 | + System.out.println("RequesterPays: " + bucket.requesterPays()); |
| 1151 | + System.out.println("SelfLink: " + bucket.getSelfLink()); |
| 1152 | + System.out.println("StorageClass: " + bucket.getStorageClass().name()); |
| 1153 | + System.out.println("TimeCreated: " + bucket.getCreateTime()); |
| 1154 | + System.out.println("VersioningEnabled: " + bucket.versioningEnabled()); |
| 1155 | + if (bucket.getLabels() != null) { |
| 1156 | + System.out.println("\n\n\nLabels:"); |
| 1157 | + for (Map.Entry<String, String> label : bucket.getLabels().entrySet()) { |
| 1158 | + System.out.println(label.getKey() + "=" + label.getValue()); |
| 1159 | + } |
| 1160 | + } |
| 1161 | + // [END storage_get_bucket_metadata] |
| 1162 | + } |
1129 | 1163 | /** Example of displaying Blob metadata */ |
1130 | 1164 | public void getBlobMetadata(String bucketName, String blobName) throws StorageException { |
1131 | 1165 | // [START storage_get_metadata] |
|
0 commit comments