com.kii.cloud.storage.resumabletransfer
Class KiiDownloader

java.lang.Object
  extended by 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.
X
Download status will be stored in persistent storage. To manage suspended downloads, refer to KiiRTransferManager


Constructor Summary
KiiDownloader()
           
 
Method Summary
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 by KiiFile.downloader(Context, File), KiiFile instance is the actual FileHolder.
abstract  KiiRTransferInfo info()
          Get the status of the download.
abstract  void infoAsync(KiiRTransferCallback callback)
          Asynchronous call of info().
abstract  void suspend()
          Suspend current running download.
abstract  void suspendAsync(KiiRTransferCallback callback)
          Asynchronous call of suspend().
abstract  void terminate()
          Terminate running/ suspended download.
abstract  void terminateAsync(KiiRTransferCallback callback)
          Asynchronous call of terminate().
abstract  void transfer(KiiRTransferProgressCallback progress)
          Start download file body and wait for completion.
abstract  void transferAsync(KiiRTransferCallback callback)
          Asynchronous call of transfer(KiiRTransferProgressCallback).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KiiDownloader

public KiiDownloader()
Method Detail

getDestFile

public abstract java.io.File getDestFile()
Get the destination file of this downloader.

Returns:
local destination file.

getFileHolder

public abstract FileHolder getFileHolder()
Get the FileHolder of this downloader.
ex.) If Downloader initiated by KiiFile.downloader(Context, File), KiiFile instance is the actual FileHolder.

Specified by:
getFileHolder in interface KiiRTransfer
Returns:
FileHolder of this downloader.

info

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 interface KiiRTransfer
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(KiiRTransferCallback callback)
Asynchronous call of info().
NOTE: This method should be executed in UI thread.

Specified by:
infoAsync in interface KiiRTransfer
Parameters:
callback - Notifies events. Can not be null.
Throws:
java.lang.IllegalArgumentException - when the callback is null.
See Also:
info(), 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 interface KiiRTransfer
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(KiiRTransferCallback callback)
Asynchronous call of suspend().
NOTE: This method should be executed in UI thread.

Specified by:
suspendAsync in interface KiiRTransfer
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 interface KiiRTransfer
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(KiiRTransferCallback callback)
Asynchronous call of terminate().
NOTE: This method should be executed in UI thread.

Specified by:
terminateAsync in interface KiiRTransfer
Parameters:
callback - can be null. If provided, notifies event.
See Also:
terminate(), KiiRTransferCallback

transfer

public abstract void transfer(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 interface KiiRTransfer
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 by suspend() or suspendAsync(KiiRTransferCallback)
TerminatedException - download has terminated due to the error or terminate() or terminateAsync(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) or transferAsync(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(KiiRTransferCallback callback)
    Asynchronous call of transfer(KiiRTransferProgressCallback).
    NOTE: This method should be executed in UI thread.

    Specified by:
    transferAsync in interface KiiRTransfer
    Parameters:
    callback - can be null. If provided, notifies event (start, completion, cancelled, etc.)
    See Also:
    transfer(KiiRTransferProgressCallback), KiiRTransferProgressCallback, KiiRTransferCallback