Class KiiDownloader
- java.lang.Object
-
- com.kii.cloud.storage.resumabletransfer.KiiDownloader
-
- All Implemented Interfaces:
KiiRTransfer
public abstract class KiiDownloader extends java.lang.Object implements KiiRTransfer
Provide apis downloading file with resumable transfer. Transition of file download status is bellow.
Download status will be stored in persistent storage. To manage suspended downloads, refer toKiiRTransferManager
-
-
Constructor Summary
Constructors Constructor Description KiiDownloader()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract java.io.File
getDestFile()
Get the destination file of this downloader.abstract FileHolder
getFileHolder()
Get the FileHolder of this downloader.
ex.) If Downloader initiated byKiiObject.downloader(android.content.Context, File)
, KiiObject instance is the actual FileHolder.abstract KiiRTransferInfo
info()
Get the status of the download.abstract void
infoAsync(KiiRTransferCallback callback)
Asynchronous call ofinfo()
.abstract void
suspend()
Suspend current running download.abstract void
suspendAsync(KiiRTransferCallback callback)
Asynchronous call ofsuspend()
.abstract void
terminate()
Terminate running/ suspended download.abstract void
terminateAsync(KiiRTransferCallback callback)
Asynchronous call ofterminate()
.abstract void
transfer(KiiRTransferProgressCallback progress)
Start download file body and wait for completion.abstract void
transferAsync(KiiRTransferCallback callback)
Asynchronous call oftransfer(KiiRTransferProgressCallback)
.
-
-
-
Method Detail
-
getFileHolder
public abstract FileHolder getFileHolder()
Get the FileHolder of this downloader.
ex.) If Downloader initiated byKiiObject.downloader(android.content.Context, File)
, KiiObject instance is the actual FileHolder.- Specified by:
getFileHolder
in interfaceKiiRTransfer
- Returns:
- FileHolder of this downloader.
-
transfer
public abstract void transfer(@Nullable KiiRTransferProgressCallback progress) throws AlreadyStartedException, SuspendedException, TerminatedException, StateStoreAccessException
Start download file body and wait for completion. If the suspended entry has exist for the file, automatically try to resume. otherwise start new downloading.
NOTE: This api access to server. Should not be executed in UI/Main thread.- Specified by:
transfer
in interfaceKiiRTransfer
- Parameters:
progress
- can be null. If provided, progress information will be notified.- Throws:
AlreadyStartedException
- when the download has already started for the file.SuspendedException
- download has suspended. mostly network error or suspended bysuspend()
orsuspendAsync(KiiRTransferCallback)
TerminatedException
- download has terminated due to the error orterminate()
orterminateAsync(KiiRTransferCallback)
has called. Stored status of the download will be cleared. Mostly the error would be for following reasons:
- target bucket/ file holder on cloud has deleted
- The destination file or the file body in the cloud has been modified.In this case, calling
transfer(KiiRTransferProgressCallback)
ortransferAsync(KiiRTransferCallback)
again upload the modified file from the beginning.StateStoreAccessException
- thrown when failed to access the persistent storage stores transfer state. (ex. Disk full, etc.) The download will be suspended and you can retry safely.- See Also:
KiiRTransferProgressCallback
,transferAsync(KiiRTransferCallback)
-
transferAsync
public abstract void transferAsync(@Nullable KiiRTransferCallback callback)
Asynchronous call oftransfer(KiiRTransferProgressCallback)
.
NOTE: This method should be executed in UI thread.- Specified by:
transferAsync
in interfaceKiiRTransfer
- Parameters:
callback
- can be null. If provided, notifies event (start, completion, cancelled, etc.)- See Also:
transfer(KiiRTransferProgressCallback)
,KiiRTransferProgressCallback
,KiiRTransferCallback
-
suspend
public abstract void suspend() throws NoEntryException, StateStoreAccessException
Suspend current running download. If already suspended, do nothing.
NOTE: This api access to internal file storage stores status of download. Should not be executed in UI/Main thread.- Specified by:
suspend
in interfaceKiiRTransfer
- Throws:
NoEntryException
- thrown when the download has finished or not started.StateStoreAccessException
- thrown when failed to access the persistent storage stores transfer state. (ex. Disk full, etc.) suspend will be failed.- See Also:
NoEntryException
,suspendAsync(KiiRTransferCallback)
-
suspendAsync
public abstract void suspendAsync(@Nullable KiiRTransferCallback callback)
Asynchronous call ofsuspend()
.
NOTE: This method should be executed in UI thread.- Specified by:
suspendAsync
in interfaceKiiRTransfer
- Parameters:
callback
- can be null. If provided, notifies event.- See Also:
suspend()
,KiiRTransferCallback
-
terminate
public abstract void terminate() throws NoEntryException, StateStoreAccessException
Terminate running/ suspended download. The entry will be removed. After termination, downloading same file would start from beginning.
NOTE: This api access to internal file storage stores status of download. Should not be executed in UI/Main thread.- Specified by:
terminate
in interfaceKiiRTransfer
- Throws:
NoEntryException
- thrown when the download has not started yet or already done.StateStoreAccessException
- thrown when failed to access the persistent storage stores transfer state. (ex. Disk full, etc.) ongoing download will be cancelled but failed to remove the entry in the storage. The state will be transit to suspended.- See Also:
terminateAsync(KiiRTransferCallback)
-
terminateAsync
public abstract void terminateAsync(@Nullable KiiRTransferCallback callback)
Asynchronous call ofterminate()
.
NOTE: This method should be executed in UI thread.- Specified by:
terminateAsync
in interfaceKiiRTransfer
- Parameters:
callback
- can be null. If provided, notifies event.- See Also:
terminate()
,KiiRTransferCallback
-
info
@Nullable public abstract KiiRTransferInfo info() throws StateStoreAccessException
Get the status of the download.
NOTE: This api access to internal file storage stores status of download. Should not be executed in UI/Main thread.- Specified by:
info
in interfaceKiiRTransfer
- Returns:
- KiiRTransferInfo represents status of download.
- Throws:
StateStoreAccessException
- Thrown when failed to access persistent storage stores transfer state. (ex. Disk full, etc.)
You can retry safely.- See Also:
KiiRTransferInfo
,infoAsync(KiiRTransferCallback)
-
infoAsync
public abstract void infoAsync(@NonNull KiiRTransferCallback callback)
Asynchronous call ofinfo()
.
NOTE: This method should be executed in UI thread.- Specified by:
infoAsync
in interfaceKiiRTransfer
- Parameters:
callback
- Notifies events. Can not be null.- Throws:
java.lang.IllegalArgumentException
- when the callback is null.- See Also:
info()
,KiiRTransferCallback
-
getDestFile
@NonNull public abstract java.io.File getDestFile()
Get the destination file of this downloader.- Returns:
- local destination file.
-
-