org.lastbamboo.common.download
Class MultiSourceDownloader

java.lang.Object
  extended by org.lastbamboo.common.download.AbstractDownloader<MsDState>
      extended by org.lastbamboo.common.download.MultiSourceDownloader
All Implemented Interfaces:
Downloader<MsDState>, LittleShootDownloader, StreamableDownloader, VisitableDownloader<MsDState>

public final class MultiSourceDownloader
extends AbstractDownloader<MsDState>
implements VisitableDownloader<MsDState>, LittleShootDownloader

A downloader that can download from multiple sources simultaneously.


Constructor Summary
MultiSourceDownloader(File incompleteFile, URI uri, long size, UriResolver uriResolver, int connectionsPerHost, URI expectedSha1, File downloadsDir, boolean streamable)
          Constructs a new downloader.
 
Method Summary
<T> T
accept(DownloadVisitor<T> visitor)
          Accepts the specified visitor class.
 long getBytesRead()
           
 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.
 MsDState getState()
          Returns the current state of this downloader.
 boolean isStarted()
          Returns whether or not this downloader has already started.
 boolean isStreamable()
          Returns whether or not this downloader can be streamed.
 void pause()
          Pauses the download.
 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.
 
Methods inherited from class org.lastbamboo.common.download.AbstractDownloader
addListener, fireStateChanged, getStartTime, removeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.lastbamboo.common.download.Downloader
addListener, getStartTime, removeListener
 
Methods inherited from interface org.lastbamboo.common.download.StreamableDownloader
getStartTime
 

Constructor Detail

MultiSourceDownloader

public MultiSourceDownloader(File incompleteFile,
                             URI uri,
                             long size,
                             UriResolver uriResolver,
                             int connectionsPerHost,
                             URI expectedSha1,
                             File downloadsDir,
                             boolean streamable)
Constructs a new downloader.

Parameters:
incompleteFile - The path for the incomplete file we're downloading to. This will of course be complete when we're done.
uri - The URI for the file.
size - The size of the file in bytes.
uriResolver - The class we'll use to resolve all initial locations for the file.
connectionsPerHost - The number of connections to allow to each HTTP server. Multiple connections to HTTP servers can speed up transfers.
expectedSha1 - The expected SHA-1 URN.
downloadsDir - The directory we're ultimately downloading to.
streamable - Whether or not this download can be streamed.
Method Detail

start

public void start()
Description copied from interface: Downloader
Starts downloading the resource.

Specified by:
start in interface Downloader<MsDState>

getIncompleteFile

public File getIncompleteFile()
Description copied from interface: Downloader
Returns the file to which this downloader downloads the resource.

Specified by:
getIncompleteFile in interface Downloader<MsDState>
Returns:
The file to which this downloader downloads the resource.

getSize

public long getSize()
Description copied from interface: Downloader
Returns the size of the resource that is downloaded by this downloader.

Specified by:
getSize in interface Downloader<MsDState>
Returns:
The size of the resource that is downloaded by this downloader.

getState

public MsDState getState()
Description copied from interface: Downloader
Returns the current state of this downloader.

Specified by:
getState in interface Downloader<MsDState>
Returns:
The current state of this downloader.

isStarted

public boolean isStarted()
Description copied from interface: Downloader
Returns whether or not this downloader has already started.

Specified by:
isStarted in interface Downloader<MsDState>
Returns:
true if this downloader has already started, otherwise false.

write

public void write(OutputStream os,
                  boolean cancelOnStreamClose)
Description copied from interface: Downloader
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.

Specified by:
write in interface Downloader<MsDState>
Parameters:
os - The output stream to which to write the resource.
cancelOnStreamClose - Whether or not the cancel the download when the stream closes.

stop

public void stop(boolean removeFiles)
Description copied from interface: Downloader
Stops the download.

Specified by:
stop in interface Downloader<MsDState>
Parameters:
removeFiles - Whether or not to also remove all downloaded files.

pause

public void pause()
Description copied from interface: Downloader
Pauses the download.

Specified by:
pause in interface Downloader<MsDState>

resume

public void resume()
Description copied from interface: Downloader
Resumes the download.

Specified by:
resume in interface Downloader<MsDState>

getFinalName

public String getFinalName()
Description copied from interface: Downloader
The final name for the file.

Specified by:
getFinalName in interface Downloader<MsDState>
Returns:
The final name for the file.

getCompleteFile

public File getCompleteFile()
Description copied from interface: Downloader
Returns the final path for the file.

Specified by:
getCompleteFile in interface Downloader<MsDState>
Returns:
The final path for the file.

accept

public <T> T accept(DownloadVisitor<T> visitor)
Description copied from interface: VisitableDownloader
Accepts the specified visitor class.

Specified by:
accept in interface VisitableDownloader<MsDState>
Type Parameters:
T - The type the visitor will return.
Parameters:
visitor - The visitor to accept.
Returns:
The return value of the visitor.

isStreamable

public boolean isStreamable()
Description copied from interface: StreamableDownloader
Returns whether or not this downloader can be streamed.

Specified by:
isStreamable in interface StreamableDownloader
Returns:
true if the downloader can be streamed, otherwise false.

getBytesRead

public long getBytesRead()


Copyright © 2013 LittleShoot. All Rights Reserved.