Class StorageClient (2.5.1)

public class StorageClient implements BackgroundResource

Service Description: ## API Overview and Naming Syntax

The Cloud Storage gRPC API allows applications to read and write data through the abstractions of buckets and objects. For a description of these abstractions please see https://cloud.google.com/storage/docs.

Resources are named as follows: - Projects are referred to as they are defined by the Resource Manager API, using strings like projects/123456 or projects/my-string-id. - Buckets are named using string names of the form: projects/{project}/buckets/{bucket} For globally unique buckets, _ may be substituted for the project. - Objects are uniquely identified by their name along with the name of the bucket they belong to, as separate strings in this API. For example:

ReadObjectRequest { bucket: 'projects/_/buckets/my-bucket' object: 'my-object' } Note that object names can contain / characters, which are treated as any other character (no special directory semantics).

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 try (StorageClient storageClient = StorageClient.create()) {
   BucketName name = BucketName.of("[PROJECT]", "[BUCKET]");
   storageClient.deleteBucket(name);
 }
 

Note: close() needs to be called on the StorageClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

The surface of this class includes several types of Java methods for each of the API's methods:

  1. A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
  2. A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
  3. A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of StorageSettings to create(). For example:

To customize credentials:


 StorageSettings storageSettings =
     StorageSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 StorageClient storageClient = StorageClient.create(storageSettings);
 

To customize the endpoint:


 StorageSettings storageSettings = StorageSettings.newBuilder().setEndpoint(myEndpoint).build();
 StorageClient storageClient = StorageClient.create(storageSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > StorageClient

Implements

BackgroundResource

Static Methods

create()

public static final StorageClient create()

Constructs an instance of StorageClient with default settings.

Returns
TypeDescription
StorageClient
Exceptions
TypeDescription
IOException

create(StorageSettings settings)

public static final StorageClient create(StorageSettings settings)

Constructs an instance of StorageClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
NameDescription
settingsStorageSettings
Returns
TypeDescription
StorageClient
Exceptions
TypeDescription
IOException

create(StorageStub stub)

public static final StorageClient create(StorageStub stub)

Constructs an instance of StorageClient, using the given stub for making calls. This is for advanced usage - prefer using create(StorageSettings).

Parameter
NameDescription
stubStorageStub
Returns
TypeDescription
StorageClient

Constructors

StorageClient(StorageSettings settings)

protected StorageClient(StorageSettings settings)

Constructs an instance of StorageClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.

Parameter
NameDescription
settingsStorageSettings

StorageClient(StorageStub stub)

protected StorageClient(StorageStub stub)
Parameter
NameDescription
stubStorageStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
NameDescription
durationlong
unitTimeUnit
Returns
TypeDescription
boolean
Exceptions
TypeDescription
InterruptedException

close()

public final void close()

composeObject(ComposeObjectRequest request)

public final Object composeObject(ComposeObjectRequest request)

Concatenates a list of existing objects into a new object in the same bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ComposeObjectRequest request =
       ComposeObjectRequest.newBuilder()
           .setDestination(Object.newBuilder().build())
           .addAllSourceObjects(new ArrayList
Parameter
NameDescription
requestComposeObjectRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Object

composeObjectCallable()

public final UnaryCallable<ComposeObjectRequest,Object> composeObjectCallable()

Concatenates a list of existing objects into a new object in the same bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ComposeObjectRequest request =
       ComposeObjectRequest.newBuilder()
           .setDestination(Object.newBuilder().build())
           .addAllSourceObjects(new ArrayList
Returns
TypeDescription
UnaryCallable<ComposeObjectRequest,Object>

createBucket(CreateBucketRequest request)

public final Bucket createBucket(CreateBucketRequest request)

Creates a new bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   CreateBucketRequest request =
       CreateBucketRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setBucket(Bucket.newBuilder().build())
           .setBucketId("bucketId-1603305307")
           .setPredefinedAcl(PredefinedBucketAcl.forNumber(0))
           .setPredefinedDefaultObjectAcl(PredefinedObjectAcl.forNumber(0))
           .build();
   Bucket response = storageClient.createBucket(request);
 }
 
Parameter
NameDescription
requestCreateBucketRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Bucket

createBucket(ProjectName parent, Bucket bucket, String bucketId)

public final Bucket createBucket(ProjectName parent, Bucket bucket, String bucketId)

Creates a new bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ProjectName parent = ProjectName.of("[PROJECT]");
   Bucket bucket = Bucket.newBuilder().build();
   String bucketId = "bucketId-1603305307";
   Bucket response = storageClient.createBucket(parent, bucket, bucketId);
 }
 
Parameters
NameDescription
parentProjectName

Required. The project to which this bucket will belong.

bucketBucket

Required. Properties of the new bucket being inserted. The project and name of the bucket are specified in this request, not in the bucket resource.

bucketIdString

Required. The ID to use for this bucket, which will become the final component of the bucket's resource name. For example, the value foo might result in a bucket with the name projects/123456/buckets/foo.

Returns
TypeDescription
Bucket

createBucket(String parent, Bucket bucket, String bucketId)

public final Bucket createBucket(String parent, Bucket bucket, String bucketId)

Creates a new bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String parent = ProjectName.of("[PROJECT]").toString();
   Bucket bucket = Bucket.newBuilder().build();
   String bucketId = "bucketId-1603305307";
   Bucket response = storageClient.createBucket(parent, bucket, bucketId);
 }
 
Parameters
NameDescription
parentString

Required. The project to which this bucket will belong.

bucketBucket

Required. Properties of the new bucket being inserted. The project and name of the bucket are specified in this request, not in the bucket resource.

bucketIdString

Required. The ID to use for this bucket, which will become the final component of the bucket's resource name. For example, the value foo might result in a bucket with the name projects/123456/buckets/foo.

Returns
TypeDescription
Bucket

createBucketCallable()

public final UnaryCallable<CreateBucketRequest,Bucket> createBucketCallable()

Creates a new bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   CreateBucketRequest request =
       CreateBucketRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setBucket(Bucket.newBuilder().build())
           .setBucketId("bucketId-1603305307")
           .setPredefinedAcl(PredefinedBucketAcl.forNumber(0))
           .setPredefinedDefaultObjectAcl(PredefinedObjectAcl.forNumber(0))
           .build();
   ApiFuture<Bucket> future = storageClient.createBucketCallable().futureCall(request);
   // Do something.
   Bucket response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CreateBucketRequest,Bucket>

createHmacKey(CreateHmacKeyRequest request)

public final CreateHmacKeyResponse createHmacKey(CreateHmacKeyRequest request)

Creates a new HMAC key for the given service account.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   CreateHmacKeyRequest request =
       CreateHmacKeyRequest.newBuilder()
           .setProject(ProjectName.of("[PROJECT]").toString())
           .setServiceAccountEmail("serviceAccountEmail1825953988")
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   CreateHmacKeyResponse response = storageClient.createHmacKey(request);
 }
 
Parameter
NameDescription
requestCreateHmacKeyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
CreateHmacKeyResponse

createHmacKey(ProjectName project, String serviceAccountEmail)

public final CreateHmacKeyResponse createHmacKey(ProjectName project, String serviceAccountEmail)

Creates a new HMAC key for the given service account.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ProjectName project = ProjectName.of("[PROJECT]");
   String serviceAccountEmail = "serviceAccountEmail1825953988";
   CreateHmacKeyResponse response = storageClient.createHmacKey(project, serviceAccountEmail);
 }
 
Parameters
NameDescription
projectProjectName

Required. The project that the HMAC-owning service account lives in.

serviceAccountEmailString

Required. The service account to create the HMAC for.

Returns
TypeDescription
CreateHmacKeyResponse

createHmacKey(String project, String serviceAccountEmail)

public final CreateHmacKeyResponse createHmacKey(String project, String serviceAccountEmail)

