codesimian
Interface Files.DownloadListener

Enclosing class:
Files

public static interface Files.DownloadListener

Watches a download of a file or URL many times as more and more bytes are downloaded. During the download, those bytes can be accessed by an InputStream. After the download, all the bytes are returned as a byte[] array.

Specifies when updates should be given and what to do when the download ends correctly or in error. Specifies how long to wait in total and after each incremental download, before ending in error.

NEED TO ADD InputStream parameters parallel to String fileNameOrURL. Or move that to a different interface?


Method Summary
 void done(java.lang.String fileNameOrURL, byte[] bytes)
          when the download is done, all the bytes are returned, the same byte[] array from the InputStream in update()
 void downloadStarted(java.lang.String fileNameOrURL, int endSize, long startTime)
          the connection is made, but no bytes downloaded yet
 void failed(java.lang.String fileNameOrURL, java.io.IOException error)
          if the download ends with some error
 long minimumUpdateIncrementInMilliseconds()
          update() will not be called if its too soon after the last update()
 long timeOutAll()
          end the download if whole download not done in this many milliseconds
 long timeOutIncrement()
          end the download if download some bytes, but not download any more bytes for this many milliseconds
 void update(java.lang.String fileNameOrURL, java.io.InputStream bytes, int endSize, long timeSoFar)
          update() is called when updateIncrementInBytes more bytes are downloaded, but not if minimumUpdateIncrementInMilliseconds time has not yet elapsed.
 int updateIncrementInBytes()
          downloader should call update() when this many more bytes have been downloaded since the last update() or downloadStarted()
 

Method Detail

timeOutIncrement

long timeOutIncrement()
end the download if download some bytes, but not download any more bytes for this many milliseconds


timeOutAll

long timeOutAll()
end the download if whole download not done in this many milliseconds


updateIncrementInBytes

int updateIncrementInBytes()
downloader should call update() when this many more bytes have been downloaded since the last update() or downloadStarted()


minimumUpdateIncrementInMilliseconds

long minimumUpdateIncrementInMilliseconds()
update() will not be called if its too soon after the last update()


downloadStarted

void downloadStarted(java.lang.String fileNameOrURL,
                     int endSize,
                     long startTime)
the connection is made, but no bytes downloaded yet


update

void update(java.lang.String fileNameOrURL,
            java.io.InputStream bytes,
            int endSize,
            long timeSoFar)
update() is called when updateIncrementInBytes more bytes are downloaded, but not if minimumUpdateIncrementInMilliseconds time has not yet elapsed.

The InputStream contains all bytes downloaded so far, returned by InputStream.available(). If you wait until later calls of update() or done(), that same InputStream will have more bytes.


done

void done(java.lang.String fileNameOrURL,
          byte[] bytes)
when the download is done, all the bytes are returned, the same byte[] array from the InputStream in update()


failed

void failed(java.lang.String fileNameOrURL,
            java.io.IOException error)
if the download ends with some error