com.kii.cloud.storage.resumabletransfer
Class KiiUploader

java.lang.Object
  extended by com.kii.cloud.storage.resumabletransfer.KiiUploader
All Implemented Interfaces:
KiiRTransfer

public abstract class KiiUploader
extends java.lang.Object
implements KiiRTransfer

Provide apis uploading file with resumable transfer. Transition of file upload status is bellow.
X
Upload status will be stored in persistent storage. To manage suspended uploads, refer to KiiRTransferManager


Constructor Summary
KiiUploader()
           
 
Method Summary
abstract  FileHolder getFileHolder()
          Get the FileHolder of this uploader.
ex.) If uploader initiated by KiiFile.uploader(Context, File), KiiFile instance is the actual FileHolder.
abstract  java.io.File getSourceFile()
          Get the source file of this uploader.
abstract  KiiRTransferInfo info()
          Get the status of the upload.
abstract  void infoAsync(KiiRTransferCallback callback)
          Asynchronous call of info().
abstract  void suspend()
          Suspend current running upload.
abstract  void suspendAsync(KiiRTransferCallback callback)
          Asynchronous call of suspend().
abstract  void terminate()
          Terminate running/ suspended upload.
abstract  void terminateAsync(KiiRTransferCallback callback)
          Asynchronous call of terminate().
abstract  void transfer(KiiRTransferProgressCallback progress)
          Start upload file 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

KiiUploader

public KiiUploader()
Method Detail

getFileHolder

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

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

getSourceFile

public abstract java.io.File getSourceFile()
Get the source file of this uploader.

Returns:
local source file

info

public abstract KiiRTransferInfo info()
                               throws StateStoreAccessException
Get the status of the upload.
NOTE: This api access to internal file storage stores status of upload . Should not be executed in UI/Main thread.

Specified by:
info in interface KiiRTransfer
Returns:
KiiRTransferInfo represents status of upload
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 upload. If already suspended, do nothing.
NOTE: This api access to internal file storage stores status of upload . Should not be executed in UI/Main thread.

Specified by:
suspend in interface KiiRTransfer
Throws:
NoEntryException - thrown when the upload 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 upload. The entry will be removed. after termination, uploading same file would start from beginning.
NOTE: This api access to internal file storage stores status of upload . Should not be executed in UI/Main thread.

Specified by:
terminate in interface KiiRTransfer
Throws:
NoEntryException - thrown when the upload has not started yet or already done.
StateStoreAccessException - thrown when failed to access the persistent storage stores transfer state. (ex. Disk full, etc.) ongoing upload 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 upload file and wait for completion. If the suspended entry has exist for the file, automatically try to resume. otherwise start new uploading.
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 upload has already started for the file.
SuspendedException - upload has suspended. mostly network error or suspended by suspend() or suspendAsync(KiiRTransferCallback)
TerminatedException - upload has terminated due to the error or terminate() or terminateAsync(KiiRTransferCallback) has called. Stored status of the upload will be cleared. Mostly the error would be for following reasons:
  • target bucket/ file holder on cloud has deleted
  • The source file 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 upload 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