Package org.openstreetmap.josm.gui.io
Class DownloadFileTask
- java.lang.Object
-
- org.openstreetmap.josm.gui.PleaseWaitRunnable
-
- org.openstreetmap.josm.gui.io.DownloadFileTask
-
- All Implemented Interfaces:
java.lang.Runnable,ProgressMonitor.CancelListener
public class DownloadFileTask extends PleaseWaitRunnable
Asynchronous task for downloading and unpacking arbitrary file lists Shows progress bar when downloading
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classDownloadFileTask.DownloadException
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringaddressprivate booleancanceledprivate HttpClientdownloadConnectionprivate java.io.Filefileprivate booleanmkdirprivate booleanunpack-
Fields inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
progressMonitor
-
-
Constructor Summary
Constructors Constructor Description DownloadFileTask(java.awt.Component parent, java.lang.String address, java.io.File file, boolean mkdir, boolean unpack)Creates the download task
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcancel()User pressed cancel button.private voidcloseConnectionIfNeeded()voiddownload()Performs download.protected voidfinish()Finish up the data work.booleanisCanceled()Replies true if the task was canceled by the userprotected voidrealRun()Called in the worker thread to do the actual work.static voidunzipFileRecursively(java.io.File file, java.lang.String dir)Recursive unzipping function TODO: May be placed somewhere else - Tools.Utils?-
Methods inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
afterFinish, canRunInBackground, getProgressMonitor, operationCanceled, run
-
-
-
-
Field Detail
-
address
private final java.lang.String address
-
file
private final java.io.File file
-
mkdir
private final boolean mkdir
-
unpack
private final boolean unpack
-
canceled
private boolean canceled
-
downloadConnection
private HttpClient downloadConnection
-
-
Constructor Detail
-
DownloadFileTask
public DownloadFileTask(java.awt.Component parent, java.lang.String address, java.io.File file, boolean mkdir, boolean unpack)
Creates the download task- Parameters:
parent- the parent component relative to which thePleaseWaitDialogis displayedaddress- the URL to downloadfile- The destination filemkdir-trueif the destination directory must be created,falseotherwiseunpack-trueif zip archives must be unpacked recursively,falseotherwise- Throws:
java.lang.IllegalArgumentException- ifparentis null
-
-
Method Detail
-
closeConnectionIfNeeded
private void closeConnectionIfNeeded()
-
cancel
protected void cancel()
Description copied from class:PleaseWaitRunnableUser pressed cancel button.- Specified by:
cancelin classPleaseWaitRunnable
-
finish
protected void finish()
Description copied from class:PleaseWaitRunnableFinish up the data work. Is guaranteed to be called if realRun is called. Finish is called in the gui thread just after the dialog disappeared.- Specified by:
finishin classPleaseWaitRunnable
-
download
public void download() throws DownloadFileTask.DownloadException
Performs download.- Throws:
DownloadFileTask.DownloadException- if the URL is invalid or if any I/O error occurs.
-
realRun
protected void realRun() throws org.xml.sax.SAXException, java.io.IOException
Description copied from class:PleaseWaitRunnableCalled in the worker thread to do the actual work. When any of the exception is thrown, a message box will be displayed and closeDialog is called. finish() is called in any case.- Specified by:
realRunin classPleaseWaitRunnable- Throws:
org.xml.sax.SAXException- if a SAX error occursjava.io.IOException- if an I/O error occurs
-
isCanceled
public boolean isCanceled()
Replies true if the task was canceled by the user- Returns:
trueif the task was canceled by the user,falseotherwise
-
unzipFileRecursively
public static void unzipFileRecursively(java.io.File file, java.lang.String dir) throws java.io.IOException
Recursive unzipping function TODO: May be placed somewhere else - Tools.Utils?- Parameters:
file- zip filedir- output directory- Throws:
java.io.IOException- if any I/O error occurs
-
-