org.lastbamboo.common.download
Interface Downloader<StateT>

Type Parameters:
StateT - The type of object that maintains the state.
All Known Subinterfaces:
VisitableDownloader<StateT>
All Known Implementing Classes:
AbstractDownloader, DummySha1Downloader, MultiSourceDownloader, Sha1Downloader

public interface Downloader<StateT>

The interface to an object that manages the download of a single resource.


Method Summary
 void addListener(DownloaderListener<StateT> listener)
          Adds a listener to be notified of events of this downloader.
 File getCompleteFile()
          Returns the final path for the file.
 String getFinalName()
          The final name for the file.
 File getIncompleteFile()
          Returns the file to which this downloader downloads the resource.
 long getSize()
          Returns the size of the resource that is downloaded by this downloader.
 long getStartTime()
          Accessor the time the download started.
 StateT getState()
          Returns the current state of this downloader.
 boolean isStarted()
          Returns whether or not this downloader has already started.
 void pause()
          Pauses the download.
 void removeListener(DownloaderListener<StateT> listener)
          Removes a listener that was being notified of events of this downloader.
 void resume()
          Resumes the download.
 void start()
          Starts downloading the resource.
 void stop(boolean removeFiles)
          Stops the download.
 void write(OutputStream os, boolean cancelOnStreamClose)
          Writes the resource that this downloader downloads to a given stream.
 

Method Detail

start

void start()
Starts downloading the resource.


getState

StateT getState()
Returns the current state of this downloader.

Returns:
The current state of this downloader.

getIncompleteFile

File getIncompleteFile()
Returns the file to which this downloader downloads the resource.

Returns:
The file to which this downloader downloads the resource.

getCompleteFile

File getCompleteFile()
Returns the final path for the file.

Returns:
The final path for the file.

getSize

long getSize()
Returns the size of the resource that is downloaded by this downloader.

Returns:
The size of the resource that is downloaded by this downloader.

write

void write(OutputStream os,
           boolean cancelOnStreamClose)
Writes the resource that this downloader downloads to a given stream. The download does not have to be complete for writing to occur. This can be used to stream the content of this downloader while it is still downloading.

Parameters:
os - The output stream to which to write the resource.
cancelOnStreamClose - Whether or not the cancel the download when the stream closes.

addListener

void addListener(DownloaderListener<StateT> listener)
Adds a listener to be notified of events of this downloader.

Parameters:
listener - The listener to be notified.

removeListener

void removeListener(DownloaderListener<StateT> listener)
Removes a listener that was being notified of events of this downloader.

Parameters:
listener - The listener to remove.

isStarted

boolean isStarted()
Returns whether or not this downloader has already started.

Returns:
true if this downloader has already started, otherwise false.

getFinalName

String getFinalName()
The final name for the file.

Returns:
The final name for the file.

stop

void stop(boolean removeFiles)
Stops the download.

Parameters:
removeFiles - Whether or not to also remove all downloaded files.

pause

void pause()
Pauses the download.


resume

void resume()
Resumes the download.


getStartTime

long getStartTime()
Accessor the time the download started.

Returns:
The time the download started.


Copyright © 2013 LittleShoot. All Rights Reserved.