public class LargeFileUploader extends java.lang.Object implements java.lang.Runnable, ProgressListener
isAbortMpuOnFailure()
is false, in which case, the MPU will be preserved.Modifier and Type | Class and Description |
---|---|
protected class |
LargeFileUploader.PutObjectTask |
protected class |
LargeFileUploader.VerifySourcePartTask |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MPU_THRESHOLD |
static long |
DEFAULT_PART_SIZE |
static int |
DEFAULT_THREADS |
static int |
MAX_PARTS |
static long |
MIN_PART_SIZE |
Constructor and Description |
---|
LargeFileUploader(S3Client s3Client,
java.lang.String bucket,
java.lang.String key,
java.io.File file)
Creates a new LargeFileUpload instance using the specified
s3Client to upload
file to bucket/key . |
LargeFileUploader(S3Client s3Client,
java.lang.String bucket,
java.lang.String key,
java.io.InputStream stream,
long size)
Creates a new LargeFileUpload instance using the specified
s3Client to upload
from a single stream to bucket/key . |
LargeFileUploader(S3Client s3Client,
java.lang.String bucket,
java.lang.String key,
LargeFileMultipartSource multipartSource)
Creates a new LargeFileUpload instance using the specified
s3Client to upload
from a multipartSource to bucket/key . |
LargeFileUploader(S3Client s3Client,
java.lang.String srcBucket,
java.lang.String srcKey,
java.lang.String dstBucket,
java.lang.String dstKey)
Creates a new LargeFileUpload instance using the specified
s3Client to copy
from srcBucket/srcKey to dstBucket/dstKey without streaming
data between the client and ECS server. |
Modifier and Type | Method and Description |
---|---|
protected void |
abortMpu(java.lang.String uploadId) |
protected CompleteMultipartUploadResult |
completeMpu(java.lang.String uploadId,
java.util.SortedSet<MultipartPartETag> parts) |
protected void |
configure()
This method should be idempotent
|
void |
doByteRangeUpload() |
void |
doMultipartUpload() |
void |
doSingleCopy() |
void |
doSinglePut() |
AccessControlList |
getAcl() |
java.lang.String |
getBucket() |
long |
getBytesTransferred() |
CannedAcl |
getCannedAcl() |
java.lang.String |
getETag()
Returns the result ETag after an upload is successfully complete.
|
java.util.concurrent.ExecutorService |
getExecutorService() |
long |
getFullSize() |
java.lang.String |
getKey() |
protected long |
getMinPartSize() |
static java.lang.String |
getMpuETag(java.util.List<MultipartPartETag> partETags) |
long |
getMpuThreshold() |
LargeFileMultipartSource |
getMultipartSource() |
S3ObjectMetadata |
getObjectMetadata() |
long |
getPartSize() |
ProgressListener |
getProgressListener() |
LargeFileUploaderResumeContext |
getResumeContext()
During an upload operation, the
resumeContext is kept up-to-date with the uploadId and list of
uploaded parts. |
S3Client |
getS3Client() |
java.lang.String |
getSourceVersionId() |
java.io.InputStream |
getStream() |
int |
getThreads() |
java.lang.String |
getVersionId()
Returns the result versionId after an upload is successfully completed to a version-enabled bucket.
|
protected java.lang.String |
initMpu() |
boolean |
isAbortMpuOnFailure() |
boolean |
isCloseStream() |
protected java.util.List<MultipartPart> |
listParts(java.lang.String uploadId) |
protected java.io.InputStream |
monitorStream(java.io.InputStream stream) |
void |
progress(long completed,
long total)
Provides feedback on the number of bytes completed and the total number of bytes to transfer.
|
protected java.lang.String |
putObject(java.io.InputStream is) |
void |
run() |
void |
setAbortMpuOnFailure(boolean abortMpuOnFailure)
Specifies whether MPU is aborted with any failure
If a failure occurs and abortMpuOnFailure is true, then MPU is aborted and the resumeContext is cleared
(uploadId and uploadedParts are set to null).
|
void |
setAcl(AccessControlList acl) |
void |
setCannedAcl(CannedAcl cannedAcl) |
void |
setCloseStream(boolean closeStream) |
void |
setExecutorService(java.util.concurrent.ExecutorService executorService)
Allows for providing a custom thread executor (i.e.
|
void |
setMpuThreshold(long mpuThreshold)
Sets the threshold above which an MPU operation is used to upload, and below which a single-PUT is used.
|
void |
setObjectMetadata(S3ObjectMetadata objectMetadata) |
void |
setPartSize(long partSize)
Sets the size of each part to upload.
|
void |
setProgressListener(ProgressListener progressListener) |
void |
setResumeContext(LargeFileUploaderResumeContext resumeContext)
Use when resuming an existing incomplete MPU by skipping existing parts.
|
void |
setSourceVersionId(java.lang.String sourceVersionId) |
void |
setThreads(int threads)
Sets the number of threads to use for transferring parts.
|
void |
transferred(long size)
Reports that some bytes have been transferred.
|
void |
upload()
This method will automatically choose between MPU and single-PUT operations based on a configured threshold.
|
LargeFileUpload |
uploadAsync()
This async version of upload() will start the upload process in the background and immediately return a
LargeFileUpload instance. |
protected MultipartPartETag |
uploadPart(java.lang.String uploadId,
int partNumber,
java.io.InputStream is,
long length) |
LargeFileUploader |
withAbortMpuOnFailure(boolean abortMpuOnFailure) |
LargeFileUploader |
withAcl(AccessControlList acl) |
LargeFileUploader |
withCannedAcl(CannedAcl cannedAcl) |
LargeFileUploader |
withCloseStream(boolean closeStream) |
LargeFileUploader |
withExecutorService(java.util.concurrent.ExecutorService executorService) |
LargeFileUploader |
withMpuThreshold(long mpuThreshold) |
LargeFileUploader |
withObjectMetadata(S3ObjectMetadata objectMetadata) |
LargeFileUploader |
withPartSize(java.lang.Long partSize) |
LargeFileUploader |
withProgressListener(ProgressListener progressListener) |
LargeFileUploader |
withResumeContext(LargeFileUploaderResumeContext resumeContext) |
LargeFileUploader |
withSourceVersionId(java.lang.String sourceVersionId) |
LargeFileUploader |
withThreads(int threads) |
public static final int DEFAULT_THREADS
public static final int DEFAULT_MPU_THRESHOLD
public static final long MIN_PART_SIZE
public static final long DEFAULT_PART_SIZE
public static final int MAX_PARTS
public LargeFileUploader(S3Client s3Client, java.lang.String bucket, java.lang.String key, java.io.File file)
s3Client
to upload
file
to bucket/key
.public LargeFileUploader(S3Client s3Client, java.lang.String bucket, java.lang.String key, java.io.InputStream stream, long size)
s3Client
to upload
from a single stream
to bucket/key
. Note that this type of upload is
single-threaded and not very efficient.public LargeFileUploader(S3Client s3Client, java.lang.String bucket, java.lang.String key, LargeFileMultipartSource multipartSource)
s3Client
to upload
from a multipartSource
to bucket/key
.LargeFileMultipartSource
public LargeFileUploader(S3Client s3Client, java.lang.String srcBucket, java.lang.String srcKey, java.lang.String dstBucket, java.lang.String dstKey)
s3Client
to copy
from srcBucket/srcKey
to dstBucket/dstKey
without streaming
data between the client and ECS server.public static java.lang.String getMpuETag(java.util.List<MultipartPartETag> partETags)
public void progress(long completed, long total)
ProgressListener
progress
in interface ProgressListener
completed
- bytes completely transferredtotal
- total number of bytes to transferpublic void transferred(long size)
ProgressListener
transferred
in interface ProgressListener
size
- number of bytes transferredpublic void run()
run
in interface java.lang.Runnable
protected long getMinPartSize()
protected java.lang.String putObject(java.io.InputStream is)
protected java.util.List<MultipartPart> listParts(java.lang.String uploadId)
protected java.lang.String initMpu()
protected MultipartPartETag uploadPart(java.lang.String uploadId, int partNumber, java.io.InputStream is, long length)
protected CompleteMultipartUploadResult completeMpu(java.lang.String uploadId, java.util.SortedSet<MultipartPartETag> parts)
protected void abortMpu(java.lang.String uploadId)
public LargeFileUpload uploadAsync()
LargeFileUpload
instance.
This allows pausing or aborting the upload in the middle, or you can use waitForCompletion()
to
block until the upload is complete.upload()
public void upload()
DEFAULT_MPU_THRESHOLD
. Also note that the defaults in this class are
optimized for high-speed LAN connectivity. When operating over a WAN or a slower connection, you should reduce
the MPU threshold
and part size
proportionately.protected java.io.InputStream monitorStream(java.io.InputStream stream)
public void doSinglePut()
public void doSingleCopy()
public void doMultipartUpload()
public void doByteRangeUpload()
protected void configure()
public S3Client getS3Client()
public java.lang.String getBucket()
public java.lang.String getKey()
public java.io.InputStream getStream()
public LargeFileMultipartSource getMultipartSource()
public long getFullSize()
public long getBytesTransferred()
public java.lang.String getETag()
public java.lang.String getVersionId()
public S3ObjectMetadata getObjectMetadata()
public void setObjectMetadata(S3ObjectMetadata objectMetadata)
public AccessControlList getAcl()
public void setAcl(AccessControlList acl)
public CannedAcl getCannedAcl()
public void setCannedAcl(CannedAcl cannedAcl)
public boolean isCloseStream()
public void setCloseStream(boolean closeStream)
public long getMpuThreshold()
public void setMpuThreshold(long mpuThreshold)
upload()
method. Note the default threshold is
DEFAULT_MPU_THRESHOLD
public long getPartSize()
public void setPartSize(long partSize)
DEFAULT_PART_SIZE
and
MIN_PART_SIZE
is the minimum part size. Note also there is a maximum of 10,000 parts, and the part size
will be increased automatically if necessary.public int getThreads()
public void setThreads(int threads)
thread
parts will be
transferred in parallel. Default is 6public java.util.concurrent.ExecutorService getExecutorService()
public void setExecutorService(java.util.concurrent.ExecutorService executorService)
threads
property will be ignored.public ProgressListener getProgressListener()
public void setProgressListener(ProgressListener progressListener)
public LargeFileUploaderResumeContext getResumeContext()
resumeContext
is kept up-to-date with the uploadId and list of
uploaded parts.public void setResumeContext(LargeFileUploaderResumeContext resumeContext)
setMpuThreshold(long)
and setPartSize(long)
.S3Exception
- if the provided uploadId does not exist, or any other S3 errors occurjava.lang.IllegalArgumentException
- if the uploadId is null or any of the parts are invalidjava.lang.UnsupportedOperationException
- if the size of the source is *not* above mpuThreshold
LargeFileUploaderResumeContext
public boolean isAbortMpuOnFailure()
public void setAbortMpuOnFailure(boolean abortMpuOnFailure)
public java.lang.String getSourceVersionId()
public void setSourceVersionId(java.lang.String sourceVersionId)
public LargeFileUploader withObjectMetadata(S3ObjectMetadata objectMetadata)
public LargeFileUploader withAcl(AccessControlList acl)
public LargeFileUploader withCannedAcl(CannedAcl cannedAcl)
public LargeFileUploader withCloseStream(boolean closeStream)
public LargeFileUploader withMpuThreshold(long mpuThreshold)
public LargeFileUploader withPartSize(java.lang.Long partSize)
public LargeFileUploader withThreads(int threads)
public LargeFileUploader withExecutorService(java.util.concurrent.ExecutorService executorService)
public LargeFileUploader withProgressListener(ProgressListener progressListener)
public LargeFileUploader withResumeContext(LargeFileUploaderResumeContext resumeContext)
public LargeFileUploader withAbortMpuOnFailure(boolean abortMpuOnFailure)
setAbortMpuOnFailure(boolean)
public LargeFileUploader withSourceVersionId(java.lang.String sourceVersionId)