本文整理汇总了Java中com.google.api.services.storage.model.Buckets类的典型用法代码示例。如果您正苦于以下问题:Java Buckets类的具体用法?Java Buckets怎么用?Java Buckets使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Buckets类属于com.google.api.services.storage.model包,在下文中一共展示了Buckets类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateBucketWithOptionsNormalOperation
import com.google.api.services.storage.model.Buckets; //导入依赖的package包/类
/**
* Test successful operation of GoogleCloudStorage.create(String, CreateBucketOptions).
*/
@Test
public void testCreateBucketWithOptionsNormalOperation()
throws IOException {
final Bucket[] bucketWithOptions = new Bucket[1];
when(mockStorage.buckets()).thenReturn(mockStorageBuckets);
when(mockBackOffFactory.newBackOff()).thenReturn(mockBackOff);
final Storage.Buckets.Insert finalMockInsert = mockStorageBucketsInsert;
when(mockStorageBuckets.insert(eq(PROJECT_ID), any(Bucket.class)))
.thenAnswer(new Answer<Storage.Buckets.Insert>() {
@Override public Storage.Buckets.Insert answer(InvocationOnMock invocation) {
bucketWithOptions[0] = (Bucket) invocation.getArguments()[1];
return finalMockInsert;
}});
gcs.create(BUCKET_NAME, new CreateBucketOptions("some-location", "storage-class"));
assertEquals(BUCKET_NAME, bucketWithOptions[0].getName());
assertEquals("some-location", bucketWithOptions[0].getLocation());
assertEquals("storage-class", bucketWithOptions[0].getStorageClass());
verify(mockStorage).buckets();
verify(mockBackOffFactory).newBackOff();
verify(mockStorageBuckets).insert(eq(PROJECT_ID), any(Bucket.class));
verify(mockStorageBucketsInsert).execute();
}
示例2: setupMocksForListBuckets
import com.google.api.services.storage.model.Buckets; //导入依赖的package包/类
/**
* Sets up mocks for a list-bucket operation.
*/
private void setupMocksForListBuckets()
throws IOException {
when(mockStorage.buckets()).thenReturn(mockStorageBuckets);
when(mockStorageBuckets.list(eq(PROJECT_ID))).thenReturn(mockStorageBucketsList);
when(mockStorageBucketsList.execute())
.thenReturn(new Buckets()
.setItems(ImmutableList.of(
createTestBucket(0),
createTestBucket(1)))
.setNextPageToken("token0"))
.thenReturn(new Buckets()
.setItems(ImmutableList.of(
createTestBucket(2)))
.setNextPageToken(null));
}
示例3: getPotentialStagingLocations
import com.google.api.services.storage.model.Buckets; //导入依赖的package包/类
/**
* Gets a collection of potential Staging Locations.
*/
public SortedSet<String> getPotentialStagingLocations(String projectId) throws IOException {
SortedSet<String> result = new TreeSet<>();
Buckets buckets = gcsClient.buckets().list(projectId).execute();
List<Bucket> bucketList = buckets.getItems();
if (bucketList != null) {
for (Bucket bucket : bucketList) {
result.add(GCS_PREFIX + bucket.getName());
}
}
return result;
}
示例4: create
import com.google.api.services.storage.model.Buckets; //导入依赖的package包/类
/**
* See {@link GoogleCloudStorage#create(String, CreateBucketOptions)} for
* details about expected behavior.
*/
@Override
public void create(String bucketName, CreateBucketOptions options)
throws IOException {
LOG.debug("create({})", bucketName);
Preconditions.checkArgument(!Strings.isNullOrEmpty(bucketName),
"bucketName must not be null or empty");
Preconditions.checkNotNull(options, "options must not be null");
Preconditions.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 =
gcs.buckets().insert(storageOptions.getProjectId(), bucket);
// 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
}
}