public class MultipartUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static long |
MAX_OBJECT_SIZE
Maximum object size supported by S3: 5 GB
|
protected long |
maxPartSize |
static long |
MIN_PART_SIZE
Minimum multipart upload part size supported by S3: 5 MB.
|
Constructor and Description |
---|
MultipartUtils()
Use default value for maximum part size:
MAX_OBJECT_SIZE . |
MultipartUtils(long maxPartSize) |
Modifier and Type | Method and Description |
---|---|
long |
getMaxPartSize() |
boolean |
isFileLargerThanMaxPartSize(java.io.File file) |
java.util.List<S3Object> |
splitFileIntoObjectsByMaxPartSize(java.lang.String objectKey,
java.io.File file)
Split the given file into objects such that no object has a size greater than
the defined maximum part size.
|
protected void |
throwServiceEventAdaptorErrorIfPresent(S3ServiceEventListener eventListener) |
void |
uploadObjects(java.lang.String bucketName,
S3Service s3Service,
java.util.List<StorageObject> objectsForMultipartUpload,
S3ServiceEventListener eventListener)
Upload one or more file-based objects to S3 as multipart uploads, where each
object's underlying file is split into parts based on the value of
maxPartSize . |
public static final long MIN_PART_SIZE
public static final long MAX_OBJECT_SIZE
protected long maxPartSize
public MultipartUtils(long maxPartSize)
maxPartSize
- the maximum size of objects that will be generated or upload by this instance,
must be between MIN_PART_SIZE
and MAX_OBJECT_SIZE
.public MultipartUtils()
MAX_OBJECT_SIZE
.public long getMaxPartSize()
public boolean isFileLargerThanMaxPartSize(java.io.File file)
file
- public java.util.List<S3Object> splitFileIntoObjectsByMaxPartSize(java.lang.String objectKey, java.io.File file) throws java.io.IOException, java.security.NoSuchAlgorithmException
SegmentedRepeatableFileInputStream
input stream to manage its own
byte range within the underlying file.objectKey
- the object key name to apply to all objects returned by this method.file
- a file to split into multiple parts.java.io.IOException
java.security.NoSuchAlgorithmException
public void uploadObjects(java.lang.String bucketName, S3Service s3Service, java.util.List<StorageObject> objectsForMultipartUpload, S3ServiceEventListener eventListener) throws java.lang.Exception
maxPartSize
.
Objects are uploaded in parallel using a ThreadedS3Service
class
that is created within this method, so uploads will take place using as
many connections and threads as are configured in your service's
Jets3tProperties
.
This method can upload small files that don't need to be split into parts,
but because there is extra overhead in performing unnecessary multipart upload
operations you should avoid doing so unless it's really necessary.bucketName
- the target bucket names3Service
- the S3 service that will perform the workobjectsForMultipartUpload
- a list of one or more objects that will be uploaded, potentially in multiple
parts if the object's underlying file is larger than maxPartSize
eventListener
- an event listener to monitor progress event notifications, which should
recognize and handle error events. May be null, in which case a standard
S3ServiceEventAdaptor
is used which won't report on events but will
throw an exception if there is a failure.java.lang.Exception
protected void throwServiceEventAdaptorErrorIfPresent(S3ServiceEventListener eventListener) throws java.lang.Exception
java.lang.Exception