org.lastbamboo.common.download
Class SingleSourceDownloader

java.lang.Object
  extended by org.lastbamboo.common.download.SingleSourceDownloader
All Implemented Interfaces:
EventListener, RangeDownloader, org.lastbamboo.common.http.client.HttpListener, org.littleshoot.util.InputStreamHandler, org.littleshoot.util.WriteListener

public class SingleSourceDownloader
extends Object
implements RangeDownloader, org.littleshoot.util.InputStreamHandler, org.lastbamboo.common.http.client.HttpListener

Downloads data from a single source.


Constructor Summary
SingleSourceDownloader(org.lastbamboo.common.http.client.CommonsHttpClient httpClient, URI source, RangeDownloadListener rangeDownloadListener, SourceRanker downloadSpeedRanker, RangeTracker rangeTracker, LaunchFileTracker launchTracker, RandomAccessFile randomAccessFile)
          Creates a downloader for downloading from a specific source.
 
Method Summary
 void download(org.apache.commons.lang.math.LongRange range)
          Downloads the specified range from the assigned file.
 org.littleshoot.util.Optional<Integer> getKbs()
          Gets the speed of this downloader in kilobytes per second.
 long getNumBytesDownloaded()
          Returns the number of bytes downloaded by this downloader.
 long getRangeIndex()
          Accessor for the byte index of the current range.
 long getRangeStartTime()
          Accessor for the time the downloader started downloading the current range.
 URI getSourceUri()
          Returns the source URI for this downloader.
 void handleInputStream(InputStream is)
           
 void issueHeadRequest()
          Sends a head request to the server this downloader is downloading from.
 void onBadHeader(String header)
           
 void onBytesRead(int bytesRead)
           
 void onConnect(long ms)
           
 void onContentLength(long contentLength)
           
 void onContentRange(org.apache.commons.lang.math.LongRange range)
           
 void onCouldNotConnect()
           
 void onDownloadStarted()
           
 void onFailure()
           
 void onHttpException(org.apache.commons.httpclient.HttpException httpException)
           
 void onMessageBodyRead()
           
 void onNoTwoHundredOk(int responseCode)
           
 void onPermanentFailure()
           
 void onStatusEvent(String status)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SingleSourceDownloader

public SingleSourceDownloader(org.lastbamboo.common.http.client.CommonsHttpClient httpClient,
                              URI source,
                              RangeDownloadListener rangeDownloadListener,
                              SourceRanker downloadSpeedRanker,
                              RangeTracker rangeTracker,
                              LaunchFileTracker launchTracker,
                              RandomAccessFile randomAccessFile)
Creates a downloader for downloading from a specific source.

Parameters:
httpClient - The HTTP client instance to use for performing downloads.
source - The URI for the source to download from.
rangeDownloadListener - The listener for range download events.
downloadSpeedRanker - The class for ranking sources.
rangeTracker - The class for tracking needed ranges in the file.
launchTracker - The tracker for bytes to send to the launch file.
randomAccessFile - The class to store downloaded bytes to.
Method Detail

download

public void download(org.apache.commons.lang.math.LongRange range)
Description copied from interface: RangeDownloader
Downloads the specified range from the assigned file.

Specified by:
download in interface RangeDownloader
Parameters:
range - The byte range to download.

issueHeadRequest

public void issueHeadRequest()
Description copied from interface: RangeDownloader
Sends a head request to the server this downloader is downloading from.

Specified by:
issueHeadRequest in interface RangeDownloader

getKbs

public org.littleshoot.util.Optional<Integer> getKbs()
Description copied from interface: RangeDownloader
Gets the speed of this downloader in kilobytes per second.

Specified by:
getKbs in interface RangeDownloader
Returns:
The speed of this downloader in kilobytes per second.

getNumBytesDownloaded

public long getNumBytesDownloaded()
Description copied from interface: RangeDownloader
Returns the number of bytes downloaded by this downloader.

Specified by:
getNumBytesDownloaded in interface RangeDownloader
Returns:
The number of bytes downloaded by this downloader.

getSourceUri

public URI getSourceUri()
Description copied from interface: RangeDownloader
Returns the source URI for this downloader.

Specified by:
getSourceUri in interface RangeDownloader
Returns:
The source URI for this downloader.

handleInputStream

public void handleInputStream(InputStream is)
                       throws IOException
Specified by:
handleInputStream in interface org.littleshoot.util.InputStreamHandler
Throws:
IOException

onContentLength

public void onContentLength(long contentLength)
Specified by:
onContentLength in interface org.lastbamboo.common.http.client.HttpListener

onCouldNotConnect

public void onCouldNotConnect()
Specified by:
onCouldNotConnect in interface org.lastbamboo.common.http.client.HttpListener

onConnect

public void onConnect(long ms)
Specified by:
onConnect in interface org.lastbamboo.common.http.client.HttpListener

onFailure

public void onFailure()
Specified by:
onFailure in interface org.lastbamboo.common.http.client.HttpListener

onPermanentFailure

public void onPermanentFailure()
Specified by:
onPermanentFailure in interface org.lastbamboo.common.http.client.HttpListener

onHttpException

public void onHttpException(org.apache.commons.httpclient.HttpException httpException)
Specified by:
onHttpException in interface org.lastbamboo.common.http.client.HttpListener

onNoTwoHundredOk

public void onNoTwoHundredOk(int responseCode)
Specified by:
onNoTwoHundredOk in interface org.lastbamboo.common.http.client.HttpListener

onMessageBodyRead

public void onMessageBodyRead()
Specified by:
onMessageBodyRead in interface org.lastbamboo.common.http.client.HttpListener

onBadHeader

public void onBadHeader(String header)
Specified by:
onBadHeader in interface org.lastbamboo.common.http.client.HttpListener

onContentRange

public void onContentRange(org.apache.commons.lang.math.LongRange range)
                    throws IOException
Specified by:
onContentRange in interface org.lastbamboo.common.http.client.HttpListener
Throws:
IOException

onStatusEvent

public void onStatusEvent(String status)
Specified by:
onStatusEvent in interface org.lastbamboo.common.http.client.HttpListener

onDownloadStarted

public void onDownloadStarted()
Specified by:
onDownloadStarted in interface org.lastbamboo.common.http.client.HttpListener

onBytesRead

public void onBytesRead(int bytesRead)
Specified by:
onBytesRead in interface org.littleshoot.util.WriteListener

getRangeStartTime

public long getRangeStartTime()
Description copied from interface: RangeDownloader
Accessor for the time the downloader started downloading the current range.

Specified by:
getRangeStartTime in interface RangeDownloader
Returns:
The time the downloader started downloading the current range.

getRangeIndex

public long getRangeIndex()
Description copied from interface: RangeDownloader
Accessor for the byte index of the current range.

Specified by:
getRangeIndex in interface RangeDownloader
Returns:
The byte index for the current range.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 LittleShoot. All Rights Reserved.