Creates a new HMAC key for the given service account.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String project = ProjectName.of("[PROJECT]").toString();
   String serviceAccountEmail = "serviceAccountEmail1825953988";
   CreateHmacKeyResponse response = storageClient.createHmacKey(project, serviceAccountEmail);
 }
 
Parameters
NameDescription
projectString

Required. The project that the HMAC-owning service account lives in.

serviceAccountEmailString

Required. The service account to create the HMAC for.

Returns
TypeDescription
CreateHmacKeyResponse

createHmacKeyCallable()

public final UnaryCallable<CreateHmacKeyRequest,CreateHmacKeyResponse> createHmacKeyCallable()

Creates a new HMAC key for the given service account.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   CreateHmacKeyRequest request =
       CreateHmacKeyRequest.newBuilder()
           .setProject(ProjectName.of("[PROJECT]").toString())
           .setServiceAccountEmail("serviceAccountEmail1825953988")
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture
Returns
TypeDescription
UnaryCallable<CreateHmacKeyRequest,CreateHmacKeyResponse>

createNotification(CreateNotificationRequest request)

public final Notification createNotification(CreateNotificationRequest request)

Creates a notification subscription for a given bucket. These notifications, when triggered, publish messages to the specified Pub/Sub topics. See https://cloud.google.com/storage/docs/pubsub-notifications.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   CreateNotificationRequest request =
       CreateNotificationRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setNotification(Notification.newBuilder().build())
           .build();
   Notification response = storageClient.createNotification(request);
 }
 
Parameter
NameDescription
requestCreateNotificationRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Notification

createNotification(ProjectName parent, Notification notification)

public final Notification createNotification(ProjectName parent, Notification notification)

Creates a notification subscription for a given bucket. These notifications, when triggered, publish messages to the specified Pub/Sub topics. See https://cloud.google.com/storage/docs/pubsub-notifications.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ProjectName parent = ProjectName.of("[PROJECT]");
   Notification notification = Notification.newBuilder().build();
   Notification response = storageClient.createNotification(parent, notification);
 }
 
Parameters
NameDescription
parentProjectName

Required. The bucket to which this notification belongs.

notificationNotification

Required. Properties of the notification to be inserted.

Returns
TypeDescription
Notification

createNotification(String parent, Notification notification)

public final Notification createNotification(String parent, Notification notification)

Creates a notification subscription for a given bucket. These notifications, when triggered, publish messages to the specified Pub/Sub topics. See https://cloud.google.com/storage/docs/pubsub-notifications.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String parent = ProjectName.of("[PROJECT]").toString();
   Notification notification = Notification.newBuilder().build();
   Notification response = storageClient.createNotification(parent, notification);
 }
 
Parameters
NameDescription
parentString

Required. The bucket to which this notification belongs.

notificationNotification

Required. Properties of the notification to be inserted.

Returns
TypeDescription
Notification

createNotificationCallable()

public final UnaryCallable<CreateNotificationRequest,Notification> createNotificationCallable()

Creates a notification subscription for a given bucket. These notifications, when triggered, publish messages to the specified Pub/Sub topics. See https://cloud.google.com/storage/docs/pubsub-notifications.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   CreateNotificationRequest request =
       CreateNotificationRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setNotification(Notification.newBuilder().build())
           .build();
   ApiFuture<Notification> future =
       storageClient.createNotificationCallable().futureCall(request);
   // Do something.
   Notification response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CreateNotificationRequest,Notification>

deleteBucket(BucketName name)

public final void deleteBucket(BucketName name)

Permanently deletes an empty bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   BucketName name = BucketName.of("[PROJECT]", "[BUCKET]");
   storageClient.deleteBucket(name);
 }
 
Parameter
NameDescription
nameBucketName

Required. Name of a bucket to delete.

deleteBucket(DeleteBucketRequest request)

public final void deleteBucket(DeleteBucketRequest request)

Permanently deletes an empty bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   DeleteBucketRequest request =
       DeleteBucketRequest.newBuilder()
           .setName(BucketName.of("[PROJECT]", "[BUCKET]").toString())
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   storageClient.deleteBucket(request);
 }
 
Parameter
NameDescription
requestDeleteBucketRequest

The request object containing all of the parameters for the API call.

deleteBucket(String name)

public final void deleteBucket(String name)

Permanently deletes an empty bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String name = BucketName.of("[PROJECT]", "[BUCKET]").toString();
   storageClient.deleteBucket(name);
 }
 
Parameter
NameDescription
nameString

Required. Name of a bucket to delete.

deleteBucketCallable()

public final UnaryCallable<DeleteBucketRequest,Empty> deleteBucketCallable()

Permanently deletes an empty bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   DeleteBucketRequest request =
       DeleteBucketRequest.newBuilder()
           .setName(BucketName.of("[PROJECT]", "[BUCKET]").toString())
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture<Empty> future = storageClient.deleteBucketCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<DeleteBucketRequest,Empty>

deleteHmacKey(DeleteHmacKeyRequest request)

public final void deleteHmacKey(DeleteHmacKeyRequest request)

Deletes a given HMAC key. Key must be in an INACTIVE state.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   DeleteHmacKeyRequest request =
       DeleteHmacKeyRequest.newBuilder()
           .setAccessId("accessId-2146437729")
           .setProject(ProjectName.of("[PROJECT]").toString())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   storageClient.deleteHmacKey(request);
 }
 
Parameter
NameDescription
requestDeleteHmacKeyRequest

The request object containing all of the parameters for the API call.

deleteHmacKey(String accessId, ProjectName project)

public final void deleteHmacKey(String accessId, ProjectName project)

Deletes a given HMAC key. Key must be in an INACTIVE state.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String accessId = "accessId-2146437729";
   ProjectName project = ProjectName.of("[PROJECT]");
   storageClient.deleteHmacKey(accessId, project);
 }
 
Parameters
NameDescription
accessIdString

Required. The identifying key for the HMAC to delete.

projectProjectName

Required. The project id the HMAC key lies in.

deleteHmacKey(String accessId, String project)

public final void deleteHmacKey(String accessId, String project)

Deletes a given HMAC key. Key must be in an INACTIVE state.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String accessId = "accessId-2146437729";
   String project = ProjectName.of("[PROJECT]").toString();
   storageClient.deleteHmacKey(accessId, project);
 }
 
Parameters
NameDescription
accessIdString

Required. The identifying key for the HMAC to delete.

projectString

Required. The project id the HMAC key lies in.

deleteHmacKeyCallable()

public final UnaryCallable<DeleteHmacKeyRequest,Empty> deleteHmacKeyCallable()

Deletes a given HMAC key. Key must be in an INACTIVE state.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   DeleteHmacKeyRequest request =
       DeleteHmacKeyRequest.newBuilder()
           .setAccessId("accessId-2146437729")
           .setProject(ProjectName.of("[PROJECT]").toString())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture<Empty> future = storageClient.deleteHmacKeyCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<DeleteHmacKeyRequest,Empty>

deleteNotification(DeleteNotificationRequest request)

public final void deleteNotification(DeleteNotificationRequest request)

Permanently deletes a notification subscription.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   DeleteNotificationRequest request =
       DeleteNotificationRequest.newBuilder()
           .setName(NotificationName.of("[PROJECT]", "[BUCKET]", "[NOTIFICATION]").toString())
           .build();
   storageClient.deleteNotification(request);
 }
 
Parameter
NameDescription
requestDeleteNotificationRequest

The request object containing all of the parameters for the API call.

deleteNotification(NotificationName name)

public final void deleteNotification(NotificationName name)

Permanently deletes a notification subscription.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   NotificationName name = NotificationName.of("[PROJECT]", "[BUCKET]", "[NOTIFICATION]");
   storageClient.deleteNotification(name);
 }
 
Parameter
NameDescription
nameNotificationName

Required. The parent bucket of the notification.

