use of com.google.cloud.storage.BlobInfo in project flink by apache.
the class GSBlobStorageImpl method writeBlob.
@Override
public GSBlobStorage.WriteChannel writeBlob(GSBlobIdentifier blobIdentifier, MemorySize chunkSize) {
LOGGER.trace("Creating writeable blob for identifier {} with chunk size {}", blobIdentifier, chunkSize);
Preconditions.checkNotNull(blobIdentifier);
Preconditions.checkArgument(chunkSize.getBytes() > 0);
BlobInfo blobInfo = BlobInfo.newBuilder(blobIdentifier.getBlobId()).build();
com.google.cloud.WriteChannel writeChannel = storage.writer(blobInfo);
writeChannel.setChunkSize((int) chunkSize.getBytes());
return new WriteChannel(blobIdentifier, writeChannel);
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageSnippets method testBlobAcl.
@Test
public void testBlobAcl() {
String blobName = "test-blob-acl";
BlobId blobId = BlobId.of(BUCKET, "test-blob-acl");
BlobInfo blob = BlobInfo.newBuilder(blobId).build();
Blob createdBlob = storage.create(blob);
assertNull(storageSnippets.getBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
assertNotNull(storageSnippets.createBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
Acl updatedAcl = storageSnippets.updateBlobAcl(BUCKET, blobName, createdBlob.getGeneration());
assertEquals(Acl.Role.OWNER, updatedAcl.getRole());
Set<Acl> acls = Sets.newHashSet(storageSnippets.listBlobAcls(BUCKET, blobName, createdBlob.getGeneration()));
assertTrue(acls.contains(updatedAcl));
assertNull(storageSnippets.getBlobAcl(BUCKET, blobName, USER_EMAIL));
storage.createAcl(BlobId.of(BUCKET, blobName), Acl.of(new User(USER_EMAIL), Role.READER));
Acl userAcl = storageSnippets.getBlobAcl(BUCKET, blobName, USER_EMAIL);
assertNotNull(userAcl);
assertEquals(USER_EMAIL, ((User) userAcl.getEntity()).getEmail());
assertNotNull(storageSnippets.getBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
assertTrue(storageSnippets.deleteBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
assertNull(storageSnippets.getBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
// test non-existing blob
String nonExistingBlob = "test-blob-acl";
assertNull(storageSnippets.getBlobAcl(BUCKET, nonExistingBlob, 1L));
assertFalse(storageSnippets.deleteBlobAcl(BUCKET, nonExistingBlob, 1L));
try {
storageSnippets.createBlobAcl(BUCKET, nonExistingBlob, 1L);
fail("Expected StorageException");
} catch (StorageException ex) {
// expected
}
try {
storageSnippets.updateBlobAcl(BUCKET, nonExistingBlob, 1L);
fail("Expected StorageException");
} catch (StorageException ex) {
// expected
}
try {
storageSnippets.listBlobAcls(BUCKET, nonExistingBlob, 1L);
fail("Expected StorageException");
} catch (StorageException ex) {
// expected
}
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method composeBlobs.
/**
* Example of composing two blobs.
*/
// [TARGET compose(ComposeRequest)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
// [VARIABLE "source_blob_1"]
// [VARIABLE "source_blob_2"]
public Blob composeBlobs(String bucketName, String blobName, String sourceBlob1, String sourceBlob2) {
// [START composeBlobs]
BlobId blobId = BlobId.of(bucketName, blobName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
ComposeRequest request = ComposeRequest.newBuilder().setTarget(blobInfo).addSource(sourceBlob1).addSource(sourceBlob2).build();
Blob blob = storage.compose(request);
// [END composeBlobs]
return blob;
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method createBlobWithSubArrayFromByteArray.
/**
* Example of creating a blob with sub array from a byte array.
*/
// [TARGET create(BlobInfo, byte[], offset, length, BlobTargetOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
public Blob createBlobWithSubArrayFromByteArray(String bucketName, String blobName, int offset, int length) {
// [START createBlobWithSubArrayFromByteArray]
BlobId blobId = BlobId.of(bucketName, blobName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
Blob blob = storage.create(blobInfo, "Hello, World!".getBytes(UTF_8), offset, length);
// [END createBlobWithSubArrayFromByteArray]
return blob;
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method batchUpdateIterable.
/**
* Example of updating information on several blobs using a single batch request.
*/
// [TARGET update(Iterable)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name1"]
// [VARIABLE "my_blob_name2"]
public List<Blob> batchUpdateIterable(String bucketName, String blobName1, String blobName2) {
// [START batchUpdateIterable]
Blob firstBlob = storage.get(bucketName, blobName1);
Blob secondBlob = storage.get(bucketName, blobName2);
List<BlobInfo> blobs = new LinkedList<>();
blobs.add(firstBlob.toBuilder().setContentType("text/plain").build());
blobs.add(secondBlob.toBuilder().setContentType("text/plain").build());
List<Blob> updatedBlobs = storage.update(blobs);
// [END batchUpdateIterable]
return updatedBlobs;
}
Aggregations