ecologylab.io
Class ZipDownload

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.io.ZipDownload
All Implemented Interfaces:
DispatchTarget, Downloadable

public class ZipDownload
extends Debug
implements Downloadable, DispatchTarget

Class implementing DownloadLoadable to allow for the downloading and writing to disk of zip files. Additionally files can be extracted after downloaded.

Author:
Blake Dworaczyk

Constructor Summary
ZipDownload(ParsedURL zipSource, java.io.File zipTarget)
           
ZipDownload(ParsedURL zipSource, java.io.File zipTarget, StatusReporter status)
           
 
Method Summary
 void delivery(java.lang.Object o)
          Called, probably later asynchronously, when the requested service is complete.
static ZipDownload downloadAndPerhapsUncompress(ParsedURL sourceZip, java.io.File targetDir, StatusReporter status, boolean unCompress)
          Convenience function to allow downloading and uncompressing of a zip file from a source to a target location with minimal effort.
 void downloadAndWrite()
           
 void downloadAndWrite(boolean extractWhenComplete)
          Initiate the download and writing of the zip file.
 void downloadDone()
          Call to notify the object that its download is completed;
static void extractZipFile(java.io.File zipSource)
           
static void extractZipFile(java.io.File zipSource, java.io.File unzipPath)
          Extracts a zip file into the directory where it resides
static void extractZipFile(java.lang.String zipSourcePath)
          Extracts a zip file into the directory where it resides
static void extractZipFile(java.lang.String zipSourcePath, java.io.File unzipPath)
          Extracts a zip file into the directory where it resides
 java.io.BufferedInputStream getInputStream(java.io.File zipTarget)
           
 void handleIoError()
          Called in case an IO error happens.
 boolean handleTimeout()
          Called in case a timeout happens.
 boolean isDownloadDone()
          Called to inquire on the status of a download.
 boolean isRecycled()
          True if the Downloadable has been recycled, and thus should not be downloaded.
 void performDownload()
          ONLY called by DownloadProcessors to actually download the zip file! Not called by outsiders!
static void setDownloadProcessor(DownloadProcessor downloadProcessor)
           
static void stopDownloadProcessor()
           
 void waitForDownload()
           
 
Methods inherited from class ecologylab.generic.Debug
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ZipDownload

public ZipDownload(ParsedURL zipSource,
                   java.io.File zipTarget,
                   StatusReporter status)

ZipDownload

public ZipDownload(ParsedURL zipSource,
                   java.io.File zipTarget)
Method Detail

downloadAndWrite

public void downloadAndWrite(boolean extractWhenComplete)
Initiate the download and writing of the zip file. This is called by outsiders.


stopDownloadProcessor

public static void stopDownloadProcessor()

downloadAndWrite

public void downloadAndWrite()

performDownload

public void performDownload()
                     throws java.lang.Exception
ONLY called by DownloadProcessors to actually download the zip file! Not called by outsiders!

Specified by:
performDownload in interface Downloadable
Throws:
java.lang.Exception

getInputStream

public java.io.BufferedInputStream getInputStream(java.io.File zipTarget)
                                           throws java.lang.Exception
Throws:
java.lang.Exception

isDownloadDone

public boolean isDownloadDone()
Description copied from interface: Downloadable
Called to inquire on the status of a download.

Specified by:
isDownloadDone in interface Downloadable
Returns:
true if the download is complete.

handleTimeout

public boolean handleTimeout()
Description copied from interface: Downloadable
Called in case a timeout happens.

Specified by:
handleTimeout in interface Downloadable
Returns:
true, if the object is able to abort the download and release resources.

handleIoError

public void handleIoError()
Description copied from interface: Downloadable
Called in case an IO error happens.

Specified by:
handleIoError in interface Downloadable

delivery

public void delivery(java.lang.Object o)
Description copied from interface: DispatchTarget
Called, probably later asynchronously, when the requested service is complete.

Specified by:
delivery in interface DispatchTarget
Parameters:
o - -- enables an argument of any type to be passed back.

downloadAndPerhapsUncompress

public static ZipDownload downloadAndPerhapsUncompress(ParsedURL sourceZip,
                                                       java.io.File targetDir,
                                                       StatusReporter status,
                                                       boolean unCompress)
Convenience function to allow downloading and uncompressing of a zip file from a source to a target location with minimal effort.

Parameters:
sourceZip - The location of the zip file to download and uncompress.
targetDir - The location where the zip file should be uncompressed. This directory structure will be created if it doesn't exist.
status - The StatusReporter object that provides a source of state change visiblity; can be null.
unCompress - true if the file is a zip that needs to be uncompressed after download.
Returns:
TODO

extractZipFile

public static void extractZipFile(java.lang.String zipSourcePath)
                           throws java.io.IOException
Extracts a zip file into the directory where it resides

Parameters:
zipSourcePath - The path to the source zip file to extract.
Throws:
java.io.IOException

extractZipFile

public static void extractZipFile(java.io.File zipSource)
                           throws java.io.IOException
Throws:
java.io.IOException

extractZipFile

public static void extractZipFile(java.lang.String zipSourcePath,
                                  java.io.File unzipPath)
                           throws java.io.IOException
Extracts a zip file into the directory where it resides

Parameters:
zipSourcePath - The source zip file to extract
Throws:
java.io.IOException

extractZipFile

public static void extractZipFile(java.io.File zipSource,
                                  java.io.File unzipPath)
                           throws java.io.IOException
Extracts a zip file into the directory where it resides

Parameters:
zipSource - The source zip file to extract
Throws:
java.io.IOException

downloadDone

public void downloadDone()
Call to notify the object that its download is completed;

Specified by:
downloadDone in interface Downloadable

waitForDownload

public void waitForDownload()

setDownloadProcessor

public static void setDownloadProcessor(DownloadProcessor downloadProcessor)

isRecycled

public boolean isRecycled()
Description copied from interface: Downloadable
True if the Downloadable has been recycled, and thus should not be downloaded.

Specified by:
isRecycled in interface Downloadable
Returns: