public class LargeFileDownloader extends java.lang.Object implements java.lang.Runnable, ProgressListener
Modifier and Type | Class and Description |
---|---|
protected class |
LargeFileDownloader.DownloadPartTask |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PARALLEL_THRESHOLD |
static int |
DEFAULT_PART_SIZE |
static int |
DEFAULT_THREADS |
static int |
MIN_PART_SIZE |
Constructor and Description |
---|
LargeFileDownloader(S3Client s3Client,
java.lang.String bucket,
java.lang.String key,
java.io.File file)
Creates a new LargeFileDownloader instance that will use
s3Client to download
bucket/key to file . |
Modifier and Type | Method and Description |
---|---|
protected void |
doParallelDownload() |
protected void |
doSingleDownload() |
void |
download()
This method will automatically choose between parallel and single-GET operations based on a configured threshold.
|
java.lang.String |
getBucket() |
long |
getBytesTransferred() |
java.util.concurrent.ExecutorService |
getExecutorService() |
java.io.File |
getFile() |
java.lang.String |
getKey() |
java.lang.Long |
getObjectSize() |
long |
getParallelThreshold() |
long |
getPartSize() |
ProgressListener |
getProgressListener() |
S3Client |
getS3Client() |
int |
getThreads() |
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 |
setExecutorService(java.util.concurrent.ExecutorService executorService)
Allows for providing a custom thread executor (i.e.
|
void |
setParallelThreshold(long parallelThreshold)
Sets the threshold above which parallel operations are used to download, and below which a single-GET is used.
|
void |
setPartSize(long partSize)
Sets the size of each part to download.
|
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.
|
LargeFileDownloader |
withExecutorService(java.util.concurrent.ExecutorService executorService) |
LargeFileDownloader |
withParallelThreshold(long parallelThreshold) |
LargeFileDownloader |
withPartSize(long partSize) |
LargeFileDownloader |
withProgressListener(ProgressListener progressListener) |
LargeFileDownloader |
withThreads(int threads) |
public static final int DEFAULT_PARALLEL_THRESHOLD
public static final int MIN_PART_SIZE
public static final int DEFAULT_PART_SIZE
public static final int DEFAULT_THREADS
public LargeFileDownloader(S3Client s3Client, java.lang.String bucket, java.lang.String key, java.io.File file)
s3Client
to download
bucket/key
to file
.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
public void download()
DEFAULT_PARALLEL_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 setParallelThreshold(long)
parallel threshold} and part size
proportionately.protected void doSingleDownload() throws java.io.IOException
java.io.IOException
protected void doParallelDownload() throws java.lang.Exception
java.lang.Exception
public S3Client getS3Client()
public java.lang.String getBucket()
public java.lang.String getKey()
public java.io.File getFile()
public java.lang.Long getObjectSize()
public long getBytesTransferred()
public long getParallelThreshold()
public void setParallelThreshold(long parallelThreshold)
download()
method. Note the default threshold is
DEFAULT_PARALLEL_THRESHOLD
public long getPartSize()
public void setPartSize(long partSize)
DEFAULT_PART_SIZE
.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 LargeFileDownloader withParallelThreshold(long parallelThreshold)
public LargeFileDownloader withPartSize(long partSize)
public LargeFileDownloader withThreads(int threads)
public LargeFileDownloader withExecutorService(java.util.concurrent.ExecutorService executorService)
public LargeFileDownloader withProgressListener(ProgressListener progressListener)