use of com.google.cloud.storage.BlobId in project google-cloud-java by GoogleCloudPlatform.
the class UpdateBlob method main.
public static void main(String... args) throws IOException {
Storage storage = StorageOptions.getDefaultInstance().getService();
BlobId blobId = BlobId.of("bucket", "blob_name");
Blob blob = storage.get(blobId);
if (blob != null) {
byte[] prevContent = blob.getContent();
System.out.println(new String(prevContent, UTF_8));
WritableByteChannel channel = blob.writer();
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
channel.close();
}
}
use of com.google.cloud.storage.BlobId in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method getBlobAcl.
/**
* Example of getting the ACL entry for a specific user on a blob.
*/
// [TARGET getAcl(BlobId, Entity)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
// [VARIABLE "google-cloud-java-tests@java-docs-samples-tests.iam.gserviceaccount.com"]
public Acl getBlobAcl(String bucketName, String blobName, String userEmail) {
// [START storagePrintFileAclForUser]
BlobId blobId = BlobId.of(bucketName, blobName);
Acl acl = storage.getAcl(blobId, new User(userEmail));
// [END storagePrintFileAclForUser]
return acl;
}
use of com.google.cloud.storage.BlobId in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method readerFromId.
/**
* Example of reading a blob's content through a reader.
*/
// [TARGET reader(BlobId, BlobSourceOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
public void readerFromId(String bucketName, String blobName) throws IOException {
// [START readerFromId]
BlobId blobId = BlobId.of(bucketName, blobName);
try (ReadChannel reader = storage.reader(blobId)) {
ByteBuffer bytes = ByteBuffer.allocate(64 * 1024);
while (reader.read(bytes) > 0) {
bytes.flip();
// do something with bytes
bytes.clear();
}
}
// [END readerFromId]
}
use of com.google.cloud.storage.BlobId in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method deleteBlob.
/**
* Example of deleting a blob.
*/
// [TARGET delete(BlobId)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
public boolean deleteBlob(String bucketName, String blobName) {
// [START deleteBlob]
BlobId blobId = BlobId.of(bucketName, blobName);
boolean deleted = storage.delete(blobId);
if (deleted) {
// the blob was deleted
} else {
// the blob was not found
}
// [END deleteBlob]
return deleted;
}
use of com.google.cloud.storage.BlobId in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method deleteBlobAcl.
/**
* Example of deleting the ACL entry for an entity on a blob.
*/
// [TARGET deleteAcl(BlobId, Entity)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
// [VARIABLE 42]
public boolean deleteBlobAcl(String bucketName, String blobName, long blobGeneration) {
// [START deleteBlobAcl]
BlobId blobId = BlobId.of(bucketName, blobName, blobGeneration);
boolean deleted = storage.deleteAcl(blobId, User.ofAllAuthenticatedUsers());
if (deleted) {
// the acl entry was deleted
} else {
// the acl entry was not found
}
// [END deleteBlobAcl]
return deleted;
}
Aggregations