org.jets3t.service.utils
Class MultipartUtils

java.lang.Object
  extended by org.jets3t.service.utils.MultipartUtils

public class MultipartUtils
extends java.lang.Object

Tool to simplify working with the multipart uploads feature offered by Amazon S3.


Field Summary
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 Summary
MultipartUtils()
          Use default value for maximum part size: MAX_OBJECT_SIZE.
MultipartUtils(long maxPartSize)
           
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

maxPartSize

protected long maxPartSize
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 between MIN_PART_SIZE and MAX_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(java.io.File file)
Parameters:
file -
Returns:
true if the given file is larger than the maximum part size defined in this instances.

splitFileIntoObjectsByMaxPartSize

public java.util.List<S3Object> splitFileIntoObjectsByMaxPartSize(java.lang.String objectKey,
                                                                  java.io.File file)
                                                           throws java.io.IOException,
                                                                  java.security.NoSuchAlgorithmException
Split the given file into objects such that no object has a size greater than the defined maximum part size. Each object uses a SegmentedRepeatableFileInputStream 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:
java.io.IOException
java.security.NoSuchAlgorithmException

uploadObjects

public void uploadObjects(java.lang.String bucketName,
                          S3Service s3Service,
                          java.util.List<StorageObject> objectsForMultipartUpload,
                          S3ServiceEventListener eventListener)
                   throws java.lang.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 of 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.

Parameters:
bucketName - the target bucket name
s3Service - the S3 service that will perform the work
objectsForMultipartUpload - 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.
Throws:
java.lang.Exception

throwServiceEventAdaptorErrorIfPresent

protected void throwServiceEventAdaptorErrorIfPresent(S3ServiceEventListener eventListener)
                                               throws java.lang.Exception
Throws:
java.lang.Exception