com.bbn.swede.core.libraries
Class DownloadFileOperation

java.lang.Object
  extended bycom.bbn.swede.core.libraries.DownloadFileOperation

public class DownloadFileOperation
extends Object

Generalized operation suitable for downloading a file from a URL. Supports progress monitoring and cancelation. This operation is intended to be run only once. Attempting to run the operation more than once will lead to undefined behaviour.

Author:
aperezlo

Constructor Summary
DownloadFileOperation(URL source)
          Creates a runnable to download a file from the web.
DownloadFileOperation(URL source, File downloadDirectory, String filename, boolean shouldDelete)
          Creates a runnable to download a file from the web.
DownloadFileOperation(URL source, String filename, boolean shouldDelete)
          Creates a runnable to download a file from the web.
 
Method Summary
 List getExceptions()
          Returns a List containing any and all exceptions generated by this operation.
 File getFile()
          Return a handle to the downloaded file.
 URL getURL()
          Retrieves the source URL of the download operation.
 boolean getWasCanceled()
          Indicates whether the operation was canceled.
 void run(IProgressMonitor monitor)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DownloadFileOperation

public DownloadFileOperation(URL source,
                             String filename,
                             boolean shouldDelete)
Creates a runnable to download a file from the web.

Parameters:
source - a URL representing the location of the file to be downloaded
filename - the name that the file should have once downloaded
shouldDelete - if this is true, the file will be set to delete on exit

DownloadFileOperation

public DownloadFileOperation(URL source,
                             File downloadDirectory,
                             String filename,
                             boolean shouldDelete)
Creates a runnable to download a file from the web.

Parameters:
source - a URL representing the location of the file to be downloaded
downloadDirectory - the directory to which the file should be downloaded
filename - the name that the file should have once downloaded
shouldDelete - if this is true, the file will be set to delete on exit

DownloadFileOperation

public DownloadFileOperation(URL source)

Creates a runnable to download a file from the web. The name that will be used for the local copy of the downloaded file is unspecified.

This is a convenience method, fully equivalent to

DownloadFileOperation(source, null, true);

Parameters:
source - a URL representing the location of the file to be downloaded
Method Detail

getURL

public URL getURL()
Retrieves the source URL of the download operation.

Returns:
the source URL as given to the constructor

getWasCanceled

public boolean getWasCanceled()
Indicates whether the operation was canceled.

Returns:
true if this operation was canceled by the progress monitor, false otherwise

getExceptions

public List getExceptions()
Returns a List containing any and all exceptions generated by this operation. If this list is empty, it can be assumed that no exceptions occurred during the operation.

Returns:
a List of all exceptions

getFile

public File getFile()
Return a handle to the downloaded file. If the download was unsuccessful, or was canceled, this value will be null.

Returns:
a handle to the downloaded file

run

public void run(IProgressMonitor monitor)
         throws InvocationTargetException,
                InterruptedException
Throws:
InvocationTargetException
InterruptedException


Copyright © 2004-2005 BBN Technologies. All Rights Reserved.