deleteNotification(String name)

public final void deleteNotification(String name)

Permanently deletes a notification subscription.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String name = NotificationName.of("[PROJECT]", "[BUCKET]", "[NOTIFICATION]").toString();
   storageClient.deleteNotification(name);
 }
 
Parameter
NameDescription
nameString

Required. The parent bucket of the notification.

deleteNotificationCallable()

public final UnaryCallable<DeleteNotificationRequest,Empty> deleteNotificationCallable()

Permanently deletes a notification subscription.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   DeleteNotificationRequest request =
       DeleteNotificationRequest.newBuilder()
           .setName(NotificationName.of("[PROJECT]", "[BUCKET]", "[NOTIFICATION]").toString())
           .build();
   ApiFuture<Empty> future = storageClient.deleteNotificationCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<DeleteNotificationRequest,Empty>

deleteObject(DeleteObjectRequest request)

public final void deleteObject(DeleteObjectRequest request)

Deletes an object and its metadata. Deletions are permanent if versioning is not enabled for the bucket, or if the generation parameter is used.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   DeleteObjectRequest request =
       DeleteObjectRequest.newBuilder()
           .setBucket("bucket-1378203158")
           .setObject("object-1023368385")
           .setUploadId("uploadId1563990780")
           .setGeneration(305703192)
           .setIfGenerationMatch(-1086241088)
           .setIfGenerationNotMatch(1475720404)
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   storageClient.deleteObject(request);
 }
 
Parameter
NameDescription
requestDeleteObjectRequest

The request object containing all of the parameters for the API call.

deleteObject(String bucket, String object)

public final void deleteObject(String bucket, String object)

Deletes an object and its metadata. Deletions are permanent if versioning is not enabled for the bucket, or if the generation parameter is used.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String bucket = "bucket-1378203158";
   String object = "object-1023368385";
   storageClient.deleteObject(bucket, object);
 }
 
Parameters
NameDescription
bucketString

Required. Name of the bucket in which the object resides.

objectString

Required. The name of the object to delete (when not using a resumable write).

deleteObject(String bucket, String object, long generation)

public final void deleteObject(String bucket, String object, long generation)

Deletes an object and its metadata. Deletions are permanent if versioning is not enabled for the bucket, or if the generation parameter is used.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String bucket = "bucket-1378203158";
   String object = "object-1023368385";
   long generation = 305703192;
   storageClient.deleteObject(bucket, object, generation);
 }
 
Parameters
NameDescription
bucketString

Required. Name of the bucket in which the object resides.

objectString

Required. The name of the object to delete (when not using a resumable write).

generationlong

If present, permanently deletes a specific revision of this object (as opposed to the latest version, the default).

deleteObjectCallable()

public final UnaryCallable<DeleteObjectRequest,Empty> deleteObjectCallable()

Deletes an object and its metadata. Deletions are permanent if versioning is not enabled for the bucket, or if the generation parameter is used.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   DeleteObjectRequest request =
       DeleteObjectRequest.newBuilder()
           .setBucket("bucket-1378203158")
           .setObject("object-1023368385")
           .setUploadId("uploadId1563990780")
           .setGeneration(305703192)
           .setIfGenerationMatch(-1086241088)
           .setIfGenerationNotMatch(1475720404)
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture<Empty> future = storageClient.deleteObjectCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<DeleteObjectRequest,Empty>

getBucket(BucketName name)

public final Bucket getBucket(BucketName name)

Returns metadata for the specified bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   BucketName name = BucketName.of("[PROJECT]", "[BUCKET]");
   Bucket response = storageClient.getBucket(name);
 }
 
Parameter
NameDescription
nameBucketName

Required. Name of a bucket.

Returns
TypeDescription
Bucket

getBucket(GetBucketRequest request)

public final Bucket getBucket(GetBucketRequest request)

Returns metadata for the specified bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   GetBucketRequest request =
       GetBucketRequest.newBuilder()
           .setName(BucketName.of("[PROJECT]", "[BUCKET]").toString())
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .setReadMask(FieldMask.newBuilder().build())
           .build();
   Bucket response = storageClient.getBucket(request);
 }
 
Parameter
NameDescription
requestGetBucketRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Bucket

getBucket(String name)

public final Bucket getBucket(String name)

Returns metadata for the specified bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String name = BucketName.of("[PROJECT]", "[BUCKET]").toString();
   Bucket response = storageClient.getBucket(name);
 }
 
Parameter
NameDescription
nameString

Required. Name of a bucket.

Returns
TypeDescription
Bucket

getBucketCallable()

public final UnaryCallable<GetBucketRequest,Bucket> getBucketCallable()

Returns metadata for the specified bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   GetBucketRequest request =
       GetBucketRequest.newBuilder()
           .setName(BucketName.of("[PROJECT]", "[BUCKET]").toString())
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .setReadMask(FieldMask.newBuilder().build())
           .build();
   ApiFuture<Bucket> future = storageClient.getBucketCallable().futureCall(request);
   // Do something.
   Bucket response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetBucketRequest,Bucket>

getHmacKey(GetHmacKeyRequest request)

public final HmacKeyMetadata getHmacKey(GetHmacKeyRequest request)

Gets an existing HMAC key metadata for the given id.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   GetHmacKeyRequest request =
       GetHmacKeyRequest.newBuilder()
           .setAccessId("accessId-2146437729")
           .setProject(ProjectName.of("[PROJECT]").toString())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   HmacKeyMetadata response = storageClient.getHmacKey(request);
 }
 
Parameter
NameDescription
requestGetHmacKeyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
HmacKeyMetadata

getHmacKey(String accessId, ProjectName project)

public final HmacKeyMetadata getHmacKey(String accessId, ProjectName project)

Gets an existing HMAC key metadata for the given id.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String accessId = "accessId-2146437729";
   ProjectName project = ProjectName.of("[PROJECT]");
   HmacKeyMetadata response = storageClient.getHmacKey(accessId, project);
 }
 
Parameters
NameDescription
accessIdString

Required. The identifying key for the HMAC to delete.

projectProjectName

Required. The project id the HMAC key lies in.

Returns
TypeDescription
HmacKeyMetadata

getHmacKey(String accessId, String project)

public final HmacKeyMetadata getHmacKey(String accessId, String project)

Gets an existing HMAC key metadata for the given id.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String accessId = "accessId-2146437729";
   String project = ProjectName.of("[PROJECT]").toString();
   HmacKeyMetadata response = storageClient.getHmacKey(accessId, project);
 }
 
Parameters
NameDescription
accessIdString

Required. The identifying key for the HMAC to delete.

projectString

Required. The project id the HMAC key lies in.

Returns
TypeDescription
HmacKeyMetadata

getHmacKeyCallable()

public final UnaryCallable<GetHmacKeyRequest,HmacKeyMetadata> getHmacKeyCallable()

Gets an existing HMAC key metadata for the given id.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   GetHmacKeyRequest request =
       GetHmacKeyRequest.newBuilder()
           .setAccessId("accessId-2146437729")
           .setProject(ProjectName.of("[PROJECT]").toString())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture
Returns
TypeDescription
UnaryCallable<GetHmacKeyRequest,HmacKeyMetadata>

getIamPolicy(ResourceName resource)

public final Policy getIamPolicy(ResourceName resource)

Gets the IAM policy for a specified bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ResourceName resource =
       CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
   Policy response = storageClient.getIamPolicy(resource);
 }
 
Parameter
NameDescription
resourcecom.google.api.resourcenames.ResourceName

REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

Returns
TypeDescription
com.google.iam.v1.Policy

getIamPolicy(GetIamPolicyRequest request)

public final Policy getIamPolicy(GetIamPolicyRequest request)

Gets the IAM policy for a specified bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   GetIamPolicyRequest request =
       GetIamPolicyRequest.newBuilder()
           .setResource(
               CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")
                   .toString())
           .setOptions(GetPolicyOptions.newBuilder().build())
           .build();
   Policy response = storageClient.getIamPolicy(request);
 }
 
