Package org.jets3t.service.utils
Class MultipartUtils
- java.lang.Object
-
- org.jets3t.service.utils.MultipartUtils
-
public class MultipartUtils extends Object
Tool to simplify working with the multipart uploads feature offered by Amazon S3.- Author:
- jmurty
-
-
Field Summary
Fields Modifier and Type Field Description static long
MAX_OBJECT_SIZE
Maximum object size supported by S3: 5 GBstatic long
MIN_PART_SIZE
Minimum multipart upload part size supported by S3: 5 MB.
-
Constructor Summary
Constructors Constructor Description MultipartUtils()
Use default value for maximum part size:MAX_OBJECT_SIZE
.MultipartUtils(long maxPartSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getMaxPartSize()
boolean
isFileLargerThanMaxPartSize(File file)
List<S3Object>
splitFileIntoObjectsByMaxPartSize(String objectKey, File file)
Split the given file into objects such that no object has a size greater than the defined maximum part size.void
uploadObjects(String bucketName, S3Service s3Service, 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 ofmaxPartSize
.
-
-
-
Field Detail
-
MIN_PART_SIZE
public static final long MIN_PART_SIZE
Minimum multipart upload part size supported by S3: 5 MB. NOTE: This minimum size does not apply to the last part in a multipart upload, which may be 1 byte or larger.- See Also:
- Constant Field Values
-
MAX_OBJECT_SIZE
public static final long MAX_OBJECT_SIZE
Maximum object size supported by S3: 5 GB- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MultipartUtils
public MultipartUtils(long maxPartSize)
- Parameters:
maxPartSize
- the maximum size of objects that will be generated or upload by this instance, must be betweenMIN_PART_SIZE
andMAX_OBJECT_SIZE
.
-
MultipartUtils
public MultipartUtils()
Use default value for maximum part size:MAX_OBJECT_SIZE
.
-
-
Method Detail
-
getMaxPartSize
public long getMaxPartSize()
- Returns:
- maximum part size as set in constructor.
-
isFileLargerThanMaxPartSize
public boolean isFileLargerThanMaxPartSize(File file)
- Parameters:
file
-- Returns:
- true if the given file is larger than the maximum part size defined in this instances.
-
splitFileIntoObjectsByMaxPartSize
public List<S3Object> splitFileIntoObjectsByMaxPartSize(String objectKey, File file) throws IOException, NoSuchAlgorithmException
Split the given file into objects such that no object has a size greater than the defined maximum part size. Each object uses aSegmentedRepeatableFileInputStream
input stream to manage its own byte range within the underlying file.- Parameters:
objectKey
- the object key name to apply to all objects returned by this method.file
- a file to split into multiple parts.- Returns:
- an ordered list of objects that can be uploaded as multipart parts to S3 to re-constitute the given file in the service.
- Throws:
IOException
NoSuchAlgorithmException
-
uploadObjects
public void uploadObjects(String bucketName, S3Service s3Service, List<StorageObject> objectsForMultipartUpload, S3ServiceEventListener eventListener) throws Exception
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 ofmaxPartSize
. Objects are uploaded in parallel using aThreadedS3Service
class that is created within this method, so uploads will take place using as many connections and threads as are configured in your service'sJets3tProperties
. 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.- Parameters:
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 thanmaxPartSize
eventListener
- an event listener to monitor progress event notifications, which should recognize and handle error events. May be null, in which case a standardS3ServiceEventAdaptor
is used which won't report on events but will throw an exception if there is a failure.- Throws:
Exception
-
-