public class LargeFileUploader extends java.lang.Object implements java.lang.Runnable, ProgressListener
| Modifier and Type | Class and Description |
|---|---|
protected class |
LargeFileUploader.PutObjectTask |
| 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) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
configure()
This method should be idempotent
|
void |
doByteRangeUpload() |
void |
doMultipartUpload() |
void |
doSinglePut() |
AccessControlList |
getAcl() |
java.lang.String |
getBucket() |
long |
getBytesTransferred() |
CannedAcl |
getCannedAcl() |
java.lang.String |
getETag() |
java.util.concurrent.ExecutorService |
getExecutorService() |
java.io.File |
getFile() |
long |
getFullSize() |
java.lang.String |
getKey() |
long |
getMpuThreshold() |
S3ObjectMetadata |
getObjectMetadata() |
long |
getPartSize() |
ProgressListener |
getProgressListener() |
S3Client |
getS3Client() |
java.io.InputStream |
getStream() |
int |
getThreads() |
boolean |
isCloseStream() |
void |
progress(long completed,
long total)
Provides feedback on the number of bytes completed and the total number of bytes to transfer.
|
void |
run() |
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 |
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.
|
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 |
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)
public void progress(long completed,
long total)
ProgressListenerprogress in interface ProgressListenercompleted - bytes completely transferredtotal - total number of bytes to transferpublic void transferred(long size)
ProgressListenertransferred in interface ProgressListenersize - number of bytes transferredpublic void run()
run in interface java.lang.Runnablepublic 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.public void doSinglePut()
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.File getFile()
public java.io.InputStream getStream()
public long getFullSize()
public long getBytesTransferred()
public java.lang.String getETag()
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_THRESHOLDpublic 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 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)