public class FileDownloader extends IstiNotifyThread implements FileUtilsConst
DEFAULT_TERMINATE_WAIT_TIME, terminateFlag
PATH_SEPARATOR, PERLINE_DEFAULT, STREAM_TRANSFER_BUFFER_SIZE
HOURS_PER_DAY, MINUTES_PER_DAY, MINUTES_PER_HOUR, MS_PER_DAY, MS_PER_HOUR, MS_PER_MINUTE, MS_PER_SECOND, SECONDS_PER_DAY, SECONDS_PER_MINUTE
Constructor and Description |
---|
FileDownloader(java.util.List<java.net.URL> urlList,
java.io.File outputDir,
CallBackStringParam callBackObj,
IstiDialogInterface dialogObj,
ProgressIndicatorInterface progressBarObj,
boolean unzipDownloadedFileFlag)
Creates a file download thread.
|
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.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addOutputFileObj(java.io.File outputFile)
Add the output file.
|
protected void |
backupOutputFile(java.io.File outputFile)
Backup the output file.
|
protected java.lang.String |
checkConnection(java.net.URLConnection urlCon)
Checks the connection.
|
protected java.lang.String |
checkHttpURLConnection(java.net.HttpURLConnection htpUrlCon)
Checks the HTTP connection.
|
protected long |
checkLastModified(java.net.URLConnection urlCon,
java.io.File outputFile)
Checks the last modified time.
|
protected java.io.File |
createOutputFileObject(java.io.File outputDir,
java.net.URL fileUrl)
Create the output file object.
|
static java.util.List<java.net.URL> |
createUrlList(java.lang.String... fileNames)
Create an immutable URL list.
|
protected void |
doThreadFinished(java.lang.String errMsgStr)
Performs thread-finished operations.
|
protected java.io.File |
getBackupFile(java.io.File outputFile)
Gets the backup file for the specified output file.
|
IstiDialogInterface |
getDialogObj()
Get the dialog object.
|
java.lang.String |
getFileNameStr()
Get the file name string.
|
protected static java.lang.String |
getFileNameStr(java.util.List<java.net.URL> urlList)
Get the file name string.
|
protected java.io.File |
getOutputDir(java.net.URL url)
Get the output directory for the specified URL.
|
java.io.File |
getOutputFileObj()
Returns the file object for the last file downloaded (or attempted).
|
java.io.File |
getOutputFileObj(int index)
Returns the file object for the file downloaded (or attempted).
|
ProgressIndicatorInterface |
getProgressBarObj()
Get the progress bar object.
|
java.util.List<java.net.URL> |
getUrlList()
Get the immutable URL list.
|
protected void |
initProgressBar()
Initialize the progress bar.
|
boolean |
isCloseWhenDone()
Determines if dialog is closed when the download is done.
|
boolean |
isDownloadDone()
Returns the completion status of the download attempt.
|
boolean |
isOutputFirstDirFlag()
Determine if output is going to the first directory.
|
void |
requestDialogFocus()
Perfoms a 'requestFocus()' on the currently-displayed dialog (if any).
|
void |
run()
Runs the thread.
|
protected java.lang.String |
run(java.io.File outputDir,
java.net.URL fileUrl)
Download the specified file.
|
void |
setBackupFile(boolean b)
Determines if the output file should be backed up if it already exists.
|
void |
setCallBackObj(CallBackStringParam callBackObj)
Sets the call-back object to use used.
|
void |
setCheckConnection(boolean b)
Determines if the connection should be checked.
|
void |
setCheckLastModified(boolean b)
Determines if the last modified time should be checked.
|
void |
setCloseWhenDone(boolean b)
Sets if the dialog is closed when the download is done.
|
void |
setDeleteFileAfterUnzip(boolean b)
Determines if the file should be deleted after unzip.
|
protected void |
setDownloadDone(java.lang.String errMsgStr)
Sets the download done.
|
void |
setFileNameStr(java.lang.String fileNameStr)
Set the file name string.
|
void |
setOutputFirstDirFlag(boolean outputFirstDirFlag)
Set if output is going to the first directory.
|
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.
|
protected java.lang.Object |
unzipZipFile(java.io.File file,
java.io.File outputDir)
Unzip the file.
|
sleep
clearThreadWaitNotifyFlag, isTerminated, nextThreadNum, notifyThread, start, terminate, waitForNotify, waitForNotify, waitForTerminate, waitForTerminate, wasStarted
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, stop, stop, suspend, toString, yield
public FileDownloader(java.util.List<java.net.URL> urlList, java.io.File outputDir, CallBackStringParam callBackObj, IstiDialogInterface dialogObj, ProgressIndicatorInterface progressBarObj, boolean unzipDownloadedFileFlag) throws java.lang.Exception
urlList
- the immutable URL list.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.java.lang.Exception
- if the URL list is null or empty.public FileDownloader(java.lang.String fileNameStr, java.io.File outputDir, CallBackStringParam callBackObj, IstiDialogInterface dialogObj, ProgressIndicatorInterface progressBarObj) throws java.lang.Exception
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.java.lang.Exception
- if the file name string cannot be parsed.public FileDownloader(java.lang.String fileNameStr, java.io.File outputDir, CallBackStringParam callBackObj, IstiDialogInterface dialogObj, ProgressIndicatorInterface progressBarObj, boolean unzipDownloadedFileFlag) throws java.lang.Exception
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.java.lang.Exception
- if the file name string cannot be parsed.public static java.util.List<java.net.URL> createUrlList(java.lang.String... fileNames) throws java.lang.Exception
fileNames
- the file names optionally using the path-separator.java.lang.Exception
- if the file names cannot be parsed.java.lang.NullPointerException
- if the file names are null.FileUtilsConst.PATH_SEPARATOR
protected static final java.lang.String getFileNameStr(java.util.List<java.net.URL> urlList) throws java.lang.Exception
urlList
- the immutable URL list.java.lang.Exception
- if the URL list is null or empty.protected void addOutputFileObj(java.io.File outputFile)
outputFile
- the output file.protected void backupOutputFile(java.io.File outputFile)
outputFile
- the output file.protected java.lang.String checkConnection(java.net.URLConnection urlCon) throws java.io.IOException
urlCon
- the URL connection.java.io.IOException
- if an I/O error has occurred.protected java.lang.String checkHttpURLConnection(java.net.HttpURLConnection htpUrlCon) throws java.io.IOException
htpUrlCon
- the HTTP URL connection.java.io.IOException
- if an I/O error has occurred.protected long checkLastModified(java.net.URLConnection urlCon, java.io.File outputFile)
urlCon
- the URL connection.outputFile
- the output file.protected java.io.File createOutputFileObject(java.io.File outputDir, java.net.URL fileUrl)
outputDir
- the output directory.fileUrl
- the file URL.protected void doThreadFinished(java.lang.String errMsgStr)
errMsgStr
- error message to be entered into the call-back
object, or null for none.protected java.io.File getBackupFile(java.io.File outputFile)
outputFile
- the output file.public IstiDialogInterface getDialogObj()
public java.lang.String getFileNameStr()
protected java.io.File getOutputDir(java.net.URL url)
url
- the URL.public java.io.File getOutputFileObj()
public java.io.File getOutputFileObj(int index)
index
- the file index or -1 for the last.public ProgressIndicatorInterface getProgressBarObj()
public java.util.List<java.net.URL> getUrlList()
protected void initProgressBar()
public boolean isCloseWhenDone()
public boolean isDownloadDone()
public boolean isOutputFirstDirFlag()
public void requestDialogFocus()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
protected java.lang.String run(java.io.File outputDir, java.net.URL fileUrl)
outputDir
- the output directory.fileUrl
- the file URL.public void setBackupFile(boolean b)
b
- true if the output file should be backed up if it already exists.public void setCallBackObj(CallBackStringParam callBackObj)
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.public void setCheckConnection(boolean b)
b
- true if the connection should be checked.public void setCheckLastModified(boolean b)
b
- true if the last modified time should be checked.public void setCloseWhenDone(boolean b)
b
- true if dialog is closed when the download is done, false
otherwise.public void setDeleteFileAfterUnzip(boolean b)
b
- true if the file should be deleted after unzip.protected void setDownloadDone(java.lang.String errMsgStr)
errMsgStr
- error message to be entered into the call-back
object, or null for none.public void setFileNameStr(java.lang.String fileNameStr) throws java.lang.Exception
fileNameStr
- the file name string.java.lang.Exception
- if the file name string cannot be parsed.public void setOutputFirstDirFlag(boolean outputFirstDirFlag)
outputFirstDirFlag
- true if output is going to the first directory, false otherwise.public void terminate()
terminateThread
method instead.terminate
in class IstiNotifyThread
terminateThread
public void terminateThread(java.lang.String msgStr)
msgStr
- message string given to call-back object.protected void threadFinished(java.lang.String errMsgStr)
errMsgStr
- error message to be entered into the call-back
object, or null for none.protected void transferStream(java.io.InputStream inputStream, java.io.OutputStream outputStream) throws java.io.IOException
inputStream
- the input stream.outputStream
- the output stream.java.io.IOException
- if an I/O error occurs.protected java.lang.Object unzipZipFile(java.io.File file, java.io.File outputDir) throws java.io.IOException
file
- the ZIP file.outputDir
- the output directory.java.io.IOException
- if an I/O error has occurred.