本文整理了Java中com.google.cloud.storage.Bucket.requesterPays()
方法的一些代码示例,展示了Bucket.requesterPays()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bucket.requesterPays()
方法的具体详情如下:
包路径:com.google.cloud.storage.Bucket
类名称:Bucket
方法名:requesterPays
暂无
代码示例来源:origin: googleapis/google-cloud-java
/**
* @param bucketName the name of the bucket to check
* @return whether requester pays is enabled for that bucket
*/
public boolean requesterPays(String bucketName) {
initStorage();
try {
// instead of true/false, this method returns true/null.
Boolean isRP = storage.get(bucketName).requesterPays();
return isRP != null && isRP.booleanValue();
} catch (StorageException ex) {
if (ex.getCode() == 400 && ex.getMessage().contains("Bucket is requester pays")) {
return true;
}
throw ex;
}
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of retrieving Requester pays status on a bucket. */
public Bucket getRequesterPaysStatus(String bucketName) throws StorageException {
// [START get_requester_pays_status]
// Instantiate a Google Cloud Storage client
Storage storage = StorageOptions.getDefaultInstance().getService();
// The name of the bucket to retrieve requester-pays status, eg. "my-bucket"
// String bucketName = "my-bucket"
// Retrieve the bucket, throws StorageException on failure
Bucket bucket = storage.get(bucketName, Storage.BucketGetOption.fields(BucketField.BILLING));
System.out.println("Requester pays status : " + bucket.requesterPays());
// [END get_requester_pays_status]
return bucket;
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of enabling Requester pays on a bucket. */
public Bucket enableRequesterPays(String bucketName) throws StorageException {
// [START enable_requester_pays]
// Instantiate a Google Cloud Storage client
Storage storage = StorageOptions.getDefaultInstance().getService();
// The name of the existing bucket to enable requester-paying for, e.g. "my-bucket"
// String bucketName = "my-bucket"
BucketInfo bucketInfo = BucketInfo.newBuilder(bucketName).setRequesterPays(true).build();
// Update the bucket, throws StorageException on failure
Bucket bucket = storage.update(bucketInfo);
System.out.println("Requester pay status for " + bucketName + ": " + bucket.requesterPays());
// [END enable_requester_pays]
return bucket;
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of disabling Requester pays on a bucket. */
public Bucket disableRequesterPays(String bucketName) {
// [START disable_requester_pays]
// Instantiate a Google Cloud Storage client
Storage storage = StorageOptions.getDefaultInstance().getService();
// The name of the bucket to disable requester-paying for, e.g. "my-bucket"
// String bucketName = "my-bucket"
BucketInfo bucketInfo = BucketInfo.newBuilder(bucketName).setRequesterPays(false).build();
// Update the bucket, throws StorageException on failure
Bucket bucket = storage.update(bucketInfo);
System.out.println("Requester pays status for " + bucketName + ": " + bucket.requesterPays());
// [END disable_requester_pays]
return bucket;
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testUpdateBucketRequesterPays() {
Bucket remoteBucket = storage.get(BUCKET, Storage.BucketGetOption.fields(BucketField.ID));
assertNull(remoteBucket.requesterPays());
remoteBucket = remoteBucket.toBuilder().setRequesterPays(true).build();
Bucket updatedBucket = storage.update(remoteBucket);
assertTrue(updatedBucket.requesterPays());
String projectId = remoteStorageHelper.getOptions().getProjectId();
Bucket.BlobTargetOption option = Bucket.BlobTargetOption.userProject(projectId);
String blobName = "test-create-empty-blob-requester-pays";
Blob remoteBlob = updatedBucket.create(blobName, BLOB_BYTE_CONTENT, option);
assertNotNull(remoteBlob);
byte[] readBytes = storage.readAllBytes(BUCKET, blobName);
assertArrayEquals(BLOB_BYTE_CONTENT, readBytes);
}
代码示例来源:origin: googleapis/google-cloud-java
private void testBucketPolicyRequesterPays(boolean requesterPays) {
if (requesterPays) {
Bucket remoteBucket = storage.get(BUCKET, Storage.BucketGetOption.fields(BucketField.ID));
assertNull(remoteBucket.requesterPays());
remoteBucket = remoteBucket.toBuilder().setRequesterPays(true).build();
Bucket updatedBucket = storage.update(remoteBucket);
assertTrue(updatedBucket.requesterPays());
代码示例来源:origin: googleapis/google-cloud-java
assertNull(remoteBucket.requesterPays());
remoteBucket = remoteBucket.toBuilder().setRequesterPays(true).build();
Bucket updatedBucket = storage.update(remoteBucket);
assertTrue(updatedBucket.requesterPays());
try {
storage.list(
代码示例来源:origin: googleapis/google-cloud-java
private void testBucketAclRequesterPays(boolean requesterPays) {
if (requesterPays) {
Bucket remoteBucket = storage.get(BUCKET, Storage.BucketGetOption.fields(BucketField.ID));
assertNull(remoteBucket.requesterPays());
remoteBucket = remoteBucket.toBuilder().setRequesterPays(true).build();
Bucket updatedBucket = storage.update(remoteBucket);
assertTrue(updatedBucket.requesterPays());
}
String projectId = remoteStorageHelper.getOptions().getProjectId();
Storage.BucketSourceOption[] bucketOptions =
requesterPays
? new Storage.BucketSourceOption[] {Storage.BucketSourceOption.userProject(projectId)}
: new Storage.BucketSourceOption[] {};
assertNull(storage.getAcl(BUCKET, User.ofAllAuthenticatedUsers(), bucketOptions));
assertFalse(storage.deleteAcl(BUCKET, User.ofAllAuthenticatedUsers(), bucketOptions));
Acl acl = Acl.of(User.ofAllAuthenticatedUsers(), Role.READER);
assertNotNull(storage.createAcl(BUCKET, acl, bucketOptions));
Acl updatedAcl =
storage.updateAcl(BUCKET, acl.toBuilder().setRole(Role.WRITER).build(), bucketOptions);
assertEquals(Role.WRITER, updatedAcl.getRole());
Set<Acl> acls = new HashSet<>();
acls.addAll(storage.listAcls(BUCKET, bucketOptions));
assertTrue(acls.contains(updatedAcl));
assertTrue(storage.deleteAcl(BUCKET, User.ofAllAuthenticatedUsers(), bucketOptions));
assertNull(storage.getAcl(BUCKET, User.ofAllAuthenticatedUsers(), bucketOptions));
}
代码示例来源:origin: googleapis/google-cloud-java
assertEquals(VERSIONING_ENABLED, bucket.versioningEnabled());
assertEquals(BUCKET_LABELS, bucket.getLabels());
assertEquals(REQUESTER_PAYS, bucket.requesterPays());
assertEquals(DEFAULT_KMS_KEY_NAME, bucket.getDefaultKmsKeyName());
assertEquals(DEFAULT_EVENT_BASED_HOLD, bucket.getDefaultEventBasedHold());
内容来源于网络,如有侵权,请联系作者删除!