Parameter
NameDescription
requestcom.google.iam.v1.GetIamPolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
com.google.iam.v1.Policy

getIamPolicy(String resource)

public final Policy getIamPolicy(String resource)

Gets the IAM policy for a specified bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String resource =
       CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString();
   Policy response = storageClient.getIamPolicy(resource);
 }
 
Parameter
NameDescription
resourceString

REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

Returns
TypeDescription
com.google.iam.v1.Policy

getIamPolicyCallable()

public final UnaryCallable<GetIamPolicyRequest,Policy> getIamPolicyCallable()

Gets the IAM policy for a specified bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   GetIamPolicyRequest request =
       GetIamPolicyRequest.newBuilder()
           .setResource(
               CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")
                   .toString())
           .setOptions(GetPolicyOptions.newBuilder().build())
           .build();
   ApiFuture<Policy> future = storageClient.getIamPolicyCallable().futureCall(request);
   // Do something.
   Policy response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy>

getNotification(BucketName name)

public final Notification getNotification(BucketName name)

View a notification config.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   BucketName name = BucketName.of("[PROJECT]", "[BUCKET]");
   Notification response = storageClient.getNotification(name);
 }
 
Parameter
NameDescription
nameBucketName

Required. The parent bucket of the notification. Format: projects/{project}/buckets/{bucket}/notificationConfigs/{notification}

Returns
TypeDescription
Notification

getNotification(GetNotificationRequest request)

public final Notification getNotification(GetNotificationRequest request)

View a notification config.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   GetNotificationRequest request =
       GetNotificationRequest.newBuilder()
           .setName(BucketName.of("[PROJECT]", "[BUCKET]").toString())
           .build();
   Notification response = storageClient.getNotification(request);
 }
 
Parameter
NameDescription
requestGetNotificationRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Notification

getNotification(String name)

public final Notification getNotification(String name)

View a notification config.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String name = BucketName.of("[PROJECT]", "[BUCKET]").toString();
   Notification response = storageClient.getNotification(name);
 }
 
Parameter
NameDescription
nameString

Required. The parent bucket of the notification. Format: projects/{project}/buckets/{bucket}/notificationConfigs/{notification}

Returns
TypeDescription
Notification

getNotificationCallable()

public final UnaryCallable<GetNotificationRequest,Notification> getNotificationCallable()

View a notification config.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   GetNotificationRequest request =
       GetNotificationRequest.newBuilder()
           .setName(BucketName.of("[PROJECT]", "[BUCKET]").toString())
           .build();
   ApiFuture<Notification> future = storageClient.getNotificationCallable().futureCall(request);
   // Do something.
   Notification response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetNotificationRequest,Notification>

getObject(GetObjectRequest request)

public final Object getObject(GetObjectRequest request)

Retrieves an object's metadata.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   GetObjectRequest request =
       GetObjectRequest.newBuilder()
           .setBucket("bucket-1378203158")
           .setObject("object-1023368385")
           .setGeneration(305703192)
           .setIfGenerationMatch(-1086241088)
           .setIfGenerationNotMatch(1475720404)
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .setReadMask(FieldMask.newBuilder().build())
           .build();
   Object response = storageClient.getObject(request);
 }
 
Parameter
NameDescription
requestGetObjectRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Object

getObject(String bucket, String object)

public final Object getObject(String bucket, String object)

Retrieves an object's metadata.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String bucket = "bucket-1378203158";
   String object = "object-1023368385";
   Object response = storageClient.getObject(bucket, object);
 }
 
Parameters
NameDescription
bucketString

Required. Name of the bucket in which the object resides.

objectString

Required. Name of the object.

Returns
TypeDescription
Object

getObject(String bucket, String object, long generation)

public final Object getObject(String bucket, String object, long generation)

Retrieves an object's metadata.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String bucket = "bucket-1378203158";
   String object = "object-1023368385";
   long generation = 305703192;
   Object response = storageClient.getObject(bucket, object, generation);
 }
 
Parameters
NameDescription
bucketString

Required. Name of the bucket in which the object resides.

objectString

Required. Name of the object.

generationlong

If present, selects a specific revision of this object (as opposed to the latest version, the default).

Returns
TypeDescription
Object

getObjectCallable()

public final UnaryCallable<GetObjectRequest,Object> getObjectCallable()

Retrieves an object's metadata.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   GetObjectRequest request =
       GetObjectRequest.newBuilder()
           .setBucket("bucket-1378203158")
           .setObject("object-1023368385")
           .setGeneration(305703192)
           .setIfGenerationMatch(-1086241088)
           .setIfGenerationNotMatch(1475720404)
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .setReadMask(FieldMask.newBuilder().build())
           .build();
   ApiFuture<Object> future = storageClient.getObjectCallable().futureCall(request);
   // Do something.
   Object response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetObjectRequest,Object>

getServiceAccount(GetServiceAccountRequest request)

public final ServiceAccount getServiceAccount(GetServiceAccountRequest request)

Retrieves the name of a project's Google Cloud Storage service account.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   GetServiceAccountRequest request =
       GetServiceAccountRequest.newBuilder()
           .setProject(ProjectName.of("[PROJECT]").toString())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ServiceAccount response = storageClient.getServiceAccount(request);
 }
 
Parameter
NameDescription
requestGetServiceAccountRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
ServiceAccount

getServiceAccount(ProjectName project)

public final ServiceAccount getServiceAccount(ProjectName project)

Retrieves the name of a project's Google Cloud Storage service account.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ProjectName project = ProjectName.of("[PROJECT]");
   ServiceAccount response = storageClient.getServiceAccount(project);
 }
 
Parameter
NameDescription
projectProjectName

Required. Project ID.

Returns
TypeDescription
ServiceAccount

getServiceAccount(String project)

public final ServiceAccount getServiceAccount(String project)

Retrieves the name of a project's Google Cloud Storage service account.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String project = ProjectName.of("[PROJECT]").toString();
   ServiceAccount response = storageClient.getServiceAccount(project);
 }
 
Parameter
NameDescription
projectString

Required. Project ID.

Returns
TypeDescription
ServiceAccount

getServiceAccountCallable()

public final UnaryCallable<GetServiceAccountRequest,ServiceAccount> getServiceAccountCallable()

Retrieves the name of a project's Google Cloud Storage service account.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   GetServiceAccountRequest request =
       GetServiceAccountRequest.newBuilder()
           .setProject(ProjectName.of("[PROJECT]").toString())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture
Returns
TypeDescription
UnaryCallable<GetServiceAccountRequest,ServiceAccount>

getSettings()

public final StorageSettings getSettings()
Returns
TypeDescription
StorageSettings

getStub()

public StorageStub getStub()
Returns
TypeDescription
StorageStub

isShutdown()

public boolean isShutdown()
Returns
TypeDescription
boolean

isTerminated()

public boolean isTerminated()
Returns
TypeDescription
boolean

listBuckets(ListBucketsRequest request)

public final StorageClient.ListBucketsPagedResponse listBuckets(ListBucketsRequest request)

