public interface BaseDownloadTask
FileDownloader,
ITaskHunter| Modifier and Type | Interface and Description |
|---|---|
static interface |
BaseDownloadTask.FinishListener |
static interface |
BaseDownloadTask.InQueueTask
Declare the task will be assembled by a queue which makes up of the same listener task.
|
static interface |
BaseDownloadTask.IRunningTask
The running task.
|
static interface |
BaseDownloadTask.LifeCycleCallback
The callback for the life cycle of the task.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_CALLBACK_PROGRESS_MIN_INTERVAL_MILLIS |
| Modifier and Type | Method and Description |
|---|---|
BaseDownloadTask |
addFinishListener(BaseDownloadTask.FinishListener finishListener)
Add the finish listener to listen when the task is finished.
|
BaseDownloadTask |
addHeader(java.lang.String line)
Add a field with the specified value to the request header.
|
BaseDownloadTask |
addHeader(java.lang.String name,
java.lang.String value)
Add the params to the request header.
|
BaseDownloadTask.InQueueTask |
asInQueueTask()
Declare the task will be assembled by a queue which makes up of the same listener task.
|
boolean |
cancel()
Deprecated.
replace with
pause() |
int |
getAutoRetryTimes() |
int |
getCallbackProgressMinInterval() |
int |
getCallbackProgressTimes() |
int |
getDownloadId()
Deprecated.
Used
getId() instead. |
java.lang.Throwable |
getErrorCause() |
java.lang.String |
getEtag() |
java.lang.Throwable |
getEx()
Deprecated.
Replaced with
getErrorCause() |
java.lang.String |
getFilename() |
int |
getId()
The downloading identify of this task, what is generated by
getUrl() and
getPath() and isPathAsDirectory() from
FileDownloadUtils.generateId(String, String). |
long |
getLargeFileSoFarBytes()
This method will be used when the length of target file is more than 1.99G.
|
long |
getLargeFileTotalBytes()
This method will be used when the length of target file is more than 1.99G.
|
FileDownloadListener |
getListener() |
java.lang.String |
getPath() |
int |
getRetryingTimes() |
int |
getSmallFileSoFarBytes()
This method will be used when the length of target file is less than or equal to 1.99G.
|
int |
getSmallFileTotalBytes()
This method will be used when the length of target file is less than or equal to 1.99G.
|
int |
getSoFarBytes()
Deprecated.
replace with
getSmallFileSoFarBytes(). |
int |
getSpeed()
Get the downloading speed.
|
byte |
getStatus() |
java.lang.Object |
getTag() |
java.lang.Object |
getTag(int key)
Returns the tag associated with this task and the specified key.
|
java.lang.String |
getTargetFilePath() |
int |
getTotalBytes()
Deprecated.
replace with
getSmallFileTotalBytes()} |
java.lang.String |
getUrl() |
boolean |
isAttached()
Whether this task has already attached to a listener / a serial-queue.
|
boolean |
isContinue()
Deprecated.
Use
isResuming() instead. |
boolean |
isForceReDownload() |
boolean |
isLargeFile() |
boolean |
isPathAsDirectory() |
boolean |
isResuming() |
boolean |
isReusedOldFile() |
boolean |
isRunning() |
boolean |
isSyncCallback() |
boolean |
isUsing() |
boolean |
isWifiRequired() |
boolean |
pause()
Why pause? not stop/cancel? because invoke this method(pause) will clear all data about this
task in memory, and stop the total processing about this task.
|
int |
ready()
Deprecated.
please use
asInQueueTask() first and when you need to enqueue this task
to the global queue to make this task is ready to be assembled by the queue which makes up of
the same listener task, just invoke BaseDownloadTask.InQueueTask.enqueue(). |
BaseDownloadTask |
removeAllHeaders(java.lang.String name)
Remove all fields in the request header.
|
boolean |
removeFinishListener(BaseDownloadTask.FinishListener finishListener)
Remove the finish listener from this task.
|
boolean |
reuse()
Reuse this task withhold request params: path、url、header、isForceReDownloader、etc.
|
BaseDownloadTask |
setAutoRetryTimes(int autoRetryTimes)
Set the number of times to retry when encounter any error, except
FileDownloadGiveUpRetryException. |
BaseDownloadTask |
setCallbackProgressIgnored()
Ignore all callbacks of
FileDownloadListener.progress(BaseDownloadTask, int, int)
during the entire process of downloading. |
BaseDownloadTask |
setCallbackProgressMinInterval(int minIntervalMillis)
Set the minimum time interval between each callback of
FileDownloadListener.progress(BaseDownloadTask, int, int). |
BaseDownloadTask |
setCallbackProgressTimes(int callbackProgressCount)
Set the maximum callback count of
FileDownloadListener.progress(BaseDownloadTask, int, int) during the entire process
of downloading. |
BaseDownloadTask |
setFinishListener(BaseDownloadTask.FinishListener finishListener)
Deprecated.
Replace with
addFinishListener(FinishListener) |
BaseDownloadTask |
setForceReDownload(boolean isForceReDownload)
Force re-downloading the file regardless the target file is exist.
|
BaseDownloadTask |
setListener(FileDownloadListener listener) |
BaseDownloadTask |
setMinIntervalUpdateSpeed(int minIntervalUpdateSpeedMs) |
BaseDownloadTask |
setPath(java.lang.String path) |
BaseDownloadTask |
setPath(java.lang.String path,
boolean pathAsDirectory) |
BaseDownloadTask |
setSyncCallback(boolean syncCallback) |
BaseDownloadTask |
setTag(int key,
java.lang.Object tag)
Set a tag associated with this task, not be used by internal.
|
BaseDownloadTask |
setTag(java.lang.Object tag)
Sets the tag associated with this task, not be used by internal.
|
BaseDownloadTask |
setWifiRequired(boolean isWifiRequired)
Set whether this task only allows downloading on the wifi network type.
|
int |
start()
Start this task in parallel.
|
static final int DEFAULT_CALLBACK_PROGRESS_MIN_INTERVAL_MILLIS
BaseDownloadTask setMinIntervalUpdateSpeed(int minIntervalUpdateSpeedMs)
minIntervalUpdateSpeedMs - The minimum interval millisecond for updating the downloading
speed in downloading process(Status equal to progress).
Default: 5 ms.
If the value is less than or equal to 0, will not calculate the download speed in process.
BaseDownloadTask setPath(java.lang.String path)
path - path = (absolute directory/filename); and isPathAsDirectory()
assign to false.BaseDownloadTask setPath(java.lang.String path, boolean pathAsDirectory)
path - The absolute path for saving the download file.pathAsDirectory - true: if the path is absolute directory to store the
downloading file, and the filename will be found in
contentDisposition from the response as default, if can't find
contentDisposition,the filename will be generated by
FileDownloadUtils.generateFileName(String) with url.
false: if the path = (absolute directory/filename).isPathAsDirectory(),
getFilename()BaseDownloadTask setListener(FileDownloadListener listener)
listener - For callback download status(pending,connected,progress,
blockComplete,retry,error,paused,completed,warn)BaseDownloadTask setCallbackProgressTimes(int callbackProgressCount)
FileDownloadListener.progress(BaseDownloadTask, int, int) during the entire process
of downloading.
Note: this function will not work if the URL is refer to 'chucked' resource.
callbackProgressCount - The maximum callback count of
FileDownloadListener.progress(com.liulishuo.filedownloader.BaseDownloadTask, int, int)
during the entire process of downloading.
Default value is 100, If the value less than or equal to 0, you
will not receive any callback of
FileDownloadListener.progress(com.liulishuo.filedownloader.BaseDownloadTask, int, int)
.
setCallbackProgressMinInterval(int)BaseDownloadTask setCallbackProgressMinInterval(int minIntervalMillis)
FileDownloadListener.progress(BaseDownloadTask, int, int).minIntervalMillis - The minimum interval between each callback of
FileDownloadListener.progress(BaseDownloadTask, int, int).
Unit: millisecond.
Default value is
DEFAULT_CALLBACK_PROGRESS_MIN_INTERVAL_MILLIS.
Scope: [5, Integer.MAX_VALUE.
setCallbackProgressTimes(int)BaseDownloadTask setCallbackProgressIgnored()
FileDownloadListener.progress(BaseDownloadTask, int, int)
during the entire process of downloading. This will optimize the performance.BaseDownloadTask setTag(java.lang.Object tag)
BaseDownloadTask setTag(int key, java.lang.Object tag)
key - The key of identifying the tag.
If the key already exists, the old data will be replaced.tag - An Object to tag the task withBaseDownloadTask setForceReDownload(boolean isForceReDownload)
isForceReDownload - If set to true, will not check whether the target file is exist.
Default: false.
BaseDownloadTask setFinishListener(BaseDownloadTask.FinishListener finishListener)
addFinishListener(FinishListener)BaseDownloadTask addFinishListener(BaseDownloadTask.FinishListener finishListener)
This listener's method BaseDownloadTask.FinishListener.over(BaseDownloadTask) will be invoked in
Internal-Flow-Thread directly, which is controlled by MessageSnapshotThreadPool.
finishListener - The finish listener.FileDownloadStatus.isOver(int)boolean removeFinishListener(BaseDownloadTask.FinishListener finishListener)
finishListener - The finish listener.true if remove the finishListener successfully.
false otherwise.BaseDownloadTask setAutoRetryTimes(int autoRetryTimes)
FileDownloadGiveUpRetryException.autoRetryTimes - The retry times, default 0.BaseDownloadTask addHeader(java.lang.String name, java.lang.String value)
Note: We have already handled Etag internal for guaranteeing tasks resuming from the breakpoint, in other words, if the task has downloaded and got Etag, we will add the 'If-Match' and the 'Range' K-V to its request header automatically.
BaseDownloadTask addHeader(java.lang.String line)
BaseDownloadTask removeAllHeaders(java.lang.String name)
BaseDownloadTask setSyncCallback(boolean syncCallback)
syncCallback - true FileDownloader will invoke methods of
FileDownloadListener directly on the download thread(isn't in the
main thread).BaseDownloadTask setWifiRequired(boolean isWifiRequired)
false
Note: If isWifiRequired is true, FileDownloader will check
the network type every time after fetch less than or equal to 4096 bytes data from the
network, what will result in slowing the download speed slightly.
Permission: If isWifiRequired is true, You need declare the
permission Manifest.permission.ACCESS_NETWORK_STATE in your manifest, let
FileDownloader has permission to check the network type in downloading, if you start this
task without this permission you will receive a FileDownloadGiveUpRetryException.
isWifiRequired - true This task only allow to download on the wifi network type.int ready()
asInQueueTask() first and when you need to enqueue this task
to the global queue to make this task is ready to be assembled by the queue which makes up of
the same listener task, just invoke BaseDownloadTask.InQueueTask.enqueue().
Note: If this task doesn't belong to a queue, what is just an isolated task,
you just need to invoke start() to start this task, that's all. In other words, If
this task doesn't belong to a queue, you must not invoke this method or
BaseDownloadTask.InQueueTask.enqueue() method before invoke start(), If you do that and if
there is the same listener object to start a queue in another thread, this task may be
assembled by the queue, in that case, when you invoke start() manually to start this
task or this task is started by the queue, there is an exception buried in there, because
this task object is started two times without declare reuse() : 1. you invoke
start() manually; 2. the queue start this task automatically.
FileDownloader.start(FileDownloadListener, boolean)BaseDownloadTask.InQueueTask asInQueueTask()
Note: If you use FileDownloadQueueSet to start this task in a queue,
you don't need to invoke this method manually, it has been handled by
FileDownloadQueueSet.
BaseDownloadTask.InQueueTask.enqueue() to
enqueue this task to the global queue to ready for being assembled by the queue.boolean reuse()
Note:If the task has been over(FileDownloadStatus.isOver(int)), but
the over-message has not been handover to the listener, since the callback is asynchronous,
once your invoke this 'reuse' method, that message would be discard, for free the messenger.
true if reuse this task successfully. false otherwise.boolean isUsing()
true if the this task already has downloading data, it means that this task
is running or has ran.isRunning(),
start(),
reuse()boolean isRunning()
boolean isAttached()
true if this task is running, and it has already attached to the listener or
has already assembled to a serial-queue and would be started automatically when it is come to
its turn.IQueuesHandler.startQueueSerial(FileDownloadListener),
IQueuesHandler.startQueueParallel(FileDownloadListener)int start()
boolean pause()
true, if pause this task successfully, false otherwise this task has
already in over status before invoke this method(this case maybe occurred in high concurrent
situation).FileDownloader.pause(int),
FileDownloader.pause(FileDownloadListener),
FileDownloader.pauseAll()boolean cancel()
pause()true if cancel this task successfully.int getId()
getUrl() and
getPath() and isPathAsDirectory() from
FileDownloadUtils.generateId(String, String).FileDownloader.pause(int),
FileDownloader.getStatus(String, String),
FileDownloader.getTotal(int),
FileDownloader.getSoFar(int)int getDownloadId()
getId() instead.java.lang.String getUrl()
int getCallbackProgressTimes()
FileDownloadListener.progress(BaseDownloadTask, int, int) during the entire process
of downloading.int getCallbackProgressMinInterval()
FileDownloadListener.progress(BaseDownloadTask, int, int) .java.lang.String getPath()
isPathAsDirectory() is true: path is a absolute directory
to store the downloading file, and the filename will be found in contentDisposition
from the response as default, if can't find contentDisposition, the filename will be
generated by FileDownloadUtils.generateFileName(String) with url. otherwise
path is the absolute path of the target file.boolean isPathAsDirectory()
java.lang.String getFilename()
isPathAsDirectory() is true, the filename will be found
in contentDisposition from the response as default, if can't find contentDisposition, the
filename will be generated by FileDownloadUtils.generateFileName(String) with
url. It will be found before the callback of
FileDownloadListener.connected(BaseDownloadTask, String, boolean, int, int).
If isPathAsDirectory() is false, the filename will be found
immediately when you invoke setPath(String, boolean) .java.lang.String getTargetFilePath()
FileDownloadListener getListener()
int getSoFarBytes()
getSmallFileSoFarBytes().int getSmallFileSoFarBytes()
long getLargeFileSoFarBytes()
int getTotalBytes()
getSmallFileTotalBytes()}
Note: this value will be valid
after FileDownloadListener.connected(BaseDownloadTask, String, boolean, int, int) or
it has already have in the database.
int getSmallFileTotalBytes()
long getLargeFileTotalBytes()
int getSpeed()
If the task is in the downloading process(status equal FileDownloadStatus.progress) :
The value is a real-time speed. it is calculated when the interval from the last calculation
more than setMinIntervalUpdateSpeed(int) before each
FileDownloadListener.progress(BaseDownloadTask, int, int) call-back method.
FileDownloadStatus.isOver(int)): The value is a average
speed. it is calculated from the entire downloading travel(connected, over).setMinIntervalUpdateSpeed(int)byte getStatus()
FileDownloadStatusboolean isForceReDownload()
true if this task force re-download regard less the target file has already
exist.java.lang.Throwable getEx()
getErrorCause()java.lang.Throwable getErrorCause()
boolean isReusedOldFile()
true if this task didn't start downloading really, because the target file
has already exist. false otherwise.isForceReDownload()java.lang.Object getTag()
java.lang.Object getTag(int key)
key - The key identifying the tag.null if not
set.setTag(int, Object),
getTag()boolean isContinue()
isResuming() instead.boolean isResuming()
true if this task is resuming from the breakpoint, this value is valid
after FileDownloadListener.connected(BaseDownloadTask, String, boolean, int, int).java.lang.String getEtag()
FileDownloadListener.connected(BaseDownloadTask, String, boolean, int, int)int getAutoRetryTimes()
setAutoRetryTimes(int)int getRetryingTimes()
FileDownloadListener.retry(BaseDownloadTask, Throwable, int, int)boolean isSyncCallback()
true if the methods of FileDownloadListener will be invoked directly
in message-thread for this task, false all methods of FileDownloadListener
will
be post to the UI thread for this task.setSyncCallback(boolean)boolean isLargeFile()
true if the length of target file is more than or equal to 2G.getLargeFileSoFarBytes(),
getLargeFileTotalBytes()boolean isWifiRequired()
true if this task has been set only allows downloading on the wifi network
type.