org.lastbamboo.common.download
Class DownloadingFileLauncher

java.lang.Object
  extended by org.lastbamboo.common.download.DownloadingFileLauncher
All Implemented Interfaces:
LaunchFileTracker, org.littleshoot.util.LongRangeListener

public class DownloadingFileLauncher
extends Object
implements LaunchFileTracker

Class for tracking parts of the downloading file we can view immediately in order.


Constructor Summary
DownloadingFileLauncher(RandomAccessFile raf, PriorityBlockingQueue<org.apache.commons.lang.math.LongRange> completedRanges, URI expectedSha1, File incompleteFile)
          Creates a new tracker for streaming the file to the browser.
 
Method Summary
 int getActiveWriteCalls()
          Accessor for the number of active writers.
 void onDownloadStopped()
          Called when a download is stopped.
 void onFailure()
          Called when a download fails for any reason.
 void onFileComplete()
          Called when the file download has completed.
 void onRangeComplete(org.apache.commons.lang.math.LongRange range)
           
 void waitForLaunchersToComplete()
          Waits until all active launcher have finished their writes, typically to the browser.
 void write(OutputStream os, boolean cancelOnStreamClose)
          Writes the file to the specified stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DownloadingFileLauncher

public DownloadingFileLauncher(RandomAccessFile raf,
                               PriorityBlockingQueue<org.apache.commons.lang.math.LongRange> completedRanges,
                               URI expectedSha1,
                               File incompleteFile)
Creates a new tracker for streaming the file to the browser.

Parameters:
raf - The random access file to copy the downloaded data from.
completedRanges - The ranges that have already completed downloading.
expectedSha1 - The expected SHA-1 for the file.
incompleteFile - The incomplete file on disk.
Method Detail

onRangeComplete

public void onRangeComplete(org.apache.commons.lang.math.LongRange range)
Specified by:
onRangeComplete in interface org.littleshoot.util.LongRangeListener

onFailure

public void onFailure()
Description copied from interface: LaunchFileTracker
Called when a download fails for any reason.

Specified by:
onFailure in interface LaunchFileTracker

write

public void write(OutputStream os,
                  boolean cancelOnStreamClose)
           throws IOException
Description copied from interface: LaunchFileTracker
Writes the file to the specified stream.

Specified by:
write in interface LaunchFileTracker
Parameters:
os - The stream to write to.
Throws:
IOException - If there's any read or write error writing to the stream.

onFileComplete

public void onFileComplete()
Description copied from interface: LaunchFileTracker
Called when the file download has completed.

Specified by:
onFileComplete in interface LaunchFileTracker

getActiveWriteCalls

public int getActiveWriteCalls()
Description copied from interface: LaunchFileTracker
Accessor for the number of active writers.

Specified by:
getActiveWriteCalls in interface LaunchFileTracker
Returns:
The number of active writers.

waitForLaunchersToComplete

public void waitForLaunchersToComplete()
Description copied from interface: LaunchFileTracker
Waits until all active launcher have finished their writes, typically to the browser.

Specified by:
waitForLaunchersToComplete in interface LaunchFileTracker

onDownloadStopped

public void onDownloadStopped()
Description copied from interface: LaunchFileTracker
Called when a download is stopped.

Specified by:
onDownloadStopped in interface LaunchFileTracker


Copyright © 2013 LittleShoot. All Rights Reserved.