Retrieves a list of buckets for a given project.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ListBucketsRequest request =
       ListBucketsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setPrefix("prefix-980110702")
           .setReadMask(FieldMask.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   for (Bucket element : storageClient.listBuckets(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListBucketsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
StorageClient.ListBucketsPagedResponse

listBuckets(ProjectName parent)

public final StorageClient.ListBucketsPagedResponse listBuckets(ProjectName parent)

Retrieves a list of buckets for a given project.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ProjectName parent = ProjectName.of("[PROJECT]");
   for (Bucket element : storageClient.listBuckets(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentProjectName

Required. The project whose buckets we are listing.

Returns
TypeDescription
StorageClient.ListBucketsPagedResponse

listBuckets(String parent)

public final StorageClient.ListBucketsPagedResponse listBuckets(String parent)

Retrieves a list of buckets for a given project.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String parent = ProjectName.of("[PROJECT]").toString();
   for (Bucket element : storageClient.listBuckets(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. The project whose buckets we are listing.

Returns
TypeDescription
StorageClient.ListBucketsPagedResponse

listBucketsCallable()

public final UnaryCallable<ListBucketsRequest,ListBucketsResponse> listBucketsCallable()

Retrieves a list of buckets for a given project.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ListBucketsRequest request =
       ListBucketsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setPrefix("prefix-980110702")
           .setReadMask(FieldMask.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   while (true) {
     ListBucketsResponse response = storageClient.listBucketsCallable().call(request);
     for (Bucket element : response.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListBucketsRequest,ListBucketsResponse>

listBucketsPagedCallable()

public final UnaryCallable<ListBucketsRequest,StorageClient.ListBucketsPagedResponse> listBucketsPagedCallable()

Retrieves a list of buckets for a given project.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ListBucketsRequest request =
       ListBucketsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setPrefix("prefix-980110702")
           .setReadMask(FieldMask.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture<Bucket> future = storageClient.listBucketsPagedCallable().futureCall(request);
   // Do something.
   for (Bucket element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListBucketsRequest,ListBucketsPagedResponse>

listHmacKeys(ListHmacKeysRequest request)

public final StorageClient.ListHmacKeysPagedResponse listHmacKeys(ListHmacKeysRequest request)

Lists HMAC keys under a given project with the additional filters provided.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ListHmacKeysRequest request =
       ListHmacKeysRequest.newBuilder()
           .setProject(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setServiceAccountEmail("serviceAccountEmail1825953988")
           .setShowDeletedKeys(true)
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   for (HmacKeyMetadata element : storageClient.listHmacKeys(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListHmacKeysRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
StorageClient.ListHmacKeysPagedResponse

listHmacKeys(ProjectName project)

public final StorageClient.ListHmacKeysPagedResponse listHmacKeys(ProjectName project)

Lists HMAC keys under a given project with the additional filters provided.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ProjectName project = ProjectName.of("[PROJECT]");
   for (HmacKeyMetadata element : storageClient.listHmacKeys(project).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
projectProjectName

Required. The project id to list HMAC keys for.

Returns
TypeDescription
StorageClient.ListHmacKeysPagedResponse

listHmacKeys(String project)

public final StorageClient.ListHmacKeysPagedResponse listHmacKeys(String project)

Lists HMAC keys under a given project with the additional filters provided.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String project = ProjectName.of("[PROJECT]").toString();
   for (HmacKeyMetadata element : storageClient.listHmacKeys(project).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
projectString

Required. The project id to list HMAC keys for.

Returns
TypeDescription
StorageClient.ListHmacKeysPagedResponse

listHmacKeysCallable()

public final UnaryCallable<ListHmacKeysRequest,ListHmacKeysResponse> listHmacKeysCallable()

Lists HMAC keys under a given project with the additional filters provided.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ListHmacKeysRequest request =
       ListHmacKeysRequest.newBuilder()
           .setProject(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setServiceAccountEmail("serviceAccountEmail1825953988")
           .setShowDeletedKeys(true)
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   while (true) {
     ListHmacKeysResponse response = storageClient.listHmacKeysCallable().call(request);
     for (HmacKeyMetadata element : response.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListHmacKeysRequest,ListHmacKeysResponse>

listHmacKeysPagedCallable()

public final UnaryCallable<ListHmacKeysRequest,StorageClient.ListHmacKeysPagedResponse> listHmacKeysPagedCallable()

Lists HMAC keys under a given project with the additional filters provided.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ListHmacKeysRequest request =
       ListHmacKeysRequest.newBuilder()
           .setProject(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setServiceAccountEmail("serviceAccountEmail1825953988")
           .setShowDeletedKeys(true)
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture
Returns
TypeDescription
UnaryCallable<ListHmacKeysRequest,ListHmacKeysPagedResponse>

listNotifications(ListNotificationsRequest request)

public final StorageClient.ListNotificationsPagedResponse listNotifications(ListNotificationsRequest request)

Retrieves a list of notification subscriptions for a given bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ListNotificationsRequest request =
       ListNotificationsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (Notification element : storageClient.listNotifications(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListNotificationsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
StorageClient.ListNotificationsPagedResponse

listNotifications(ProjectName parent)

public final StorageClient.ListNotificationsPagedResponse listNotifications(ProjectName parent)

Retrieves a list of notification subscriptions for a given bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ProjectName parent = ProjectName.of("[PROJECT]");
   for (Notification element : storageClient.listNotifications(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentProjectName

Required. Name of a Google Cloud Storage bucket.

Returns
TypeDescription
StorageClient.ListNotificationsPagedResponse

listNotifications(String parent)

public final StorageClient.ListNotificationsPagedResponse listNotifications(String parent)

Retrieves a list of notification subscriptions for a given bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String parent = ProjectName.of("[PROJECT]").toString();
   for (Notification element : storageClient.listNotifications(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. Name of a Google Cloud Storage bucket.

Returns
TypeDescription
StorageClient.ListNotificationsPagedResponse

listNotificationsCallable()

public final UnaryCallable<ListNotificationsRequest,ListNotificationsResponse> listNotificationsCallable()

Retrieves a list of notification subscriptions for a given bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ListNotificationsRequest request =
       ListNotificationsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   while (true) {
     ListNotificationsResponse response =
         storageClient.listNotificationsCallable().call(request);
     for (Notification element : response.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListNotificationsRequest,ListNotificationsResponse>

listNotificationsPagedCallable()

public final UnaryCallable<ListNotificationsRequest,StorageClient.ListNotificationsPagedResponse> listNotificationsPagedCallable()

Retrieves a list of notification subscriptions for a given bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ListNotificationsRequest request =
       ListNotificationsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<Notification> future =
       storageClient.listNotificationsPagedCallable().futureCall(request);
   // Do something.
   for (Notification element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListNotificationsRequest,ListNotificationsPagedResponse>

listObjects(ListObjectsRequest request)

public final StorageClient.ListObjectsPagedResponse listObjects(ListObjectsRequest request)

Retrieves a list of objects matching the criteria.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ListObjectsRequest request =
       ListObjectsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setDelimiter("delimiter-250518009")
           .setIncludeTrailingDelimiter(true)
           .setPrefix("prefix-980110702")
           .setVersions(true)
           .setReadMask(FieldMask.newBuilder().build())
           .setLexicographicStart("lexicographicStart-2093413008")
           .setLexicographicEnd("lexicographicEnd1646968169")
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   for (Object element : storageClient.listObjects(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListObjectsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
StorageClient.ListObjectsPagedResponse

listObjects(ProjectName parent)

public final StorageClient.ListObjectsPagedResponse listObjects(ProjectName parent)

Retrieves a list of objects matching the criteria.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ProjectName parent = ProjectName.of("[PROJECT]");
   for (Object element : storageClient.listObjects(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentProjectName

Required. Name of the bucket in which to look for objects.

Returns
TypeDescription
StorageClient.ListObjectsPagedResponse

listObjects(String parent)

public final StorageClient.ListObjectsPagedResponse listObjects(String parent)

Retrieves a list of objects matching the criteria.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String parent = ProjectName.of("[PROJECT]").toString();
   for (Object element : storageClient.listObjects(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. Name of the bucket in which to look for objects.

Returns
TypeDescription
StorageClient.ListObjectsPagedResponse

listObjectsCallable()

public final UnaryCallable<ListObjectsRequest,ListObjectsResponse> listObjectsCallable()

Retrieves a list of objects matching the criteria.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ListObjectsRequest request =
       ListObjectsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setDelimiter("delimiter-250518009")
           .setIncludeTrailingDelimiter(true)
           .setPrefix("prefix-980110702")
           .setVersions(true)
           .setReadMask(FieldMask.newBuilder().build())
           .setLexicographicStart("lexicographicStart-2093413008")
           .setLexicographicEnd("lexicographicEnd1646968169")
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   while (true) {
     ListObjectsResponse response = storageClient.listObjectsCallable().call(request);
     for (Object element : response.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListObjectsRequest,ListObjectsResponse>

listObjectsPagedCallable()

public final UnaryCallable<ListObjectsRequest,StorageClient.ListObjectsPagedResponse> listObjectsPagedCallable()

Retrieves a list of objects matching the criteria.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ListObjectsRequest request =
       ListObjectsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setDelimiter("delimiter-250518009")
           .setIncludeTrailingDelimiter(true)
           .setPrefix("prefix-980110702")
           .setVersions(true)
           .setReadMask(FieldMask.newBuilder().build())
           .setLexicographicStart("lexicographicStart-2093413008")
           .setLexicographicEnd("lexicographicEnd1646968169")
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture<Object> future = storageClient.listObjectsPagedCallable().futureCall(request);
   // Do something.
   for (Object element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListObjectsRequest,ListObjectsPagedResponse>

lockBucketRetentionPolicy(BucketName bucket)

public final Bucket lockBucketRetentionPolicy(BucketName bucket)

Locks retention policy on a bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   BucketName bucket = BucketName.of("[PROJECT]", "[BUCKET]");
   Bucket response = storageClient.lockBucketRetentionPolicy(bucket);
 }
 
Parameter
NameDescription
bucketBucketName

Required. Name of a bucket.

Returns
TypeDescription
Bucket

lockBucketRetentionPolicy(LockBucketRetentionPolicyRequest request)

public final Bucket lockBucketRetentionPolicy(LockBucketRetentionPolicyRequest request)

Locks retention policy on a bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   LockBucketRetentionPolicyRequest request =
       LockBucketRetentionPolicyRequest.newBuilder()
           .setBucket(BucketName.of("[PROJECT]", "[BUCKET]").toString())
           .setIfMetagenerationMatch(1043427781)
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   Bucket response = storageClient.lockBucketRetentionPolicy(request);
 }
 
Parameter
NameDescription
requestLockBucketRetentionPolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Bucket

lockBucketRetentionPolicy(String bucket)

public final Bucket lockBucketRetentionPolicy(String bucket)

Locks retention policy on a bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String bucket = BucketName.of("[PROJECT]", "[BUCKET]").toString();
   Bucket response = storageClient.lockBucketRetentionPolicy(bucket);
 }
 
Parameter
NameDescription
bucketString

Required. Name of a bucket.

Returns
TypeDescription
Bucket

lockBucketRetentionPolicyCallable()

public final UnaryCallable<LockBucketRetentionPolicyRequest,Bucket> lockBucketRetentionPolicyCallable()

Locks retention policy on a bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   LockBucketRetentionPolicyRequest request =
       LockBucketRetentionPolicyRequest.newBuilder()
           .setBucket(BucketName.of("[PROJECT]", "[BUCKET]").toString())
           .setIfMetagenerationMatch(1043427781)
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture<Bucket> future =
       storageClient.lockBucketRetentionPolicyCallable().futureCall(request);
   // Do something.
   Bucket response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<LockBucketRetentionPolicyRequest,Bucket>

queryWriteStatus(QueryWriteStatusRequest request)

public final QueryWriteStatusResponse queryWriteStatus(QueryWriteStatusRequest request)

Determines the persisted_size for an object that is being written, which can then be used as the write_offset for the next Write() call.

If the object does not exist (i.e., the object has been deleted, or the first Write() has not yet reached the service), this method returns the error NOT_FOUND.

The client **may** call QueryWriteStatus() at any time to determine how much data has been processed for this object. This is useful if the client is buffering data and needs to know which data can be safely evicted. For any sequence of QueryWriteStatus() calls for a given object name, the sequence of returned persisted_size values will be non-decreasing.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   QueryWriteStatusRequest request =
       QueryWriteStatusRequest.newBuilder()
           .setUploadId("uploadId1563990780")
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   QueryWriteStatusResponse response = storageClient.queryWriteStatus(request);
 }
 
Parameter
NameDescription
requestQueryWriteStatusRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
QueryWriteStatusResponse

queryWriteStatus(String uploadId)

public final QueryWriteStatusResponse queryWriteStatus(String uploadId)

Determines the persisted_size for an object that is being written, which can then be used as the write_offset for the next Write() call.

If the object does not exist (i.e., the object has been deleted, or the first Write() has not yet reached the service), this method returns the error NOT_FOUND.

The client **may** call QueryWriteStatus() at any time to determine how much data has been processed for this object. This is useful if the client is buffering data and needs to know which data can be safely evicted. For any sequence of QueryWriteStatus() calls for a given object name, the sequence of returned persisted_size values will be non-decreasing.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String uploadId = "uploadId1563990780";
   QueryWriteStatusResponse response = storageClient.queryWriteStatus(uploadId);
 }
 
Parameter
NameDescription
uploadIdString

Required. The name of the resume token for the object whose write status is being requested.

Returns
TypeDescription
QueryWriteStatusResponse

queryWriteStatusCallable()

public final UnaryCallable<QueryWriteStatusRequest,QueryWriteStatusResponse> queryWriteStatusCallable()

Determines the persisted_size for an object that is being written, which can then be used as the write_offset for the next Write() call.

If the object does not exist (i.e., the object has been deleted, or the first Write() has not yet reached the service), this method returns the error NOT_FOUND.

The client **may** call QueryWriteStatus() at any time to determine how much data has been processed for this object. This is useful if the client is buffering data and needs to know which data can be safely evicted. For any sequence of QueryWriteStatus() calls for a given object name, the sequence of returned persisted_size values will be non-decreasing.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   QueryWriteStatusRequest request =
       QueryWriteStatusRequest.newBuilder()
           .setUploadId("uploadId1563990780")
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture
Returns
TypeDescription
UnaryCallable<QueryWriteStatusRequest,QueryWriteStatusResponse>

readObjectCallable()

public final ServerStreamingCallable<ReadObjectRequest,ReadObjectResponse> readObjectCallable()

Reads an object's data.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ReadObjectRequest request =
       ReadObjectRequest.newBuilder()
           .setBucket("bucket-1378203158")
           .setObject("object-1023368385")
           .setGeneration(305703192)
           .setReadOffset(-715377828)
           .setReadLimit(-164298798)
           .setIfGenerationMatch(-1086241088)
           .setIfGenerationNotMatch(1475720404)
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .setReadMask(FieldMask.newBuilder().build())
           .build();
   ServerStream
Returns
TypeDescription
ServerStreamingCallable<ReadObjectRequest,ReadObjectResponse>

rewriteObject(RewriteObjectRequest request)

public final RewriteResponse rewriteObject(RewriteObjectRequest request)

Rewrites a source object to a destination object. Optionally overrides metadata.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   RewriteObjectRequest request =
       RewriteObjectRequest.newBuilder()
           .setDestinationName("destinationName-1762755655")
           .setDestinationBucket(BucketName.of("[PROJECT]", "[BUCKET]").toString())
           .setDestinationKmsKey(
               CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")
                   .toString())
           .setDestination(Object.newBuilder().build())
           .setSourceBucket("sourceBucket841604581")
           .setSourceObject("sourceObject1196439354")
           .setSourceGeneration(1232209852)
           .setRewriteToken("rewriteToken80654285")
           .setDestinationPredefinedAcl(PredefinedObjectAcl.forNumber(0))
           .setIfGenerationMatch(-1086241088)
           .setIfGenerationNotMatch(1475720404)
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setIfSourceGenerationMatch(-1427877280)
           .setIfSourceGenerationNotMatch(1575612532)
           .setIfSourceMetagenerationMatch(1143319909)
           .setIfSourceMetagenerationNotMatch(1900822777)
           .setMaxBytesRewrittenPerCall(1178170730)
           .setCopySourceEncryptionAlgorithm("copySourceEncryptionAlgorithm-1524952548")
           .setCopySourceEncryptionKeyBytes(ByteString.EMPTY)
           .setCopySourceEncryptionKeySha256Bytes(ByteString.EMPTY)
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   RewriteResponse response = storageClient.rewriteObject(request);
 }
 
Parameter
NameDescription
requestRewriteObjectRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
RewriteResponse

rewriteObjectCallable()

public final UnaryCallable<RewriteObjectRequest,RewriteResponse> rewriteObjectCallable()

Rewrites a source object to a destination object. Optionally overrides metadata.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   RewriteObjectRequest request =
       RewriteObjectRequest.newBuilder()
           .setDestinationName("destinationName-1762755655")
           .setDestinationBucket(BucketName.of("[PROJECT]", "[BUCKET]").toString())
           .setDestinationKmsKey(
               CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")
                   .toString())
           .setDestination(Object.newBuilder().build())
           .setSourceBucket("sourceBucket841604581")
           .setSourceObject("sourceObject1196439354")
           .setSourceGeneration(1232209852)
           .setRewriteToken("rewriteToken80654285")
           .setDestinationPredefinedAcl(PredefinedObjectAcl.forNumber(0))
           .setIfGenerationMatch(-1086241088)
           .setIfGenerationNotMatch(1475720404)
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setIfSourceGenerationMatch(-1427877280)
           .setIfSourceGenerationNotMatch(1575612532)
           .setIfSourceMetagenerationMatch(1143319909)
           .setIfSourceMetagenerationNotMatch(1900822777)
           .setMaxBytesRewrittenPerCall(1178170730)
           .setCopySourceEncryptionAlgorithm("copySourceEncryptionAlgorithm-1524952548")
           .setCopySourceEncryptionKeyBytes(ByteString.EMPTY)
           .setCopySourceEncryptionKeySha256Bytes(ByteString.EMPTY)
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture
Returns
TypeDescription
UnaryCallable<RewriteObjectRequest,RewriteResponse>

setIamPolicy(ResourceName resource, Policy policy)

public final Policy setIamPolicy(ResourceName resource, Policy policy)

Updates an IAM policy for the specified bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ResourceName resource =
       CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
   Policy policy = Policy.newBuilder().build();
   Policy response = storageClient.setIamPolicy(resource, policy);
 }
 
Parameters
NameDescription
resourcecom.google.api.resourcenames.ResourceName

REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

policycom.google.iam.v1.Policy

REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.

Returns
TypeDescription
com.google.iam.v1.Policy

setIamPolicy(SetIamPolicyRequest request)

public final Policy setIamPolicy(SetIamPolicyRequest request)

Updates an IAM policy for the specified bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   SetIamPolicyRequest request =
       SetIamPolicyRequest.newBuilder()
           .setResource(
               CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")
                   .toString())
           .setPolicy(Policy.newBuilder().build())
           .build();
   Policy response = storageClient.setIamPolicy(request);
 }
 
Parameter
NameDescription
requestcom.google.iam.v1.SetIamPolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
com.google.iam.v1.Policy

setIamPolicy(String resource, Policy policy)

public final Policy setIamPolicy(String resource, Policy policy)

Updates an IAM policy for the specified bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String resource =
       CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString();
   Policy policy = Policy.newBuilder().build();
   Policy response = storageClient.setIamPolicy(resource, policy);
 }
 
Parameters
NameDescription
resourceString

REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

policycom.google.iam.v1.Policy

REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.

Returns
TypeDescription
com.google.iam.v1.Policy

setIamPolicyCallable()

public final UnaryCallable<SetIamPolicyRequest,Policy> setIamPolicyCallable()

Updates an IAM policy for the specified bucket.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   SetIamPolicyRequest request =
       SetIamPolicyRequest.newBuilder()
           .setResource(
               CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")
                   .toString())
           .setPolicy(Policy.newBuilder().build())
           .build();
   ApiFuture<Policy> future = storageClient.setIamPolicyCallable().futureCall(request);
   // Do something.
   Policy response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()

startResumableWrite(StartResumableWriteRequest request)

public final StartResumableWriteResponse startResumableWrite(StartResumableWriteRequest request)

Starts a resumable write. How long the write operation remains valid, and what happens when the write operation becomes invalid, are service-dependent.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   StartResumableWriteRequest request =
       StartResumableWriteRequest.newBuilder()
           .setWriteObjectSpec(WriteObjectSpec.newBuilder().build())
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   StartResumableWriteResponse response = storageClient.startResumableWrite(request);
 }
 
Parameter
NameDescription
requestStartResumableWriteRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
StartResumableWriteResponse

startResumableWriteCallable()

public final UnaryCallable<StartResumableWriteRequest,StartResumableWriteResponse> startResumableWriteCallable()

Starts a resumable write. How long the write operation remains valid, and what happens when the write operation becomes invalid, are service-dependent.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   StartResumableWriteRequest request =
       StartResumableWriteRequest.newBuilder()
           .setWriteObjectSpec(WriteObjectSpec.newBuilder().build())
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture
Returns
TypeDescription
UnaryCallable<StartResumableWriteRequest,StartResumableWriteResponse>

testIamPermissions(ResourceName resource, List<String> permissions)

public final TestIamPermissionsResponse testIamPermissions(ResourceName resource, List<String> permissions)

Tests a set of permissions on the given bucket to see which, if any, are held by the caller.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ResourceName resource =
       CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
   List<String> permissions = new ArrayList<>();
   TestIamPermissionsResponse response = storageClient.testIamPermissions(resource, permissions);
 }
 
Parameters
NameDescription
resourcecom.google.api.resourcenames.ResourceName

REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.

permissionsList<String>

The set of permissions to check for the resource. Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see IAM Overview.

Returns
TypeDescription
com.google.iam.v1.TestIamPermissionsResponse

testIamPermissions(TestIamPermissionsRequest request)

public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsRequest request)

Tests a set of permissions on the given bucket to see which, if any, are held by the caller.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   TestIamPermissionsRequest request =
       TestIamPermissionsRequest.newBuilder()
           .setResource(
               CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")
                   .toString())
           .addAllPermissions(new ArrayList<String>())
           .build();
   TestIamPermissionsResponse response = storageClient.testIamPermissions(request);
 }
 
Parameter
NameDescription
requestcom.google.iam.v1.TestIamPermissionsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
com.google.iam.v1.TestIamPermissionsResponse

testIamPermissions(String resource, List<String> permissions)

public final TestIamPermissionsResponse testIamPermissions(String resource, List<String> permissions)

Tests a set of permissions on the given bucket to see which, if any, are held by the caller.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   String resource =
       CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString();
   List<String> permissions = new ArrayList<>();
   TestIamPermissionsResponse response = storageClient.testIamPermissions(resource, permissions);
 }
 
Parameters
NameDescription
resourceString

REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.

permissionsList<String>

The set of permissions to check for the resource. Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see IAM Overview.

Returns
TypeDescription
com.google.iam.v1.TestIamPermissionsResponse

testIamPermissionsCallable()

public final UnaryCallable<TestIamPermissionsRequest,TestIamPermissionsResponse> testIamPermissionsCallable()

Tests a set of permissions on the given bucket to see which, if any, are held by the caller.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   TestIamPermissionsRequest request =
       TestIamPermissionsRequest.newBuilder()
           .setResource(
               CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")
                   .toString())
           .addAllPermissions(new ArrayList<String>())
           .build();
   ApiFuture
Returns
TypeDescription
UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse>

updateBucket(Bucket bucket, FieldMask updateMask)

public final Bucket updateBucket(Bucket bucket, FieldMask updateMask)

Updates a bucket. Equivalent to JSON API's storage.buckets.patch method.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   Bucket bucket = Bucket.newBuilder().build();
   FieldMask updateMask = FieldMask.newBuilder().build();
   Bucket response = storageClient.updateBucket(bucket, updateMask);
 }
 
Parameters
NameDescription
bucketBucket

The bucket to update. The bucket's name field will be used to identify the bucket.

updateMaskFieldMask

List of fields to be updated.

To specify ALL fields, equivalent to the JSON API's "update" function, specify a single field with the value *. Note: not recommended. If a new field is introduced at a later time, an older client updating with the * may accidentally reset the new field's value.

Not specifying any fields is an error. Not specifying a field while setting that field to a non-default value is an error.

Returns
TypeDescription
Bucket

updateBucket(UpdateBucketRequest request)

public final Bucket updateBucket(UpdateBucketRequest request)

Updates a bucket. Equivalent to JSON API's storage.buckets.patch method.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   UpdateBucketRequest request =
       UpdateBucketRequest.newBuilder()
           .setBucket(Bucket.newBuilder().build())
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setPredefinedAcl(PredefinedBucketAcl.forNumber(0))
           .setPredefinedDefaultObjectAcl(PredefinedObjectAcl.forNumber(0))
           .setUpdateMask(FieldMask.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   Bucket response = storageClient.updateBucket(request);
 }
 
Parameter
NameDescription
requestUpdateBucketRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Bucket

updateBucketCallable()

public final UnaryCallable<UpdateBucketRequest,Bucket> updateBucketCallable()

Updates a bucket. Equivalent to JSON API's storage.buckets.patch method.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   UpdateBucketRequest request =
       UpdateBucketRequest.newBuilder()
           .setBucket(Bucket.newBuilder().build())
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setPredefinedAcl(PredefinedBucketAcl.forNumber(0))
           .setPredefinedDefaultObjectAcl(PredefinedObjectAcl.forNumber(0))
           .setUpdateMask(FieldMask.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture<Bucket> future = storageClient.updateBucketCallable().futureCall(request);
   // Do something.
   Bucket response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<UpdateBucketRequest,Bucket>

updateHmacKey(HmacKeyMetadata hmacKey, FieldMask updateMask)

public final HmacKeyMetadata updateHmacKey(HmacKeyMetadata hmacKey, FieldMask updateMask)

Updates a given HMAC key state between ACTIVE and INACTIVE.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   HmacKeyMetadata hmacKey = HmacKeyMetadata.newBuilder().build();
   FieldMask updateMask = FieldMask.newBuilder().build();
   HmacKeyMetadata response = storageClient.updateHmacKey(hmacKey, updateMask);
 }
 
Parameters
NameDescription
hmacKeyHmacKeyMetadata

Required. The HMAC key to update. If present, the hmac_key's id field will be used to identify the key. Otherwise, the hmac_key's access_id and project fields will be used to identify the key.

updateMaskFieldMask

Update mask for hmac_key.

Returns
TypeDescription
HmacKeyMetadata

updateHmacKey(UpdateHmacKeyRequest request)

public final HmacKeyMetadata updateHmacKey(UpdateHmacKeyRequest request)

Updates a given HMAC key state between ACTIVE and INACTIVE.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   UpdateHmacKeyRequest request =
       UpdateHmacKeyRequest.newBuilder()
           .setHmacKey(HmacKeyMetadata.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   HmacKeyMetadata response = storageClient.updateHmacKey(request);
 }
 
Parameter
NameDescription
requestUpdateHmacKeyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
HmacKeyMetadata

updateHmacKeyCallable()

public final UnaryCallable<UpdateHmacKeyRequest,HmacKeyMetadata> updateHmacKeyCallable()

Updates a given HMAC key state between ACTIVE and INACTIVE.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   UpdateHmacKeyRequest request =
       UpdateHmacKeyRequest.newBuilder()
           .setHmacKey(HmacKeyMetadata.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   ApiFuture
Returns
TypeDescription
UnaryCallable<UpdateHmacKeyRequest,HmacKeyMetadata>

updateObject(Object object, FieldMask updateMask)

public final Object updateObject(Object object, FieldMask updateMask)

Updates an object's metadata. Equivalent to JSON API's storage.objects.patch.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   Object object = Object.newBuilder().build();
   FieldMask updateMask = FieldMask.newBuilder().build();
   Object response = storageClient.updateObject(object, updateMask);
 }
 
Parameters
NameDescription
objectObject

The object to update. The object's bucket and name fields are used to identify the object to update. If present, the object's generation field selects a specific revision of this object whose metadata should be updated. Otherwise, assumes the current, live version of the object.

updateMaskFieldMask

List of fields to be updated.

To specify ALL fields, equivalent to the JSON API's "update" function, specify a single field with the value *. Note: not recommended. If a new field is introduced at a later time, an older client updating with the * may accidentally reset the new field's value.

Not specifying any fields is an error. Not specifying a field while setting that field to a non-default value is an error.

Returns
TypeDescription
Object

updateObject(UpdateObjectRequest request)

public final Object updateObject(UpdateObjectRequest request)

Updates an object's metadata. Equivalent to JSON API's storage.objects.patch.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   UpdateObjectRequest request =
       UpdateObjectRequest.newBuilder()
           .setObject(Object.newBuilder().build())
           .setIfGenerationMatch(-1086241088)
           .setIfGenerationNotMatch(1475720404)
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setPredefinedAcl(PredefinedObjectAcl.forNumber(0))
           .setUpdateMask(FieldMask.newBuilder().build())
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   Object response = storageClient.updateObject(request);
 }
 
Parameter
NameDescription
requestUpdateObjectRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Object

updateObjectCallable()

public final UnaryCallable<UpdateObjectRequest,Object> updateObjectCallable()

Updates an object's metadata. Equivalent to JSON API's storage.objects.patch.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   UpdateObjectRequest request =
       UpdateObjectRequest.newBuilder()
           .setObject(Object.newBuilder().build())
           .setIfGenerationMatch(-1086241088)
           .setIfGenerationNotMatch(1475720404)
           .setIfMetagenerationMatch(1043427781)
           .setIfMetagenerationNotMatch(1025430873)
           .setPredefinedAcl(PredefinedObjectAcl.forNumber(0))
           .setUpdateMask(FieldMask.newBuilder().build())
           .setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build())
           .setCommonRequestParams(CommonRequestParams.newBuilder().build())
           .build();
   ApiFuture<Object> future = storageClient.updateObjectCallable().futureCall(request);
   // Do something.
   Object response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<UpdateObjectRequest,Object>

writeObjectCallable()

public final ClientStreamingCallable<WriteObjectRequest,WriteObjectResponse> writeObjectCallable()

Stores a new object and metadata.

An object can be written either in a single message stream or in a resumable sequence of message streams. To write using a single stream, the client should include in the first message of the stream an WriteObjectSpec describing the destination bucket, object, and any preconditions. Additionally, the final message must set 'finish_write' to true, or else it is an error.

For a resumable write, the client should instead call StartResumableWrite() and provide that method an WriteObjectSpec. They should then attach the returned upload_id to the first message of each following call to Create. If there is an error or the connection is broken during the resumable Create(), the client should check the status of the Create() by calling QueryWriteStatus() and continue writing from the returned persisted_size. This may be less than the amount of data the client previously sent.

The service will not view the object as complete until the client has sent a WriteObjectRequest with finish_write set to true. Sending any requests on a stream after sending a request with finish_write set to true will cause an error. The client **should** check the response it receives to determine how much data the service was able to commit and whether the service views the object as complete.

Sample code:


 try (StorageClient storageClient = StorageClient.create()) {
   ApiStreamObserver
Returns
TypeDescription
ClientStreamingCallable<WriteObjectRequest,WriteObjectResponse>