com.isti.util
Class FileDownloader

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.isti.util.IstiThread
          extended bycom.isti.util.IstiNotifyThread
              extended bycom.isti.util.FileDownloader
All Implemented Interfaces:
java.lang.Runnable

public class FileDownloader
extends IstiNotifyThread

Class FileDownloader downloads a file with optional dialogs.


Field Summary
(package private)  long maxProgressVal
           
 
Fields inherited from class com.isti.util.IstiThread
DEFAULT_TERMINATE_WAIT_TIME, terminateFlag
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
FileDownloader(java.lang.String fileNameStr, java.io.File outputDir, CallBackStringParam callBackObj, IstiDialogInterface dialogObj, ProgressIndicatorInterface progressBarObj)
          Creates a file download thread.
FileDownloader(java.lang.String fileNameStr, java.io.File outputDir, CallBackStringParam callBackObj, IstiDialogInterface dialogObj, ProgressIndicatorInterface progressBarObj, boolean unzipDownloadedFileFlag)
          Creates a file download thread.
 
Method Summary
protected  void closeStreams()
          Closes the streams.
protected  void doThreadFinished(java.lang.String errMsgStr)
          Performs thread-finished operations.
 java.io.File getOutputFileObj()
          Returns the file object for the last file downloaded (or attempted).
 boolean isDownloadDone()
          Returns the completion status of the download attempt.
 void requestDialogFocus()
          Perfoms a 'requestFocus()' on the currently-displayed dialog (if any).
 void run()
          Runs the thread.
 void setCallBackObj(CallBackStringParam callBackObj)
          Sets the call-back object to use used.
 void terminate()
          Deprecated. Should use the terminateThread method instead.
 void terminateThread(java.lang.String msgStr)
          Terminates this download thread.
protected  void threadFinished(java.lang.String errMsgStr)
          Performs thread-finished operations (if terminate flag not set).
protected  void transferStream(java.io.InputStream inputStream, java.io.OutputStream outputStream)
          Transfers data from the input stream to the output stream.
 
Methods inherited from class com.isti.util.IstiNotifyThread
sleep
 
Methods inherited from class com.isti.util.IstiThread
clearThreadWaitNotifyFlag, isTerminated, nextThreadNum, notifyThread, start, terminate, waitForNotify, waitForNotify, waitForTerminate, waitForTerminate, wasStarted
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

maxProgressVal

long maxProgressVal
Constructor Detail

FileDownloader

public FileDownloader(java.lang.String fileNameStr,
                      java.io.File outputDir,
                      CallBackStringParam callBackObj,
                      IstiDialogInterface dialogObj,
                      ProgressIndicatorInterface progressBarObj,
                      boolean unzipDownloadedFileFlag)
Creates a file download thread. It downloads the specified file to the output directory.

Parameters:
fileNameStr - the installer file name string.
outputDir - the output directory.
callBackObj - if not null then a call-back object whose method is called (after the download is complete) with a string parameter containing null if successful or an error message if an error occurred.
dialogObj - the dialog object or null for none.
progressBarObj - the progress bar object or null for none.
unzipDownloadedFileFlag - true to unzip file after download (if it is a ZIP file); false to not unzip file.

FileDownloader

public FileDownloader(java.lang.String fileNameStr,
                      java.io.File outputDir,
                      CallBackStringParam callBackObj,
                      IstiDialogInterface dialogObj,
                      ProgressIndicatorInterface progressBarObj)
Creates a file download thread. It downloads the specified file to the output directory and if the file is a ZIP file it unzips the file.

Parameters:
fileNameStr - the installer file name string.
outputDir - the output directory.
callBackObj - if not null then a call-back object whose method is called (after the download is complete) with a string parameter containing null if successful or an error message if an error occurred.
dialogObj - the dialog object or null for none.
progressBarObj - the progress bar object or null for none.
Method Detail

setCallBackObj

public void setCallBackObj(CallBackStringParam callBackObj)
Sets the call-back object to use used.

Parameters:
callBackObj - if not null then a call-back object whose method is called (after the download is complete) with a string parameter containing null if successful or an error message if an error occurred.

run

public void run()
Runs the thread.


closeStreams

protected void closeStreams()
Closes the streams.


transferStream

protected void transferStream(java.io.InputStream inputStream,
                              java.io.OutputStream outputStream)
                       throws java.io.IOException
Transfers data from the input stream to the output stream.

Parameters:
inputStream - the input stream.
outputStream - the output stream.
Throws:
java.io.IOException - if an I/O error occurs.

threadFinished

protected void threadFinished(java.lang.String errMsgStr)
Performs thread-finished operations (if terminate flag not set).

Parameters:
errMsgStr - error message to be entered into the call-back object, or null for none.

doThreadFinished

protected void doThreadFinished(java.lang.String errMsgStr)
Performs thread-finished operations.

Parameters:
errMsgStr - error message to be entered into the call-back object, or null for none.

terminate

public void terminate()
Deprecated. Should use the terminateThread method instead.

Terminates this thread if the thread is not terminated and alive.

Overrides:
terminate in class IstiNotifyThread
See Also:
terminateThread

terminateThread

public void terminateThread(java.lang.String msgStr)
Terminates this download thread.

Parameters:
msgStr - message string given to call-back object.

requestDialogFocus

public void requestDialogFocus()
Perfoms a 'requestFocus()' on the currently-displayed dialog (if any).


isDownloadDone

public boolean isDownloadDone()
Returns the completion status of the download attempt.

Returns:
true if the download attempt has finish; false if not.

getOutputFileObj

public java.io.File getOutputFileObj()
Returns the file object for the last file downloaded (or attempted).

Returns:
The file object for the last file downloaded, or null if none.