"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
+ *
+ *
listManagedFolders(BucketName parent)
+ *
listManagedFolders(String parent)
+ *
+ *
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
+ *
+ *
listManagedFoldersPagedCallable()
+ *
listManagedFoldersCallable()
+ *
+ *
+ *
*
*
*
See the individual methods for example code.
@@ -310,7 +387,10 @@ public final OperationsClient getOperationsClient() {
* @param folder Required. Properties of the new folder being created. The bucket and name of the
* folder are specified in the parent and folder_id fields, respectively. Populating those
* fields in `folder` will result in an error.
- * @param folderId Required. The absolute path of the folder, using a single `/` as delimiter.
+ * @param folderId Required. The full name of a folder, including all its parent folders. Folders
+ * use single '/' characters as a delimiter. The folder_id must end with a slash. For example,
+ * the folder_id of "books/biographies/" would create a new "biographies/" folder under the
+ * "books/" folder.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Folder createFolder(BucketName parent, Folder folder, String folderId) {
@@ -347,7 +427,10 @@ public final Folder createFolder(BucketName parent, Folder folder, String folder
* @param folder Required. Properties of the new folder being created. The bucket and name of the
* folder are specified in the parent and folder_id fields, respectively. Populating those
* fields in `folder` will result in an error.
- * @param folderId Required. The absolute path of the folder, using a single `/` as delimiter.
+ * @param folderId Required. The full name of a folder, including all its parent folders. Folders
+ * use single '/' characters as a delimiter. The folder_id must end with a slash. For example,
+ * the folder_id of "books/biographies/" would create a new "biographies/" folder under the
+ * "books/" folder.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Folder createFolder(String parent, Folder folder, String folderId) {
@@ -1117,6 +1200,560 @@ public final UnaryCallable getStorageLay
return stub.getStorageLayoutCallable();
}
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Creates a new managed folder.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * BucketName parent = BucketName.of("[PROJECT]", "[BUCKET]");
+ * ManagedFolder managedFolder = ManagedFolder.newBuilder().build();
+ * String managedFolderId = "managedFolderId-2027084056";
+ * ManagedFolder response =
+ * storageControlClient.createManagedFolder(parent, managedFolder, managedFolderId);
+ * }
+ * }
+ *
+ * @param parent Required. Name of the bucket this managed folder belongs to.
+ * @param managedFolder Required. Properties of the managed folder being created. The bucket and
+ * managed folder names are specified in the `parent` and `managed_folder_id` fields.
+ * Populating these fields in `managed_folder` will result in an error.
+ * @param managedFolderId Required. The name of the managed folder. It uses a single `/` as
+ * delimiter and leading and trailing `/` are allowed.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final ManagedFolder createManagedFolder(
+ BucketName parent, ManagedFolder managedFolder, String managedFolderId) {
+ CreateManagedFolderRequest request =
+ CreateManagedFolderRequest.newBuilder()
+ .setParent(parent == null ? null : parent.toString())
+ .setManagedFolder(managedFolder)
+ .setManagedFolderId(managedFolderId)
+ .build();
+ return createManagedFolder(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Creates a new managed folder.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * String parent = BucketName.of("[PROJECT]", "[BUCKET]").toString();
+ * ManagedFolder managedFolder = ManagedFolder.newBuilder().build();
+ * String managedFolderId = "managedFolderId-2027084056";
+ * ManagedFolder response =
+ * storageControlClient.createManagedFolder(parent, managedFolder, managedFolderId);
+ * }
+ * }
+ *
+ * @param parent Required. Name of the bucket this managed folder belongs to.
+ * @param managedFolder Required. Properties of the managed folder being created. The bucket and
+ * managed folder names are specified in the `parent` and `managed_folder_id` fields.
+ * Populating these fields in `managed_folder` will result in an error.
+ * @param managedFolderId Required. The name of the managed folder. It uses a single `/` as
+ * delimiter and leading and trailing `/` are allowed.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final ManagedFolder createManagedFolder(
+ String parent, ManagedFolder managedFolder, String managedFolderId) {
+ CreateManagedFolderRequest request =
+ CreateManagedFolderRequest.newBuilder()
+ .setParent(parent)
+ .setManagedFolder(managedFolder)
+ .setManagedFolderId(managedFolderId)
+ .build();
+ return createManagedFolder(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Creates a new managed folder.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * CreateManagedFolderRequest request =
+ * CreateManagedFolderRequest.newBuilder()
+ * .setParent(BucketName.of("[PROJECT]", "[BUCKET]").toString())
+ * .setManagedFolder(ManagedFolder.newBuilder().build())
+ * .setManagedFolderId("managedFolderId-2027084056")
+ * .setRequestId("requestId693933066")
+ * .build();
+ * ManagedFolder response = storageControlClient.createManagedFolder(request);
+ * }
+ * }
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final ManagedFolder createManagedFolder(CreateManagedFolderRequest request) {
+ return createManagedFolderCallable().call(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Creates a new managed folder.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * CreateManagedFolderRequest request =
+ * CreateManagedFolderRequest.newBuilder()
+ * .setParent(BucketName.of("[PROJECT]", "[BUCKET]").toString())
+ * .setManagedFolder(ManagedFolder.newBuilder().build())
+ * .setManagedFolderId("managedFolderId-2027084056")
+ * .setRequestId("requestId693933066")
+ * .build();
+ * ApiFuture future =
+ * storageControlClient.createManagedFolderCallable().futureCall(request);
+ * // Do something.
+ * ManagedFolder response = future.get();
+ * }
+ * }
+ */
+ public final UnaryCallable
+ createManagedFolderCallable() {
+ return stub.createManagedFolderCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Permanently deletes an empty managed folder.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * ManagedFolderName name = ManagedFolderName.of("[PROJECT]", "[BUCKET]", "[MANAGEDFOLDER]");
+ * storageControlClient.deleteManagedFolder(name);
+ * }
+ * }
+ *
+ * @param name Required. Name of the managed folder. Format:
+ * `projects/{project}/buckets/{bucket}/managedFolders/{managedFolder}`
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final void deleteManagedFolder(ManagedFolderName name) {
+ DeleteManagedFolderRequest request =
+ DeleteManagedFolderRequest.newBuilder()
+ .setName(name == null ? null : name.toString())
+ .build();
+ deleteManagedFolder(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Permanently deletes an empty managed folder.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * String name = ManagedFolderName.of("[PROJECT]", "[BUCKET]", "[MANAGEDFOLDER]").toString();
+ * storageControlClient.deleteManagedFolder(name);
+ * }
+ * }
+ *
+ * @param name Required. Name of the managed folder. Format:
+ * `projects/{project}/buckets/{bucket}/managedFolders/{managedFolder}`
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final void deleteManagedFolder(String name) {
+ DeleteManagedFolderRequest request =
+ DeleteManagedFolderRequest.newBuilder().setName(name).build();
+ deleteManagedFolder(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Permanently deletes an empty managed folder.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * DeleteManagedFolderRequest request =
+ * DeleteManagedFolderRequest.newBuilder()
+ * .setName(ManagedFolderName.of("[PROJECT]", "[BUCKET]", "[MANAGEDFOLDER]").toString())
+ * .setIfMetagenerationMatch(1043427781)
+ * .setIfMetagenerationNotMatch(1025430873)
+ * .setAllowNonEmpty(true)
+ * .setRequestId("requestId693933066")
+ * .build();
+ * storageControlClient.deleteManagedFolder(request);
+ * }
+ * }
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final void deleteManagedFolder(DeleteManagedFolderRequest request) {
+ deleteManagedFolderCallable().call(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Permanently deletes an empty managed folder.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * DeleteManagedFolderRequest request =
+ * DeleteManagedFolderRequest.newBuilder()
+ * .setName(ManagedFolderName.of("[PROJECT]", "[BUCKET]", "[MANAGEDFOLDER]").toString())
+ * .setIfMetagenerationMatch(1043427781)
+ * .setIfMetagenerationNotMatch(1025430873)
+ * .setAllowNonEmpty(true)
+ * .setRequestId("requestId693933066")
+ * .build();
+ * ApiFuture future =
+ * storageControlClient.deleteManagedFolderCallable().futureCall(request);
+ * // Do something.
+ * future.get();
+ * }
+ * }
+ */
+ public final UnaryCallable deleteManagedFolderCallable() {
+ return stub.deleteManagedFolderCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Returns metadata for the specified managed folder.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * ManagedFolderName name = ManagedFolderName.of("[PROJECT]", "[BUCKET]", "[MANAGEDFOLDER]");
+ * ManagedFolder response = storageControlClient.getManagedFolder(name);
+ * }
+ * }
+ *
+ * @param name Required. Name of the managed folder. Format:
+ * `projects/{project}/buckets/{bucket}/managedFolders/{managedFolder}`
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final ManagedFolder getManagedFolder(ManagedFolderName name) {
+ GetManagedFolderRequest request =
+ GetManagedFolderRequest.newBuilder().setName(name == null ? null : name.toString()).build();
+ return getManagedFolder(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Returns metadata for the specified managed folder.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * String name = ManagedFolderName.of("[PROJECT]", "[BUCKET]", "[MANAGEDFOLDER]").toString();
+ * ManagedFolder response = storageControlClient.getManagedFolder(name);
+ * }
+ * }
+ *
+ * @param name Required. Name of the managed folder. Format:
+ * `projects/{project}/buckets/{bucket}/managedFolders/{managedFolder}`
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final ManagedFolder getManagedFolder(String name) {
+ GetManagedFolderRequest request = GetManagedFolderRequest.newBuilder().setName(name).build();
+ return getManagedFolder(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Returns metadata for the specified managed folder.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * GetManagedFolderRequest request =
+ * GetManagedFolderRequest.newBuilder()
+ * .setName(ManagedFolderName.of("[PROJECT]", "[BUCKET]", "[MANAGEDFOLDER]").toString())
+ * .setIfMetagenerationMatch(1043427781)
+ * .setIfMetagenerationNotMatch(1025430873)
+ * .setRequestId("requestId693933066")
+ * .build();
+ * ManagedFolder response = storageControlClient.getManagedFolder(request);
+ * }
+ * }
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final ManagedFolder getManagedFolder(GetManagedFolderRequest request) {
+ return getManagedFolderCallable().call(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Returns metadata for the specified managed folder.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * GetManagedFolderRequest request =
+ * GetManagedFolderRequest.newBuilder()
+ * .setName(ManagedFolderName.of("[PROJECT]", "[BUCKET]", "[MANAGEDFOLDER]").toString())
+ * .setIfMetagenerationMatch(1043427781)
+ * .setIfMetagenerationNotMatch(1025430873)
+ * .setRequestId("requestId693933066")
+ * .build();
+ * ApiFuture future =
+ * storageControlClient.getManagedFolderCallable().futureCall(request);
+ * // Do something.
+ * ManagedFolder response = future.get();
+ * }
+ * }
+ */
+ public final UnaryCallable getManagedFolderCallable() {
+ return stub.getManagedFolderCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Retrieves a list of managed folders for a given bucket.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * BucketName parent = BucketName.of("[PROJECT]", "[BUCKET]");
+ * for (ManagedFolder element : storageControlClient.listManagedFolders(parent).iterateAll()) {
+ * // doThingsWith(element);
+ * }
+ * }
+ * }
+ *
+ * @param parent Required. Name of the bucket this managed folder belongs to.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final ListManagedFoldersPagedResponse listManagedFolders(BucketName parent) {
+ ListManagedFoldersRequest request =
+ ListManagedFoldersRequest.newBuilder()
+ .setParent(parent == null ? null : parent.toString())
+ .build();
+ return listManagedFolders(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Retrieves a list of managed folders for a given bucket.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * String parent = BucketName.of("[PROJECT]", "[BUCKET]").toString();
+ * for (ManagedFolder element : storageControlClient.listManagedFolders(parent).iterateAll()) {
+ * // doThingsWith(element);
+ * }
+ * }
+ * }
+ *
+ * @param parent Required. Name of the bucket this managed folder belongs to.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final ListManagedFoldersPagedResponse listManagedFolders(String parent) {
+ ListManagedFoldersRequest request =
+ ListManagedFoldersRequest.newBuilder().setParent(parent).build();
+ return listManagedFolders(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Retrieves a list of managed folders for a given bucket.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * ListManagedFoldersRequest request =
+ * ListManagedFoldersRequest.newBuilder()
+ * .setParent(BucketName.of("[PROJECT]", "[BUCKET]").toString())
+ * .setPageSize(883849137)
+ * .setPageToken("pageToken873572522")
+ * .setPrefix("prefix-980110702")
+ * .setRequestId("requestId693933066")
+ * .build();
+ * for (ManagedFolder element : storageControlClient.listManagedFolders(request).iterateAll()) {
+ * // doThingsWith(element);
+ * }
+ * }
+ * }
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final ListManagedFoldersPagedResponse listManagedFolders(
+ ListManagedFoldersRequest request) {
+ return listManagedFoldersPagedCallable().call(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Retrieves a list of managed folders for a given bucket.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * ListManagedFoldersRequest request =
+ * ListManagedFoldersRequest.newBuilder()
+ * .setParent(BucketName.of("[PROJECT]", "[BUCKET]").toString())
+ * .setPageSize(883849137)
+ * .setPageToken("pageToken873572522")
+ * .setPrefix("prefix-980110702")
+ * .setRequestId("requestId693933066")
+ * .build();
+ * ApiFuture future =
+ * storageControlClient.listManagedFoldersPagedCallable().futureCall(request);
+ * // Do something.
+ * for (ManagedFolder element : future.get().iterateAll()) {
+ * // doThingsWith(element);
+ * }
+ * }
+ * }
+ */
+ public final UnaryCallable
+ listManagedFoldersPagedCallable() {
+ return stub.listManagedFoldersPagedCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Retrieves a list of managed folders for a given bucket.
+ *
+ *
Sample code:
+ *
+ *
{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * try (StorageControlClient storageControlClient = StorageControlClient.create()) {
+ * ListManagedFoldersRequest request =
+ * ListManagedFoldersRequest.newBuilder()
+ * .setParent(BucketName.of("[PROJECT]", "[BUCKET]").toString())
+ * .setPageSize(883849137)
+ * .setPageToken("pageToken873572522")
+ * .setPrefix("prefix-980110702")
+ * .setRequestId("requestId693933066")
+ * .build();
+ * while (true) {
+ * ListManagedFoldersResponse response =
+ * storageControlClient.listManagedFoldersCallable().call(request);
+ * for (ManagedFolder element : response.getManagedFoldersList()) {
+ * // doThingsWith(element);
+ * }
+ * String nextPageToken = response.getNextPageToken();
+ * if (!Strings.isNullOrEmpty(nextPageToken)) {
+ * request = request.toBuilder().setPageToken(nextPageToken).build();
+ * } else {
+ * break;
+ * }
+ * }
+ * }
+ * }
Configuration of buffer size can be performed via {@link
+ * BidiBlobWriteSessionConfig#withBufferSize(int)}.
+ *
+ * @since 2.34.0 This new api is in preview and is subject to breaking changes.
+ */
+@Immutable
+@BetaApi
+@TransportCompatibility({Transport.GRPC})
+public final class BidiBlobWriteSessionConfig extends BlobWriteSessionConfig
implements BlobWriteSessionConfig.GrpcCompatible {
private static final long serialVersionUID = -903533790705476197L;
@@ -54,7 +66,7 @@ public int getBufferSize() {
@Override
WriterFactory createFactory(Clock clock) throws IOException {
- return new Factory(ByteSizeConstants._16MiB);
+ return new Factory(bufferSize);
}
@InternalApi
@@ -124,57 +136,4 @@ public BidiBlobWriteSessionConfig withBufferSize(int bufferSize) {
ByteSizeConstants._256KiB);
return new BidiBlobWriteSessionConfig(bufferSize);
}
-
- private static final class DecoratedWritableByteChannelSession
- implements WritableByteChannelSession {
-
- private final WritableByteChannelSession delegate;
- private final Conversions.Decoder decoder;
-
- private DecoratedWritableByteChannelSession(
- WritableByteChannelSession delegate, Conversions.Decoder decoder) {
- this.delegate = delegate;
- this.decoder = decoder;
- }
-
- @Override
- public WBC open() {
- try {
- return WritableByteChannelSession.super.open();
- } catch (Exception e) {
- throw StorageException.coalesce(e);
- }
- }
-
- @Override
- public ApiFuture openAsync() {
- return delegate.openAsync();
- }
-
- @Override
- public ApiFuture getResult() {
- return ApiFutures.transform(
- delegate.getResult(), decoder::decode, MoreExecutors.directExecutor());
- }
- }
-
- private static final class LazySession
- implements WritableByteChannelSession<
- BufferedWritableByteChannelSession.BufferedWritableByteChannel, R> {
- private final LazyWriteChannel lazy;
-
- private LazySession(LazyWriteChannel lazy) {
- this.lazy = lazy;
- }
-
- @Override
- public ApiFuture openAsync() {
- return lazy.getSession().openAsync();
- }
-
- @Override
- public ApiFuture getResult() {
- return lazy.getSession().getResult();
- }
- }
}
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSession.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSession.java
index 02ea23a6a7..81cecdc892 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSession.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSession.java
@@ -20,6 +20,7 @@
import com.google.api.core.BetaApi;
import java.io.IOException;
import java.nio.channels.WritableByteChannel;
+import java.util.concurrent.TimeUnit;
/**
* A session to write an object to Google Cloud Storage.
@@ -50,6 +51,10 @@ public interface BlobWriteSession {
*
Upon calling {@link WritableByteChannel#close()} the object creation will be finalized, and
* {@link #getResult()}s future should resolve.
*
+ *
The returned {@code WritableByteChannel} can throw IOExceptions from any of its usual
+ * methods. Any {@link IOException} thrown can have a cause of a {@link StorageException}.
+ * However, not all {@code IOExceptions} will have {@code StorageException}s.
+ *
* @throws IOException When creating the {@link WritableByteChannel} if an unrecoverable
* underlying IOException occurs it can be rethrown
* @throws IllegalStateException if open is called more than once
@@ -66,6 +71,10 @@ public interface BlobWriteSession {
* Google Cloud Storage 2. A terminal failure occurs, the terminal failure will become the
* exception result
*
+ *
If a terminal failure is encountered, calling either {@link ApiFuture#get()} or {@link
+ * ApiFuture#get(long, TimeUnit)} will result in an {@link
+ * java.util.concurrent.ExecutionException} with a cause that is the {@link StorageException}.
+ *
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
*/
@BetaApi
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfig.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfig.java
index b52e9bd4f7..441f78ac77 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfig.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfig.java
@@ -53,6 +53,15 @@ WritableByteChannelSession, BlobInfo> writeSession(
StorageInternal s, BlobInfo info, Opts opts);
}
+ /**
+ * Internal marker interface to signify an implementation of {@link BlobWriteSessionConfig} is
+ * compatible with {@link com.google.cloud.storage.TransportCompatibility.Transport#HTTP}
+ *
+ *
We could evaluate the annotations, but the code for that is more complicated and probably
+ * not worth the effort.
+ */
+ interface HttpCompatible {}
+
/**
* Internal marker interface to signify an implementation of {@link BlobWriteSessionConfig} is
* compatible with {@link com.google.cloud.storage.TransportCompatibility.Transport#GRPC}
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfigs.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfigs.java
index 43b68d8a0e..9e9479e144 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfigs.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessionConfigs.java
@@ -55,7 +55,7 @@
* full or close. Buffer size is configurable via
* {@link DefaultBlobWriteSessionConfig#withChunkSize(int)}
*
- *
gRPC
+ *
gRPC, HTTP
*
The network will only be used for the following operations:
*
*
Creating the Resumable Upload Session
@@ -86,7 +86,7 @@
* Buffer bytes to a temporary file on disk. On {@link WritableByteChannel#close() close()}
* upload the entire files contents to Cloud Storage. Delete the temporary file.
*
- *
gRPC
+ *
gRPC, HTTP
*
*
*
A Resumable Upload Session will be used to upload the file on disk.
@@ -142,7 +142,7 @@
* Break the stream of bytes into smaller part objects uploading each part in parallel. Then
* composing the parts together to make the ultimate object.
*
- *
gRPC
+ *
gRPC, HTTP
*
*
*
@@ -241,7 +241,7 @@ private BlobWriteSessionConfigs() {}
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
*/
@BetaApi
- @TransportCompatibility({Transport.GRPC})
+ @TransportCompatibility({Transport.GRPC, Transport.HTTP})
public static DefaultBlobWriteSessionConfig getDefault() {
return new DefaultBlobWriteSessionConfig(ByteSizeConstants._16MiB);
}
@@ -272,7 +272,7 @@ public static BidiBlobWriteSessionConfig bidiWrite() {
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
*/
@BetaApi
- @TransportCompatibility({Transport.GRPC})
+ @TransportCompatibility({Transport.GRPC, Transport.HTTP})
public static BlobWriteSessionConfig bufferToTempDirThenUpload() throws IOException {
return bufferToDiskThenUpload(
Paths.get(System.getProperty("java.io.tmpdir"), "google-cloud-storage"));
@@ -289,7 +289,7 @@ public static BlobWriteSessionConfig bufferToTempDirThenUpload() throws IOExcept
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
*/
@BetaApi
- @TransportCompatibility({Transport.GRPC})
+ @TransportCompatibility({Transport.GRPC, Transport.HTTP})
public static BufferToDiskThenUpload bufferToDiskThenUpload(Path path) throws IOException {
return bufferToDiskThenUpload(ImmutableList.of(path));
}
@@ -308,7 +308,7 @@ public static BufferToDiskThenUpload bufferToDiskThenUpload(Path path) throws IO
* @since 2.26.0 This new api is in preview and is subject to breaking changes.
*/
@BetaApi
- @TransportCompatibility({Transport.GRPC})
+ @TransportCompatibility({Transport.GRPC, Transport.HTTP})
public static BufferToDiskThenUpload bufferToDiskThenUpload(Collection paths)
throws IOException {
return new BufferToDiskThenUpload(ImmutableList.copyOf(paths), false);
@@ -342,7 +342,7 @@ public static JournalingBlobWriteSessionConfig journaling(Collection paths
* @since 2.28.0 This new api is in preview and is subject to breaking changes.
*/
@BetaApi
- @TransportCompatibility({Transport.GRPC})
+ @TransportCompatibility({Transport.GRPC, Transport.HTTP})
public static ParallelCompositeUploadBlobWriteSessionConfig parallelCompositeUpload() {
return ParallelCompositeUploadBlobWriteSessionConfig.withDefaults();
}
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessions.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessions.java
index 878552a125..c9da9ee05c 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessions.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteSessions.java
@@ -17,6 +17,7 @@
package com.google.cloud.storage;
import com.google.api.core.ApiFuture;
+import com.google.common.base.Preconditions;
import java.io.IOException;
import java.nio.channels.WritableByteChannel;
@@ -30,14 +31,20 @@ static BlobWriteSession of(WritableByteChannelSession, BlobInfo> s) {
static final class WritableByteChannelSessionAdapter implements BlobWriteSession {
private final WritableByteChannelSession, BlobInfo> delegate;
+ private boolean open;
private WritableByteChannelSessionAdapter(WritableByteChannelSession, BlobInfo> delegate) {
this.delegate = delegate;
+ open = false;
}
@Override
public WritableByteChannel open() throws IOException {
- return delegate.open();
+ synchronized (this) {
+ Preconditions.checkState(!open, "already open");
+ open = true;
+ return delegate.open();
+ }
}
@Override
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BufferToDiskThenUpload.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BufferToDiskThenUpload.java
index 8c9cb7c107..58ce102932 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BufferToDiskThenUpload.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BufferToDiskThenUpload.java
@@ -59,9 +59,9 @@
*/
@Immutable
@BetaApi
-@TransportCompatibility({Transport.GRPC})
+@TransportCompatibility({Transport.GRPC, Transport.HTTP})
public final class BufferToDiskThenUpload extends BlobWriteSessionConfig
- implements BlobWriteSessionConfig.GrpcCompatible {
+ implements BlobWriteSessionConfig.HttpCompatible, BlobWriteSessionConfig.GrpcCompatible {
private static final long serialVersionUID = 9059242302276891867L;
/**
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultBlobWriteSessionConfig.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultBlobWriteSessionConfig.java
index 090f929e7e..ffcbcfa8ee 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultBlobWriteSessionConfig.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/DefaultBlobWriteSessionConfig.java
@@ -21,17 +21,23 @@
import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.api.gax.grpc.GrpcCallContext;
+import com.google.api.services.storage.model.StorageObject;
import com.google.cloud.storage.BufferedWritableByteChannelSession.BufferedWritableByteChannel;
import com.google.cloud.storage.Conversions.Decoder;
import com.google.cloud.storage.TransportCompatibility.Transport;
import com.google.cloud.storage.UnifiedOpts.ObjectTargetOpt;
import com.google.cloud.storage.UnifiedOpts.Opts;
+import com.google.cloud.storage.spi.v1.StorageRpc;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.storage.v2.WriteObjectRequest;
import com.google.storage.v2.WriteObjectResponse;
+import java.io.IOException;
+import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
import java.time.Clock;
+import java.util.Map;
+import java.util.function.Supplier;
import javax.annotation.concurrent.Immutable;
/**
@@ -55,9 +61,9 @@
*/
@Immutable
@BetaApi
-@TransportCompatibility({Transport.GRPC})
+@TransportCompatibility({Transport.GRPC, Transport.HTTP})
public final class DefaultBlobWriteSessionConfig extends BlobWriteSessionConfig
- implements BlobWriteSessionConfig.GrpcCompatible {
+ implements BlobWriteSessionConfig.HttpCompatible, BlobWriteSessionConfig.GrpcCompatible {
private static final long serialVersionUID = -6873740918589930633L;
private final int chunkSize;
@@ -146,6 +152,39 @@ public WritableByteChannelSession, BlobInfo> writeSession(
.build();
})),
WRITE_OBJECT_RESPONSE_BLOB_INFO_DECODER);
+ } else if (s instanceof StorageImpl) {
+ StorageImpl json = (StorageImpl) s;
+
+ return new DecoratedWritableByteChannelSession<>(
+ new LazySession<>(
+ new LazyWriteChannel<>(
+ () -> {
+ final Map optionsMap = opts.getRpcOptions();
+ BlobInfo.Builder builder = info.toBuilder().setMd5(null).setCrc32c(null);
+ BlobInfo updated = opts.blobInfoMapper().apply(builder).build();
+
+ StorageObject encode = Conversions.json().blobInfo().encode(updated);
+ Supplier uploadIdSupplier =
+ ResumableMedia.startUploadForBlobInfo(
+ json.getOptions(),
+ updated,
+ optionsMap,
+ json.retryAlgorithmManager.getForResumableUploadSessionCreate(
+ optionsMap));
+ ApiFuture startAsync =
+ ApiFutures.immediateFuture(
+ JsonResumableWrite.of(
+ encode, optionsMap, uploadIdSupplier.get(), 0L));
+
+ return ResumableMedia.http()
+ .write()
+ .byteChannel(HttpClientContext.from(json.storageRpc))
+ .resumable()
+ .buffered(BufferHandle.allocate(chunkSize))
+ .setStartAsync(startAsync)
+ .build();
+ })),
+ Conversions.json().blobInfo());
} else {
throw new IllegalStateException(
"Unknown Storage implementation: " + s.getClass().getName());
@@ -153,50 +192,99 @@ public WritableByteChannelSession, BlobInfo> writeSession(
}
}
- private static final class DecoratedWritableByteChannelSession
+ static final class DecoratedWritableByteChannelSession
implements WritableByteChannelSession {
private final WritableByteChannelSession delegate;
private final Decoder decoder;
- private DecoratedWritableByteChannelSession(
+ DecoratedWritableByteChannelSession(
WritableByteChannelSession delegate, Decoder decoder) {
this.delegate = delegate;
this.decoder = decoder;
}
- @Override
- public WBC open() {
- try {
- return WritableByteChannelSession.super.open();
- } catch (Exception e) {
- throw StorageException.coalesce(e);
- }
- }
-
@Override
public ApiFuture openAsync() {
- return delegate.openAsync();
+ return ApiFutures.catchingAsync(
+ delegate.openAsync(),
+ Throwable.class,
+ throwable -> ApiFutures.immediateFailedFuture(StorageException.coalesce(throwable)),
+ MoreExecutors.directExecutor());
}
@Override
public ApiFuture getResult() {
- return ApiFutures.transform(
- delegate.getResult(), decoder::decode, MoreExecutors.directExecutor());
+ ApiFuture decodeResult =
+ ApiFutures.transform(
+ delegate.getResult(), decoder::decode, MoreExecutors.directExecutor());
+ return ApiFutures.catchingAsync(
+ decodeResult,
+ Throwable.class,
+ throwable -> ApiFutures.immediateFailedFuture(StorageException.coalesce(throwable)),
+ MoreExecutors.directExecutor());
}
}
- private static final class LazySession
+ static final class LazySession
implements WritableByteChannelSession {
private final LazyWriteChannel lazy;
- private LazySession(LazyWriteChannel lazy) {
+ LazySession(LazyWriteChannel lazy) {
this.lazy = lazy;
}
@Override
public ApiFuture openAsync() {
- return lazy.getSession().openAsync();
+ // make sure the errors coming out of the BufferedWritableByteChannel are either IOException
+ // or StorageException
+ return ApiFutures.transform(
+ lazy.getSession().openAsync(),
+ delegate ->
+ new BufferedWritableByteChannel() {
+ @Override
+ public int write(ByteBuffer src) throws IOException {
+ try {
+ return delegate.write(src);
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw StorageException.coalesce(e);
+ }
+ }
+
+ @Override
+ public void flush() throws IOException {
+ try {
+ delegate.flush();
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw StorageException.coalesce(e);
+ }
+ }
+
+ @Override
+ public boolean isOpen() {
+ try {
+ return delegate.isOpen();
+ } catch (Exception e) {
+ throw StorageException.coalesce(e);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ try {
+ delegate.close();
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw StorageException.coalesce(e);
+ }
+ }
+ },
+ MoreExecutors.directExecutor());
}
@Override
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicDownloadSessionBuilder.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicDownloadSessionBuilder.java
index 704794a389..82789bcd2f 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicDownloadSessionBuilder.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicDownloadSessionBuilder.java
@@ -48,19 +48,23 @@ public static GapicDownloadSessionBuilder create() {
* ultimately produced channel will not do any retries of its own.
*/
public ReadableByteChannelSessionBuilder byteChannel(
- ServerStreamingCallable read) {
- return new ReadableByteChannelSessionBuilder(read);
+ ServerStreamingCallable read,
+ ResponseContentLifecycleManager responseContentLifecycleManager) {
+ return new ReadableByteChannelSessionBuilder(read, responseContentLifecycleManager);
}
public static final class ReadableByteChannelSessionBuilder {
private final ServerStreamingCallable read;
+ private final ResponseContentLifecycleManager responseContentLifecycleManager;
private boolean autoGzipDecompression;
private Hasher hasher;
private ReadableByteChannelSessionBuilder(
- ServerStreamingCallable read) {
+ ServerStreamingCallable read,
+ ResponseContentLifecycleManager responseContentLifecycleManager) {
this.read = read;
+ this.responseContentLifecycleManager = responseContentLifecycleManager;
this.hasher = Hasher.noop();
this.autoGzipDecompression = false;
}
@@ -100,11 +104,13 @@ public UnbufferedReadableByteChannelSessionBuilder unbuffered() {
return (object, resultFuture) -> {
if (autoGzipDecompression) {
return new GzipReadableByteChannel(
- new GapicUnbufferedReadableByteChannel(resultFuture, read, object, hasher),
+ new GapicUnbufferedReadableByteChannel(
+ resultFuture, read, object, hasher, responseContentLifecycleManager),
ApiFutures.transform(
resultFuture, Object::getContentEncoding, MoreExecutors.directExecutor()));
} else {
- return new GapicUnbufferedReadableByteChannel(resultFuture, read, object, hasher);
+ return new GapicUnbufferedReadableByteChannel(
+ resultFuture, read, object, hasher, responseContentLifecycleManager);
}
};
}
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java
index 4b19c3f998..6cecc8dded 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java
@@ -16,8 +16,6 @@
package com.google.cloud.storage;
-import static com.google.common.base.Preconditions.checkArgument;
-
import com.google.api.client.http.HttpStatusCodes;
import com.google.api.core.ApiFuture;
import com.google.api.core.SettableApiFuture;
@@ -25,6 +23,7 @@
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.cloud.storage.Crc32cValue.Crc32cLengthKnown;
import com.google.cloud.storage.UnbufferedReadableByteChannelSession.UnbufferedReadableByteChannel;
+import com.google.protobuf.ByteString;
import com.google.storage.v2.ChecksummedData;
import com.google.storage.v2.Object;
import com.google.storage.v2.ReadObjectRequest;
@@ -46,6 +45,7 @@ final class GapicUnbufferedReadableByteChannel
private final ReadObjectRequest req;
private final Hasher hasher;
private final LazyServerStreamIterator iter;
+ private final ResponseContentLifecycleManager rclm;
private boolean open = true;
private boolean complete = false;
@@ -53,18 +53,20 @@ final class GapicUnbufferedReadableByteChannel
private Object metadata;
- private ByteBuffer leftovers;
+ private ResponseContentLifecycleHandle leftovers;
GapicUnbufferedReadableByteChannel(
SettableApiFuture