public class MultipartObjectAssembler extends Object
MultiPartObjectAssembler provides a simplified interaction with uploading large objects using multi-part uploads.
An assembler can be used begin a new upload, or resume a previous one. Parts are be added to the assembler in order, and the assembler will handle all transfers and part numbering. Users can reference the returned manifest to watch/monitor updates to the upload as new parts are added or parts complete.
Note, a new assembler instance should be used for every multi-part upload. Once initialized (or resumed), an assembler cannot be reused.
Modifier and Type | Class and Description |
---|---|
static class |
MultipartObjectAssembler.MultipartObjectAssemblerBuilder |
Constructor and Description |
---|
MultipartObjectAssembler(ObjectStorage service,
String namespaceName,
String bucketName,
String objectName,
boolean allowOverwrite,
ExecutorService executorService)
Deprecated.
use
builder() instead |
Modifier and Type | Method and Description |
---|---|
AbortMultipartUploadResponse |
abort()
Aborts the current multi-part assembly and all uploads that are currently in progress.
|
int |
addPart(File file,
String md5)
Add the next part to the upload.
|
int |
addPart(InputStream stream,
long contentLength,
String md5)
Add the next part to the upload.
|
int |
addPart(InputStream stream,
long contentLength,
String checksum,
String checksumAlgorithm)
Adds the next part to the upload.
|
static MultipartObjectAssembler.MultipartObjectAssemblerBuilder |
builder() |
CommitMultipartUploadResponse |
commit()
Commits the multi-part upload after all in-progress uploads have completed.
|
MultipartManifest |
newRequest(String contentType,
String contentLanguage,
String contentEncoding,
Map<String,String> opcMeta)
Initialize a new multi-part upload request.
|
MultipartManifest |
resumeRequest(String uploadId)
Resumes an existing multi-part upload using the upload ID.
|
void |
setOpcClientRequestId(String opcClientRequestId)
The opcClientRequestId to send for all requests related to this multi-part upload.
|
void |
setPart(File file,
String md5,
int partNum)
Adds a part to the upload.
|
void |
setPart(InputStream stream,
long contentLength,
String md5,
int partNum)
Adds a part to the upload.
|
void |
setPart(InputStream stream,
long contentLength,
String checksum,
String checksumAlgorithm,
int partNum)
Adds a part to the upload.
|
@Deprecated public MultipartObjectAssembler(ObjectStorage service, String namespaceName, String bucketName, String objectName, boolean allowOverwrite, ExecutorService executorService)
builder()
insteadCreates a new assembler.
service
- The object storage servicenamespaceName
- The namespace to usebucketName
- The bucket to useobjectName
- The final object name.allowOverwrite
- Allow uploads to overwrite existing parts with the same part numberexecutorService
- The executor service to usepublic MultipartManifest newRequest(String contentType, String contentLanguage, String contentEncoding, Map<String,String> opcMeta)
Initialize a new multi-part upload request.
contentType
- The content-type of the object, optionalcontentLanguage
- The content-language of the object, optionalcontentEncoding
- The content-encoding of the object, optionalpublic MultipartManifest resumeRequest(String uploadId)
Resumes an existing multi-part upload using the upload ID.
uploadId
- The upload ID.public int addPart(File file, String md5)
Add the next part to the upload. Parts will be committed in the order submitted.
Calling this will set the ifNoneMatch value and will not allow overwriting existing parts.
file
- The file to upload as the next partmd5
- The MD5 checksum of the file, optionalpublic int addPart(InputStream stream, long contentLength, String md5)
Add the next part to the upload. Parts will be committed in the order submitted.
We allow part overwrites to facilitate retries.
stream
- The stream to upload as the next partcontentLength
- The content length of the partmd5
- The MD5 checksum, optionalpublic int addPart(InputStream stream, long contentLength, String checksum, String checksumAlgorithm)
Adds the next part to the upload. Parts will be committed in the order submitted.
We allow part overwrites to facilitate retries.
stream
- The stream to upload as the next partcontentLength
- The content length of the partchecksum
- The checksum of the part, optionalchecksumAlgorithm
- The checksum algorithm used, optional (e.g., “CRC32C”)IllegalStateException
- if the assembler has not been initialized or the upload has
been abortedpublic void setPart(File file, String md5, int partNum)
Adds a part to the upload. The part will be ordered based on the part number provided.
This is useful to retry a failed part, to explicitly control the part numbering, or overwrite an existing part.
Calling this will not set the ifNoneMatch value and will allow overwriting existing parts.
file
- The file to uploadmd5
- The MD5 checksum, optionalpartNum
- The part number to to assign to the partpublic void setPart(InputStream stream, long contentLength, String md5, int partNum)
Adds a part to the upload. The part will be ordered based on the part number provided.
This is useful to retry a failed part, to explicitly control the part numbering, or overwrite an existing part.
Calling this will not set the ifNoneMatch value and will allow overwriting existing parts.
stream
- The stream to uploadcontentLength
- The content length of the partmd5
- The MD5 checksum, optionalpartNum
- The part number to to assign to the partpublic void setPart(InputStream stream, long contentLength, String checksum, String checksumAlgorithm, int partNum)
Adds a part to the upload. The part will be ordered based on the part number provided.
This method is for setting parts with additional checksum algorithms.
Calling this will not set the ifNoneMatch value and will allow overwriting existing parts.
stream
- The stream to uploadcontentLength
- The content length of the partchecksum
- The checksum value, optionalchecksumAlgorithm
- The checksum algorithm usedpartNum
- The part number to assign to the partpublic AbortMultipartUploadResponse abort()
Aborts the current multi-part assembly and all uploads that are currently in progress.
public CommitMultipartUploadResponse commit()
Commits the multi-part upload after all in-progress uploads have completed.
This is a blocking call, and throws IllegalStateException if you try to commit an upload
in which the Manifest reports it is not successful (MultipartManifest.isUploadSuccessful()
).
public static MultipartObjectAssembler.MultipartObjectAssemblerBuilder builder()
public void setOpcClientRequestId(String opcClientRequestId)
The opcClientRequestId to send for all requests related to this multi-part upload.
Copyright © 2016–2024. All rights reserved.