本文整理了Java中com.google.cloud.storage.Bucket.getRetentionEffectiveTime()
方法的一些代码示例,展示了Bucket.getRetentionEffectiveTime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bucket.getRetentionEffectiveTime()
方法的具体详情如下:
包路径:com.google.cloud.storage.Bucket
类名称:Bucket
方法名:getRetentionEffectiveTime
暂无
代码示例来源:origin: googleapis/google-cloud-java
/** Example of how to get a bucket's retention policy */
public Bucket getRetentionPolicy(String bucketName) throws StorageException {
// [START storage_get_retention_policy]
// Instantiate a Google Cloud Storage client
Storage storage = StorageOptions.getDefaultInstance().getService();
// The name of a bucket, e.g. "my-bucket"
// String bucketName = "my-bucket";
Bucket bucket = storage.get(bucketName, BucketGetOption.fields(BucketField.RETENTION_POLICY));
System.out.println("Retention Policy for " + bucketName);
System.out.println("Retention Period: " + bucket.getRetentionPeriod());
if (bucket.retentionPolicyIsLocked() != null && bucket.retentionPolicyIsLocked()) {
System.out.println("Retention Policy is locked");
}
if (bucket.getRetentionEffectiveTime() != null) {
System.out.println("Effective Time: " + new Date(bucket.getRetentionEffectiveTime()));
}
// [END storage_get_retention_policy]
return bucket;
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of how to lock a bucket retention policy */
public Bucket lockRetentionPolicy(String bucketName) throws StorageException {
// [START storage_lock_retention_policy]
// Instantiate a Google Cloud Storage client
Storage storage = StorageOptions.getDefaultInstance().getService();
// The name of a bucket, e.g. "my-bucket"
// String bucketName = "my-bucket";
Bucket bucket =
storage.get(bucketName, Storage.BucketGetOption.fields(BucketField.METAGENERATION));
Bucket lockedBucket =
bucket.lockRetentionPolicy(Storage.BucketTargetOption.metagenerationMatch());
System.out.println("Retention period for " + bucketName + " is now locked");
System.out.println(
"Retention policy effective as of " + new Date(lockedBucket.getRetentionEffectiveTime()));
// [END storage_lock_retention_policy]
return lockedBucket;
}
代码示例来源:origin: googleapis/google-cloud-java
try {
assertNull(remoteBucket.retentionPolicyIsLocked());
assertNotNull(remoteBucket.getRetentionEffectiveTime());
assertNotNull(remoteBucket.getMetageneration());
if (requesterPays) {
assertNotNull(remoteBucket.getRetentionEffectiveTime());
} finally {
RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS);
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testRetentionPolicyNoLock() throws ExecutionException, InterruptedException {
String bucketName = RemoteStorageHelper.generateBucketName();
Bucket remoteBucket =
storage.create(
BucketInfo.newBuilder(bucketName).setRetentionPeriod(RETENTION_PERIOD).build());
try {
assertEquals(RETENTION_PERIOD, remoteBucket.getRetentionPeriod());
assertNotNull(remoteBucket.getRetentionEffectiveTime());
assertNull(remoteBucket.retentionPolicyIsLocked());
remoteBucket =
storage.get(bucketName, Storage.BucketGetOption.fields(BucketField.RETENTION_POLICY));
assertEquals(RETENTION_PERIOD, remoteBucket.getRetentionPeriod());
assertNotNull(remoteBucket.getRetentionEffectiveTime());
assertNull(remoteBucket.retentionPolicyIsLocked());
String blobName = "test-create-with-retention-policy-hold";
BlobInfo blobInfo = BlobInfo.newBuilder(bucketName, blobName).build();
Blob remoteBlob = storage.create(blobInfo);
assertNotNull(remoteBlob.getRetentionExpirationTime());
remoteBucket = remoteBucket.toBuilder().setRetentionPeriod(null).build().update();
assertNull(remoteBucket.getRetentionPeriod());
remoteBucket = remoteBucket.toBuilder().setRetentionPeriod(null).build().update();
assertNull(remoteBucket.getRetentionPeriod());
} finally {
RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS);
}
}
代码示例来源:origin: googleapis/google-cloud-java
assertEquals(DEFAULT_KMS_KEY_NAME, bucket.getDefaultKmsKeyName());
assertEquals(DEFAULT_EVENT_BASED_HOLD, bucket.getDefaultEventBasedHold());
assertEquals(RETENTION_EFFECTIVE_TIME, bucket.getRetentionEffectiveTime());
assertEquals(RETENTION_PERIOD, bucket.getRetentionPeriod());
assertEquals(RETENTION_POLICY_IS_LOCKED, bucket.retentionPolicyIsLocked());
内容来源于网络,如有侵权,请联系作者删除!