use of com.google.cloud.storage.BlobId in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method listBlobAcls.
/**
* Example of listing the ACL entries for a blob.
*/
// [TARGET listAcls(BlobId)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
// [VARIABLE 42]
public List<Acl> listBlobAcls(String bucketName, String blobName, long blobGeneration) {
// [START listBlobAcls]
BlobId blobId = BlobId.of(bucketName, blobName, blobGeneration);
List<Acl> acls = storage.listAcls(blobId);
for (Acl acl : acls) {
// do something with ACL entry
}
// [END listBlobAcls]
return acls;
}
use of com.google.cloud.storage.BlobId in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method createEncryptedBlob.
/**
* Example of uploading an encrypted blob.
*/
// [TARGET create(BlobInfo, InputStream, BlobWriteOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
// [VARIABLE "my_encryption_key"]
public Blob createEncryptedBlob(String bucketName, String blobName, String encryptionKey) {
// [START storageUploadEncryptedFile]
InputStream content = new ByteArrayInputStream("Hello, World!".getBytes(UTF_8));
BlobId blobId = BlobId.of(bucketName, blobName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
Blob blob = storage.create(blobInfo, content, BlobWriteOption.encryptionKey(encryptionKey));
// [END storageUploadEncryptedFile]
return blob;
}
use of com.google.cloud.storage.BlobId in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method deleteBlobFromIdWithGeneration.
/**
* Example of deleting a blob, only if its generation matches a value, otherwise a
* {@link StorageException} is thrown.
*/
// [TARGET delete(BlobId, BlobSourceOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
// [VARIABLE 42]
public boolean deleteBlobFromIdWithGeneration(String bucketName, String blobName, long blobGeneration) {
// [START deleteBlobFromIdWithGeneration]
BlobId blobId = BlobId.of(bucketName, blobName);
boolean deleted = storage.delete(blobId, BlobSourceOption.generationMatch(blobGeneration));
if (deleted) {
// the blob was deleted
} else {
// the blob was not found
}
// [END deleteBlobFromIdWithGeneration]
return deleted;
}
use of com.google.cloud.storage.BlobId in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method createBlobFromInputStream.
/**
* Example of creating a blob from an input stream.
*/
// [TARGET create(BlobInfo, InputStream, BlobWriteOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
public Blob createBlobFromInputStream(String bucketName, String blobName) {
// [START createBlobFromInputStream]
InputStream content = new ByteArrayInputStream("Hello, World!".getBytes(UTF_8));
BlobId blobId = BlobId.of(bucketName, blobName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
Blob blob = storage.create(blobInfo, content);
// [END createBlobFromInputStream]
return blob;
}
use of com.google.cloud.storage.BlobId in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method createBlobFromByteArray.
/**
* Example of creating a blob from a byte array.
*/
// [TARGET create(BlobInfo, byte[], BlobTargetOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
public Blob createBlobFromByteArray(String bucketName, String blobName) {
// [START createBlobFromByteArray]
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));
// [END createBlobFromByteArray]
return blob;
}
Aggregations