本文整理汇总了Java中com.google.cloud.storage.BlobId类的典型用法代码示例。如果您正苦于以下问题:Java BlobId类的具体用法?Java BlobId怎么用?Java BlobId使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlobId类属于com.google.cloud.storage包,在下文中一共展示了BlobId类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testWritableOutputStreamWithAutoCreateOnNullBlob
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Test
public void testWritableOutputStreamWithAutoCreateOnNullBlob() throws Exception {
String location = "gs://test-spring/test";
Storage storage = mock(Storage.class);
BlobId blobId = BlobId.of("test-spring", "test");
when(storage.get(blobId)).thenReturn(null);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
WriteChannel writeChannel = mock(WriteChannel.class);
Blob blob = mock(Blob.class);
when(blob.writer()).thenReturn(writeChannel);
when(storage.create(blobInfo)).thenReturn(blob);
GoogleStorageResourceObject resource = new GoogleStorageResourceObject(storage, location);
GoogleStorageResourceObject spyResource = spy(resource);
doReturn(this.bucketResource).when(spyResource).getBucket();
OutputStream os = spyResource.getOutputStream();
Assert.assertNotNull(os);
}
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:19,代码来源:GoogleStorageTests.java
示例2: write
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Override
public void write(InputStream inputStream, String destination) throws IOException {
String[] tokens = getBucketAndObjectFromPath(destination);
Assert.state(tokens.length == 2, "Can only write to files, not buckets.");
BlobInfo gcsBlobInfo = BlobInfo.newBuilder(BlobId.of(tokens[0], tokens[1])).build();
try (InputStream is = inputStream) {
try (WriteChannel channel = this.gcs.writer(gcsBlobInfo)) {
channel.write(ByteBuffer.wrap(StreamUtils.copyToByteArray(is)));
}
}
}
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:14,代码来源:GcsSession.java
示例3: testWritableOutputStreamWithAutoCreateOnNonExistantBlob
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Test
public void testWritableOutputStreamWithAutoCreateOnNonExistantBlob()
throws Exception {
String location = "gs://test-spring/test";
Storage storage = mock(Storage.class);
BlobId blobId = BlobId.of("test-spring", "test");
Blob nonExistantBlob = mock(Blob.class);
when(nonExistantBlob.exists()).thenReturn(false);
when(storage.get(blobId)).thenReturn(nonExistantBlob);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
WriteChannel writeChannel = mock(WriteChannel.class);
Blob blob = mock(Blob.class);
when(blob.writer()).thenReturn(writeChannel);
when(storage.create(blobInfo)).thenReturn(blob);
GoogleStorageResourceObject resource = new GoogleStorageResourceObject(storage, location);
GoogleStorageResourceObject spyResource = spy(resource);
doReturn(this.bucketResource).when(spyResource).getBucket();
OutputStream os = spyResource.getOutputStream();
Assert.assertNotNull(os);
}
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:23,代码来源:GoogleStorageTests.java
示例4: mockStorage
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Bean
public static Storage mockStorage() throws Exception {
Storage storage = mock(Storage.class);
BlobId validBlob = BlobId.of("test-spring", "images/spring.png");
Bucket mockedBucket = mock(Bucket.class);
Blob mockedBlob = mock(Blob.class);
WriteChannel writeChannel = mock(WriteChannel.class);
when(mockedBlob.exists()).thenReturn(true);
when(mockedBucket.exists()).thenReturn(true);
when(mockedBlob.getSize()).thenReturn(4096L);
when(storage.get(eq(validBlob))).thenReturn(mockedBlob);
when(storage.get("test-spring")).thenReturn(mockedBucket);
when(mockedBucket.getName()).thenReturn("test-spring");
when(mockedBlob.writer()).thenReturn(writeChannel);
return storage;
}
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:17,代码来源:GoogleStorageTests.java
示例5: tearDownClass
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@AfterClass
public static void tearDownClass() {
// Clear the datastore
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
Batch batch = datastore.newBatch();
StructuredQuery<Key> query = Query.newKeyQueryBuilder()
.setKind("Book3").build();
for (QueryResults<Key> keys = datastore.run(query); keys.hasNext(); ) {
batch.delete(keys.next());
}
batch.submit();
// Delete any objects in the bucket
Storage storage = StorageOptions.getDefaultInstance().getService();
Page<Blob> blobs = storage.list(System.getProperty("bookshelf.bucket"));
List<BlobId> blobIds = new ArrayList<BlobId>();
for (Blob b : blobs.iterateAll()) {
blobIds.add(b.getBlobId());
}
storage.delete(blobIds);
service.stop();
}
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:24,代码来源:UserJourneyTestIT.java
示例6: tearDownClass
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@AfterClass
public static void tearDownClass() {
// Delete any objects in the bucket
Storage storage = StorageOptions.getDefaultInstance().getService();
Page<Blob> blobs = storage.list(System.getProperty("bookshelf.bucket"));
List<BlobId> blobIds = new ArrayList<BlobId>();
for (Blob b : blobs.iterateAll()) {
blobIds.add(b.getBlobId());
}
storage.delete(blobIds);
// Clear the datastore if we're not using the local emulator
if (!LOCAL_TEST) {
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
Batch batch = datastore.newBatch();
StructuredQuery<Key> query = Query.newKeyQueryBuilder()
.setKind("Book3").build();
for (QueryResults<Key> keys = datastore.run(query); keys.hasNext(); ) {
batch.delete(keys.next());
}
batch.submit();
}
service.stop();
}
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:26,代码来源:UserJourneyTestIT.java
示例7: copy
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
/**
* Copy a blob for gcs to a destination bucket and a path (and delete the source blob if needed)
* @param sourceBlobId sourceBlobId
* @param destinationBucket destination bucket
* @param destinationPath destination path
* @param deleteSource delete source blob
*/
private void copy(BlobId sourceBlobId, String destinationBucket, String destinationPath, boolean deleteSource) {
LOG.debug(
"Copying object '{}' to Object '{}'",
String.format(BLOB_PATH_TEMPLATE, sourceBlobId.getBucket(), sourceBlobId.getName()),
String.format(BLOB_PATH_TEMPLATE, destinationBucket, destinationPath)
);
Storage.CopyRequest copyRequest = new Storage.CopyRequest.Builder()
.setSource(sourceBlobId)
.setTarget(BlobId.of(destinationBucket, destinationPath))
.build();
Blob destinationBlob = storage.copy(copyRequest).getResult();
LOG.debug(
"Copied object '{}' to Object '{}'",
String.format(BLOB_PATH_TEMPLATE, sourceBlobId.getBucket(), sourceBlobId.getName()),
String.format(BLOB_PATH_TEMPLATE, destinationBlob.getBlobId().getBucket(), destinationBlob.getBlobId().getName())
);
if (deleteSource) {
delete(sourceBlobId);
}
}
开发者ID:streamsets,项目名称:datacollector,代码行数:29,代码来源:GcsObjectPostProcessingHandler.java
示例8: handleArchive
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
/**
* Archive the blob
* @param blobId blobId
*/
private void handleArchive(BlobId blobId) {
String destinationPath = getDestinationPath(blobId, gcsOriginErrorConfig.errorPrefix);
switch (gcsOriginErrorConfig.archivingOption) {
case COPY_TO_BUCKET:
copy(blobId, gcsOriginErrorConfig.errorBucket, destinationPath, false);
break;
case MOVE_TO_BUCKET:
copy(blobId, gcsOriginErrorConfig.errorBucket, destinationPath, true);
break;
case COPY_TO_PREFIX:
copy(blobId, blobId.getBucket(), destinationPath, false);
break;
case MOVE_TO_PREFIX:
copy(blobId, blobId.getBucket(), destinationPath, true);
break;
}
}
开发者ID:streamsets,项目名称:datacollector,代码行数:22,代码来源:GcsObjectPostProcessingHandler.java
示例9: openConnectionInternal
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
protected void openConnectionInternal() throws ConnectionException, AuthenticationException
{
final Repository repository = getRepository();
if (!"gs".equals(repository.getProtocol())) {
throw new IllegalArgumentException(String.format("Unsupported protocol [%s]", repository.getProtocol()));
}
final HttpClient client = buildClient();
swapAndCloseConnection(new ConnectionPOJO(
buildStorage(client),
BlobId.of(repository.getHost(), repository.getBasedir().substring(1)),
client
));
}
开发者ID:drcrallen,项目名称:gswagon-maven-plugin,代码行数:17,代码来源:GSWagon.java
示例10: toBlobID
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@VisibleForTesting
BlobId toBlobID(String resource)
{
final BlobId base = getBaseId();
// getName yields a leading `/`
return BlobId.of(base.getBucket(), String.format("%s/%s", base.getName(), resource));
}
开发者ID:drcrallen,项目名称:gswagon-maven-plugin,代码行数:8,代码来源:GSWagon.java
示例11: testToBlobID
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Test
public void testToBlobID()
{
final String resource = "resource";
final GSWagon gsWagon = new GSWagon();
gsWagon.swapAndCloseConnection(connectionPOJO);
final BlobId blobId = gsWagon.toBlobID(resource);
assertEquals(connectionPOJO.baseId.getBucket(), blobId.getBucket());
assertNull(connectionPOJO.baseId.getGeneration());
assertEquals(String.format("%s/%s", connectionPOJO.baseId.getName(), resource), blobId.getName());
}
开发者ID:drcrallen,项目名称:gswagon-maven-plugin,代码行数:12,代码来源:GSWagonTest.java
示例12: testOpenConnectionInternal
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Test
public void testOpenConnectionInternal() throws Exception
{
gsWagon.openConnectionInternal();
final BlobId baseId = gsWagon.getBaseId();
assertEquals("bucket", baseId.getBucket());
assertEquals("key", baseId.getName());
assertNull(baseId.getGeneration());
}
开发者ID:drcrallen,项目名称:gswagon-maven-plugin,代码行数:10,代码来源:GSWagonTest.java
示例13: testGetItem
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Test
public void testGetItem() throws Exception
{
final HttpClient client = strictMock(HttpClient.class);
final Storage storage = createStrictMock(Storage.class);
final GSWagon gsWagon = new GSWagon()
{
@Override
void get(Blob blob, File file) throws IOException, TransferFailedException
{
// noop
}
};
gsWagon.swapAndCloseConnection(new ConnectionPOJO(
storage,
BLOB_ID,
client
));
final Capture<BlobId> blobIdCapture = Capture.newInstance();
expect(storage.get(capture(blobIdCapture))).andReturn(createStrictMock(Blob.class)).once();
replay(storage);
final File outFile = temporaryFolder.newFile();
gsWagon.get("artifact", outFile);
verify(storage);
assertTrue(blobIdCapture.hasCaptured());
assertEquals(connectionPOJO.baseId.getBucket(), blobIdCapture.getValue().getBucket());
assertEquals(
String.format("%s/%s", connectionPOJO.baseId.getName(), "artifact"),
blobIdCapture.getValue().getName()
);
assertNull(blobIdCapture.getValue().getGeneration());
}
开发者ID:drcrallen,项目名称:gswagon-maven-plugin,代码行数:36,代码来源:GSWagonTest.java
示例14: testGetItemNotFound
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Test
public void testGetItemNotFound() throws Exception
{
expectedException.expect(new CustomMatcher<Object>(ResourceDoesNotExistException.class.getName())
{
@Override
public boolean matches(Object item)
{
return item instanceof ResourceDoesNotExistException;
}
});
final HttpClient client = strictMock(HttpClient.class);
final Storage storage = createStrictMock(Storage.class);
final GSWagon gsWagon = new GSWagon()
{
@Override
void get(Blob blob, File file) throws IOException, TransferFailedException
{
// noop
}
};
gsWagon.swapAndCloseConnection(new ConnectionPOJO(
storage,
BLOB_ID,
client
));
expect(storage.get(EasyMock.<BlobId>anyObject())).andReturn(null).once();
replay(storage);
final File outFile = temporaryFolder.newFile();
gsWagon.get("artifact", outFile);
}
开发者ID:drcrallen,项目名称:gswagon-maven-plugin,代码行数:33,代码来源:GSWagonTest.java
示例15: testWritableOutputStream
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Test
public void testWritableOutputStream() throws Exception {
String location = "gs://test-spring/test";
Storage storage = mock(Storage.class);
Blob blob = mock(Blob.class);
WriteChannel writeChannel = mock(WriteChannel.class);
when(blob.writer()).thenReturn(writeChannel);
when(blob.exists()).thenReturn(true);
when(storage.get(BlobId.of("test-spring", "test"))).thenReturn(blob);
GoogleStorageResourceObject resource = new GoogleStorageResourceObject(storage, location);
OutputStream os = resource.getOutputStream();
Assert.assertNotNull(os);
}
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:15,代码来源:GoogleStorageTests.java
示例16: testWritableOutputStreamNoAutoCreateOnNullBlob
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Test(expected = FileNotFoundException.class)
public void testWritableOutputStreamNoAutoCreateOnNullBlob() throws Exception {
String location = "gs://test-spring/test";
Storage storage = mock(Storage.class);
when(storage.get(BlobId.of("test-spring", "test"))).thenReturn(null);
GoogleStorageResourceObject resource = new GoogleStorageResourceObject(storage, location,
false);
resource.getOutputStream();
}
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:11,代码来源:GoogleStorageTests.java
示例17: testGetInputStreamOnNullBlob
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Test(expected = FileNotFoundException.class)
public void testGetInputStreamOnNullBlob() throws Exception {
String location = "gs://test-spring/test";
Storage storage = mock(Storage.class);
when(storage.get(BlobId.of("test-spring", "test"))).thenReturn(null);
GoogleStorageResourceObject resource = new GoogleStorageResourceObject(storage, location,
false);
resource.getInputStream();
}
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:11,代码来源:GoogleStorageTests.java
示例18: testGetFilenameOnNullBlob
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Test
public void testGetFilenameOnNullBlob() throws Exception {
String location = "gs://test-spring/test";
Storage storage = mock(Storage.class);
when(storage.get(BlobId.of("test-spring", "test"))).thenReturn(null);
GoogleStorageResourceObject resource = new GoogleStorageResourceObject(storage, location,
false);
Assert.assertNull(resource.getFilename());
}
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:11,代码来源:GoogleStorageTests.java
示例19: nullSignedUrlForNullBlob
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Test
public void nullSignedUrlForNullBlob() throws IOException {
String location = "gs://test-spring/t1/test.png";
Storage storage = mock(Storage.class);
GoogleStorageResourceObject resource = new GoogleStorageResourceObject(storage,
location);
when(storage.get(any(BlobId.class))).thenReturn(null);
Assert.assertNull(resource.createSignedUrl(TimeUnit.DAYS, 1));
}
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:10,代码来源:GoogleStorageTests.java
示例20: signedUrlFunctionCalled
import com.google.cloud.storage.BlobId; //导入依赖的package包/类
@Test
public void signedUrlFunctionCalled() throws IOException {
String location = "gs://test-spring/t1/test.png";
Storage storage = mock(Storage.class);
Blob blob = mock(Blob.class);
when(blob.getBucket()).thenReturn("fakeBucket");
when(blob.getName()).thenReturn("fakeObject");
GoogleStorageResourceObject resource = new GoogleStorageResourceObject(storage, location);
when(storage.get(any(BlobId.class))).thenReturn(blob);
resource.createSignedUrl(TimeUnit.DAYS, 1L);
verify(storage, times(1)).signUrl(any(), eq(1L), eq(TimeUnit.DAYS));
}
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:13,代码来源:GoogleStorageTests.java
注:本文中的com.google.cloud.storage.BlobId类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论