/** * Creates a {@code ComposeRequest} object. * * @param bucket name of the bucket where the compose operation takes place * @param sources source blobs names * @param target target blob name */ public static ComposeRequest of(String bucket, Iterable<String> sources, String target) { return of(sources, BlobInfo.newBuilder(BlobId.of(bucket, target)).build()); }
/** Example of updating a blob to be public-read. */ // [TARGET createAcl(BlobId, Acl)] // [VARIABLE "my_unique_bucket"] // [VARIABLE "my_blob_name"] // [VARIABLE 42] public Acl blobToPublicRead(String bucketName, String blobName, long blobGeneration) { // [START storageMakePublic] BlobId blobId = BlobId.of(bucketName, blobName, blobGeneration); Acl acl = storage.createAcl(blobId, Acl.of(User.ofAllUsers(), Role.READER)); // [END storageMakePublic] return acl; }
/** Example of copying the blob to a different bucket with a different name. */ // [TARGET copyTo(BlobId, BlobSourceOption...)] // [VARIABLE "my_unique_bucket"] // [VARIABLE "copy_blob_name"] public Blob copyToId(String bucketName, String blobName) { // [START copyToId] CopyWriter copyWriter = blob.copyTo(BlobId.of(bucketName, blobName)); Blob copiedBlob = copyWriter.getResult(); // [END copyToId] return copiedBlob; }
@Override protected Restorable<?>[] restorableObjects() { StorageOptions options = StorageOptions.newBuilder().setProjectId("p2").build(); ReadChannel reader = new BlobReadChannel(options, BlobId.of("b", "n"), EMPTY_RPC_OPTIONS); // avoid closing when you don't want partial writes to GCS upon failure @SuppressWarnings("resource") BlobWriteChannel writer = new BlobWriteChannel( options, BlobInfo.newBuilder(BlobId.of("b", "n")).build(), "upload-id"); return new Restorable<?>[] {reader, writer}; } }
/** Example of creating a blob with no content. */ // [TARGET create(BlobInfo, BlobTargetOption...)] // [VARIABLE "my_unique_bucket"] // [VARIABLE "my_blob_name"] public Blob createBlob(String bucketName, String blobName) { // [START createBlob] BlobId blobId = BlobId.of(bucketName, blobName); BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build(); Blob blob = storage.create(blobInfo); // [END createBlob] return blob; }
private byte[] getRawBytes(String blobName) { Bucket bucket = storage.get(bucketName); Preconditions.checkNotNull(bucket, "Bucket [%s] not found", bucketName); Blob blob = bucket.get(blobName); Preconditions.checkNotNull(blob, "blob [%s] not found", blobName); return blob.getContent(); }
/** Example of creating a new ACL entry on a blob. */ // [TARGET createAcl(BlobId, Acl)] // [VARIABLE "my_unique_bucket"] // [VARIABLE "my_blob_name"] // [VARIABLE 42] public Acl createBlobAcl(String bucketName, String blobName, long blobGeneration) { // [START createBlobAcl] BlobId blobId = BlobId.of(bucketName, blobName, blobGeneration); Acl acl = storage.createAcl(blobId, Acl.of(User.ofAllAuthenticatedUsers(), Role.READER)); // [END createBlobAcl] return acl; }
/** Example of updating a new ACL entry on a blob. */ // [TARGET updateAcl(BlobId, Acl)] // [VARIABLE "my_unique_bucket"] // [VARIABLE "my_blob_name"] // [VARIABLE 42] public Acl updateBlobAcl(String bucketName, String blobName, long blobGeneration) { // [START updateBlobAcl] BlobId blobId = BlobId.of(bucketName, blobName, blobGeneration); Acl acl = storage.updateAcl(blobId, Acl.of(User.ofAllAuthenticatedUsers(), Role.OWNER)); // [END updateBlobAcl] return acl; }
/** 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; }
/** Example of updating bucket information. */ // [TARGET update(BucketInfo, BucketTargetOption...)] // [VARIABLE "my_unique_bucket"] public Bucket updateBucket(String bucketName) { // [START updateBucket] BucketInfo bucketInfo = BucketInfo.newBuilder(bucketName).setVersioningEnabled(true).build(); Bucket bucket = storage.update(bucketInfo); // [END updateBucket] return bucket; }
@Override public ReadChannel reader(String bucket, String blob, BlobSourceOption... options) { Map<StorageRpc.Option, ?> optionsMap = optionMap(options); return new BlobReadChannel(getOptions(), BlobId.of(bucket, blob), optionsMap); }
/** Example of updating a new default ACL entry on a bucket. */ // [TARGET updateDefaultAcl(String, Acl)] // [VARIABLE "my_unique_bucket"] public Acl updateDefaultBucketAcl(String bucketName) { // [START updateDefaultBucketAcl] Acl acl = storage.updateDefaultAcl(bucketName, Acl.of(User.ofAllAuthenticatedUsers(), Role.OWNER)); // [END updateDefaultBucketAcl] return acl; }
/** Example of updating a new ACL entry on a bucket. */ // [TARGET updateAcl(String, Acl)] // [VARIABLE "my_unique_bucket"] public Acl updateBucketAcl(String bucketName) { // [START updateBucketAcl] Acl acl = storage.updateAcl(bucketName, Acl.of(User.ofAllAuthenticatedUsers(), Role.OWNER)); // [END updateBucketAcl] return acl; }
/** Example of creating a new ACL entry. */ // [TARGET createAcl(Acl)] public Acl createAcl() { // [START createAcl] Acl acl = blob.createAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.READER)); // [END createAcl] return acl; }
/** Example of updating a new ACL entry. */ // [TARGET updateAcl(Acl)] public Acl updateAcl() { // [START updateAcl] Acl acl = blob.updateAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER)); // [END updateAcl] return acl; }
/** Example of creating a new ACL entry. */ // [TARGET createAcl(Acl)] public Acl createAcl() { // [START createAcl] Acl acl = bucket.createAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.READER)); // [END createAcl] return acl; }
/** Example of updating a new ACL entry. */ // [TARGET updateAcl(Acl)] public Acl updateAcl() { // [START updateAcl] Acl acl = bucket.updateAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER)); // [END updateAcl] return acl; }
/** Example of creating a new default ACL entry. */ // [TARGET createDefaultAcl(Acl)] public Acl createDefaultAcl() { // [START createDefaultAcl] Acl acl = bucket.createDefaultAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.READER)); // [END createDefaultAcl] return acl; }
private void initializeServiceDependentObjects() { expectedBlob1 = new Blob(storage, new BlobInfo.BuilderImpl(BLOB_INFO1)); expectedBlob2 = new Blob(storage, new BlobInfo.BuilderImpl(BLOB_INFO2)); expectedBlob3 = new Blob(storage, new BlobInfo.BuilderImpl(BLOB_INFO3)); expectedBucket1 = new Bucket(storage, new BucketInfo.BuilderImpl(BUCKET_INFO1)); expectedBucket2 = new Bucket(storage, new BucketInfo.BuilderImpl(BUCKET_INFO2)); expectedBucket3 = new Bucket(storage, new BucketInfo.BuilderImpl(BUCKET_INFO3)); }
static Blob fromPb(Storage storage, StorageObject storageObject) { BlobInfo info = BlobInfo.fromPb(storageObject); return new Blob(storage, new BlobInfo.BuilderImpl(info)); } }