|
| 1 | +/* |
| 2 | + * Copyright 2025 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.cloud.storage; |
| 18 | + |
| 19 | +import com.google.api.core.BetaApi; |
| 20 | +import com.google.api.core.InternalExtensionOnly; |
| 21 | +import com.google.cloud.storage.multipartupload.model.AbortMultipartUploadRequest; |
| 22 | +import com.google.cloud.storage.multipartupload.model.AbortMultipartUploadResponse; |
| 23 | +import com.google.cloud.storage.multipartupload.model.CompleteMultipartUploadRequest; |
| 24 | +import com.google.cloud.storage.multipartupload.model.CompleteMultipartUploadResponse; |
| 25 | +import com.google.cloud.storage.multipartupload.model.CreateMultipartUploadRequest; |
| 26 | +import com.google.cloud.storage.multipartupload.model.CreateMultipartUploadResponse; |
| 27 | +import com.google.cloud.storage.multipartupload.model.ListPartsRequest; |
| 28 | +import com.google.cloud.storage.multipartupload.model.ListPartsResponse; |
| 29 | +import com.google.cloud.storage.multipartupload.model.UploadPartRequest; |
| 30 | +import com.google.cloud.storage.multipartupload.model.UploadPartResponse; |
| 31 | +import java.net.URI; |
| 32 | + |
| 33 | +/** |
| 34 | + * A client for interacting with Google Cloud Storage's Multipart Upload API. |
| 35 | + * |
| 36 | + * <p>This class is for internal use only and is not intended for public consumption. It provides a |
| 37 | + * low-level interface for creating and managing multipart uploads. |
| 38 | + * |
| 39 | + * @see <a href="https://cloud.google.com/storage/docs/multipart-uploads">Multipart Uploads</a> |
| 40 | + * @since 2.60.0 This new api is in preview and is subject to breaking changes. |
| 41 | + */ |
| 42 | +@BetaApi |
| 43 | +@InternalExtensionOnly |
| 44 | +public abstract class MultipartUploadClient { |
| 45 | + |
| 46 | + MultipartUploadClient() {} |
| 47 | + |
| 48 | + /** |
| 49 | + * Creates a new multipart upload. |
| 50 | + * |
| 51 | + * @param request The request object containing the details for creating the multipart upload. |
| 52 | + * @return A {@link CreateMultipartUploadResponse} object containing the upload ID. |
| 53 | + * @since 2.60.0 This new api is in preview and is subject to breaking changes. |
| 54 | + */ |
| 55 | + @BetaApi |
| 56 | + public abstract CreateMultipartUploadResponse createMultipartUpload( |
| 57 | + CreateMultipartUploadRequest request); |
| 58 | + |
| 59 | + /** |
| 60 | + * Lists the parts that have been uploaded for a specific multipart upload. |
| 61 | + * |
| 62 | + * @param listPartsRequest The request object containing the details for listing the parts. |
| 63 | + * @return A {@link ListPartsResponse} object containing the list of parts. |
| 64 | + * @since 2.60.0 This new api is in preview and is subject to breaking changes. |
| 65 | + */ |
| 66 | + @BetaApi |
| 67 | + public abstract ListPartsResponse listParts(ListPartsRequest listPartsRequest); |
| 68 | + |
| 69 | + /** |
| 70 | + * Aborts a multipart upload. |
| 71 | + * |
| 72 | + * @param request The request object containing the details for aborting the multipart upload. |
| 73 | + * @return An {@link AbortMultipartUploadResponse} object. |
| 74 | + * @since 2.60.0 This new api is in preview and is subject to breaking changes. |
| 75 | + */ |
| 76 | + @BetaApi |
| 77 | + public abstract AbortMultipartUploadResponse abortMultipartUpload( |
| 78 | + AbortMultipartUploadRequest request); |
| 79 | + |
| 80 | + /** |
| 81 | + * Completes a multipart upload. |
| 82 | + * |
| 83 | + * @param request The request object containing the details for completing the multipart upload. |
| 84 | + * @return A {@link CompleteMultipartUploadResponse} object containing information about the |
| 85 | + * completed upload. |
| 86 | + * @since 2.60.0 This new api is in preview and is subject to breaking changes. |
| 87 | + */ |
| 88 | + @BetaApi |
| 89 | + public abstract CompleteMultipartUploadResponse completeMultipartUpload( |
| 90 | + CompleteMultipartUploadRequest request); |
| 91 | + |
| 92 | + /** |
| 93 | + * Uploads a part in a multipart upload. |
| 94 | + * |
| 95 | + * @param request The request object containing the details for uploading the part. |
| 96 | + * @param requestBody The content of the part to upload. |
| 97 | + * @return An {@link UploadPartResponse} object containing the ETag of the uploaded part. |
| 98 | + * @since 2.60.0 This new api is in preview and is subject to breaking changes. |
| 99 | + */ |
| 100 | + @BetaApi |
| 101 | + public abstract UploadPartResponse uploadPart(UploadPartRequest request, RequestBody requestBody); |
| 102 | + |
| 103 | + /** |
| 104 | + * Creates a new instance of {@link MultipartUploadClient}. |
| 105 | + * |
| 106 | + * @param config The configuration for the client. |
| 107 | + * @return A new {@link MultipartUploadClient} instance. |
| 108 | + * @since 2.60.0 This new api is in preview and is subject to breaking changes. |
| 109 | + */ |
| 110 | + @BetaApi |
| 111 | + public static MultipartUploadClient create(MultipartUploadSettings config) { |
| 112 | + HttpStorageOptions options = config.getOptions(); |
| 113 | + return new MultipartUploadClientImpl( |
| 114 | + URI.create(options.getHost()), |
| 115 | + options.createRetrier(), |
| 116 | + MultipartUploadHttpRequestManager.createFrom(options), |
| 117 | + options.getRetryAlgorithmManager()); |
| 118 | + } |
| 119 | +} |
0 commit comments