com.google.api.services.storage.model.Bucket类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(208)

本文整理了Java中com.google.api.services.storage.model.Bucket类的一些代码示例,展示了Bucket类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bucket类的具体详情如下:
包路径:com.google.api.services.storage.model.Bucket
类名称:Bucket

Bucket介绍

暂无

代码示例

代码示例来源:origin: googleapis/google-cloud-java

com.google.api.services.storage.model.Bucket toPb() {
 com.google.api.services.storage.model.Bucket bucketPb =
   new com.google.api.services.storage.model.Bucket();
 bucketPb.setId(generatedId);
 bucketPb.setName(name);
 bucketPb.setEtag(etag);
 if (createTime != null) {
  bucketPb.setTimeCreated(new DateTime(createTime));
  bucketPb.setMetageneration(metageneration);
  bucketPb.setLocation(location);
  bucketPb.setStorageClass(storageClass.toString());
  bucketPb.setCors(transform(cors, Cors.TO_PB_FUNCTION));
  bucketPb.setAcl(
    transform(
      acl,
  bucketPb.setDefaultObjectAcl(
    transform(
      defaultAcl,
  bucketPb.setOwner(new Owner().setEntity(owner.toPb()));
 bucketPb.setSelfLink(selfLink);
 if (versioningEnabled != null) {
  bucketPb.setVersioning(new Versioning().setEnabled(versioningEnabled));

代码示例来源:origin: googleapis/google-cloud-java

static BucketInfo fromPb(com.google.api.services.storage.model.Bucket bucketPb) {
 Builder builder = new BuilderImpl(bucketPb.getName());
 if (bucketPb.getId() != null) {
  builder.setGeneratedId(bucketPb.getId());
 if (bucketPb.getEtag() != null) {
  builder.setEtag(bucketPb.getEtag());
 if (bucketPb.getMetageneration() != null) {
  builder.setMetageneration(bucketPb.getMetageneration());
 if (bucketPb.getSelfLink() != null) {
  builder.setSelfLink(bucketPb.getSelfLink());
 if (bucketPb.getTimeCreated() != null) {
  builder.setCreateTime(bucketPb.getTimeCreated().getValue());
 if (bucketPb.getLocation() != null) {
  builder.setLocation(bucketPb.getLocation());
 if (bucketPb.getStorageClass() != null) {
  builder.setStorageClass(StorageClass.valueOf(bucketPb.getStorageClass()));
 if (bucketPb.getCors() != null) {
  builder.setCors(transform(bucketPb.getCors(), Cors.FROM_PB_FUNCTION));
 if (bucketPb.getAcl() != null) {
  builder.setAcl(
    transform(
      bucketPb.getAcl(),

代码示例来源:origin: google/google-api-java-client-samples

static void show(Bucket bucket) {
 System.out.println("name: " + bucket.getName());
 System.out.println("location: " + bucket.getLocation());
 System.out.println("timeCreated: " + bucket.getTimeCreated());
 System.out.println("owner: " + bucket.getOwner());
 System.out.println("acl: " + bucket.getAcl());
}

代码示例来源:origin: spinnaker/kayenta

Bucket bucket = new Bucket().setName(bucketName).setVersioning(versioning);
 bucket.setLocation(bucketLocation);

代码示例来源:origin: com.google.gcloud/gcloud-java-storage

com.google.api.services.storage.model.Bucket toPb() {
 com.google.api.services.storage.model.Bucket bucketPb =
   new com.google.api.services.storage.model.Bucket();
 bucketPb.setId(generatedId);
 bucketPb.setName(name);
 bucketPb.setEtag(etag);
 if (createTime != null) {
  bucketPb.setTimeCreated(new DateTime(createTime));
  bucketPb.setMetageneration(metageneration);
  bucketPb.setLocation(location);
  bucketPb.setStorageClass(storageClass);
  bucketPb.setCors(transform(cors, Cors.TO_PB_FUNCTION));
  bucketPb.setAcl(transform(acl, new Function<Acl, BucketAccessControl>() {
   @Override
   public BucketAccessControl apply(Acl acl) {
  bucketPb.setDefaultObjectAcl(transform(defaultAcl, new Function<Acl, ObjectAccessControl>() {
   @Override
   public ObjectAccessControl apply(Acl acl) {
  bucketPb.setOwner(new Owner().setEntity(owner.toPb()));
 bucketPb.setSelfLink(selfLink);
 if (versioningEnabled != null) {
  bucketPb.setVersioning(new Versioning().setEnabled(versioningEnabled));

代码示例来源:origin: google/google-api-java-client-samples

public static void main(String[] args) throws Exception {
 HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
 JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
 Credential credential = CredentialsProvider.authorize(httpTransport, jsonFactory);
 Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential)
   .setApplicationName("Google-BucketsInsertExample/1.0").build();
 createInProject(storage, PROJECT_NAME, new Bucket().setName(BUCKET_NAME)
   .setLocation(BUCKET_LOCATION));
}

代码示例来源:origin: com.google.gcloud/gcloud-java-storage

static BucketInfo fromPb(com.google.api.services.storage.model.Bucket bucketPb) {
 Builder builder = new BuilderImpl(bucketPb.getName());
 if (bucketPb.getId() != null) {
  builder.generatedId(bucketPb.getId());
 if (bucketPb.getEtag() != null) {
  builder.etag(bucketPb.getEtag());
 if (bucketPb.getMetageneration() != null) {
  builder.metageneration(bucketPb.getMetageneration());
 if (bucketPb.getSelfLink() != null) {
  builder.selfLink(bucketPb.getSelfLink());
 if (bucketPb.getTimeCreated() != null) {
  builder.createTime(bucketPb.getTimeCreated().getValue());
 if (bucketPb.getLocation() != null) {
  builder.location(bucketPb.getLocation());
 if (bucketPb.getStorageClass() != null) {
  builder.storageClass(bucketPb.getStorageClass());
 if (bucketPb.getCors() != null) {
  builder.cors(transform(bucketPb.getCors(), Cors.FROM_PB_FUNCTION));
 if (bucketPb.getAcl() != null) {
  builder.acl(transform(bucketPb.getAcl(), new Function<BucketAccessControl, Acl>() {
   @Override
   public Acl apply(BucketAccessControl bucketAccessControl) {

代码示例来源:origin: apache/ignite

Bucket newBucket = new Bucket();
newBucket.setName(bucketName);

代码示例来源:origin: com.google.cloud.bigdataoss/gcsio

/**
 * See {@link GoogleCloudStorage#create(String, CreateBucketOptions)} for details about expected
 * behavior.
 */
@Override
public void create(String bucketName, CreateBucketOptions options) throws IOException {
 logger.atFine().log("create(%s)", bucketName);
 Preconditions.checkArgument(
   !Strings.isNullOrEmpty(bucketName), "bucketName must not be null or empty");
 checkNotNull(options, "options must not be null");
 checkNotNull(storageOptions.getProjectId(), "projectId must not be null");
 Bucket bucket = new Bucket();
 bucket.setName(bucketName);
 bucket.setLocation(options.getLocation());
 bucket.setStorageClass(options.getStorageClass());
 Storage.Buckets.Insert insertBucket =
   configureRequest(gcs.buckets().insert(storageOptions.getProjectId(), bucket), bucketName);
 // TODO(user): To match the behavior of throwing FileNotFoundException for 404, we probably
 // want to throw org.apache.commons.io.FileExistsException for 409 here.
 try {
  ResilientOperation.retry(
    ResilientOperation.getGoogleRequestCallable(insertBucket),
    backOffFactory.newBackOff(),
    rateLimitedRetryDeterminer,
    IOException.class,
    sleeper);
 } catch (InterruptedException e) {
  throw new IOException(e); // From sleep
 }
}

代码示例来源:origin: com.google.cloud.bigdataoss/gcsio

/** Helper for converting a StorageResourceId + Bucket into a GoogleCloudStorageItemInfo. */
public static GoogleCloudStorageItemInfo createItemInfoForBucket(
  StorageResourceId resourceId, Bucket bucket) {
 Preconditions.checkArgument(resourceId != null, "resourceId must not be null");
 Preconditions.checkArgument(bucket != null, "bucket must not be null");
 Preconditions.checkArgument(
   resourceId.isBucket(), "resourceId must be a Bucket. resourceId: %s", resourceId);
 Preconditions.checkArgument(
   resourceId.getBucketName().equals(bucket.getName()),
   "resourceId.getBucketName() must equal bucket.getName(): '%s' vs '%s'",
   resourceId.getBucketName(), bucket.getName());
 // For buckets, size is 0.
 return new GoogleCloudStorageItemInfo(resourceId, bucket.getTimeCreated().getValue(),
   0, bucket.getLocation(), bucket.getStorageClass());
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public Bucket lockRetentionPolicy(Bucket bucket, Map<Option, ?> options) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_LOCK_RETENTION_POLICY);
 Scope scope = tracer.withSpan(span);
 try {
  return storage
    .buckets()
    .lockRetentionPolicy(bucket.getName(), Option.IF_METAGENERATION_MATCH.getLong(options))
    .setUserProject(Option.USER_PROJECT.getString(options))
    .execute();
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  throw translate(ex);
 } finally {
  scope.close();
  span.end();
 }
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-google-cloud-platform-core

@Test
public void testCreateBucket() throws IOException {
 GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
 GcsUtil gcsUtil = pipelineOptions.getGcsUtil();
 Storage.Buckets mockStorageObjects = Mockito.mock(Storage.Buckets.class);
 Storage mockStorage = Mockito.mock(Storage.class);
 gcsUtil.setStorageClient(mockStorage);
 Storage.Buckets.Insert mockStorageInsert = Mockito.mock(Storage.Buckets.Insert.class);
 BackOff mockBackOff = BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff());
 when(mockStorage.buckets()).thenReturn(mockStorageObjects);
 when(mockStorageObjects.insert(any(String.class), any(Bucket.class)))
   .thenReturn(mockStorageInsert);
 when(mockStorageInsert.execute())
   .thenThrow(new SocketTimeoutException("SocketException"))
   .thenReturn(new Bucket());
 gcsUtil.createBucket("a", new Bucket(), mockBackOff, new FastNanoClockAndSleeper());
}

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

System.out.println("location: " + bucket.getLocation());
System.out.println("timeCreated: " + bucket.getTimeCreated());
System.out.println("owner: " + bucket.getOwner());

代码示例来源:origin: stackoverflow.com

List<Bucket> buckets=s3.listBuckets();
for(Bucket bucket:buckets){
  Log.e("Bucket ","Name "+bucket.getName()+" Owner "+bucket.getOwner()+ " Date " + bucket.getCreationDate());

代码示例来源:origin: spinnaker/halyard

private static void ensureBucketExistsAndVersioned(Storage storage, String projectId, String locationId, String bucketId) {
 Bucket bucket;
 try {
  bucket = storage.buckets().get(bucketId).execute();
 } catch (GoogleJsonResponseException e) {
  if (e.getStatusCode() == 404) {
   bucket = createBucket(storage, projectId, locationId, bucketId);
  } else {
   throw new RuntimeException("Can't retrieve bucket", e);
  }
 } catch (IOException e) {
  throw new RuntimeException("Can't retrieve bucket", e);
 }
 if (!bucket.getVersioning().getEnabled()) {
  throw new RuntimeException("Bucket " + bucketId + " is not versioned. Aborting.");
 }
}

代码示例来源:origin: spinnaker/halyard

private static Bucket createBucket(Storage storage, String projectId, String locationId, String bucketId) {
 try {
  Bucket bucket = new Bucket()
    .setLocation(locationId)
    .setName(bucketId)
    .setVersioning(new Bucket.Versioning().setEnabled(true));
  if (!StringUtils.isEmpty(locationId)) {
   bucket.setLocation(locationId);
  }
  return storage.buckets().insert(projectId, bucket).execute();
 } catch (IOException e) {
  throw new RuntimeException("Unable to create bucket", e);
 }
}

代码示例来源:origin: google/google-api-java-client-samples

new Bucket().setName(settings.getBucket()).setLocation("US"));

代码示例来源:origin: GoogleCloudPlatform/pubsub

/**
 * Creates the storage bucket used by the load test.
 */
private void createStorageBucket() throws IOException {
 try {
  storage.buckets().insert(projectName, new Bucket()
    .setName(projectName + "-cloud-pubsub-loadtest")).execute();
 } catch (GoogleJsonResponseException e) {
  if (e.getStatusCode() != ALREADY_EXISTS) {
   throw e;
  }
 }
}

代码示例来源:origin: com.google.cloud.bigdataoss/gcsio

/**
 * See {@link GoogleCloudStorage#listBucketInfo()} for details about expected behavior.
 */
@Override
public List<GoogleCloudStorageItemInfo> listBucketInfo()
  throws IOException {
 logger.atFine().log("listBucketInfo()");
 List<Bucket> allBuckets = listBucketsInternal();
 List<GoogleCloudStorageItemInfo> bucketInfos = new ArrayList<>(allBuckets.size());
 for (Bucket bucket : allBuckets) {
  bucketInfos.add(new GoogleCloudStorageItemInfo(
    new StorageResourceId(bucket.getName()), bucket.getTimeCreated().getValue(), 0,
    bucket.getLocation(), bucket.getStorageClass()));
 }
 return bucketInfos;
}

代码示例来源:origin: googleapis/google-cloud-java

@Override
public boolean delete(Bucket bucket, Map<Option, ?> options) {
 Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_DELETE_BUCKET);
 Scope scope = tracer.withSpan(span);
 try {
  storage
    .buckets()
    .delete(bucket.getName())
    .setIfMetagenerationMatch(Option.IF_METAGENERATION_MATCH.getLong(options))
    .setIfMetagenerationNotMatch(Option.IF_METAGENERATION_NOT_MATCH.getLong(options))
    .setUserProject(Option.USER_PROJECT.getString(options))
    .execute();
  return true;
 } catch (IOException ex) {
  span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage()));
  StorageException serviceException = translate(ex);
  if (serviceException.getCode() == HTTP_NOT_FOUND) {
   return false;
  }
  throw serviceException;
 } finally {
  scope.close();
  span.end();
 }
}

相关文章