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 class
DownloadFileTask.DownloadException
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
address
private boolean
canceled
private HttpClient
downloadConnection
private java.io.File
file
private boolean
mkdir
private boolean
unpack
-
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 void
cancel()
User pressed cancel button.private void
closeConnectionIfNeeded()
void
download()
Performs download.protected void
finish()
Finish up the data work.boolean
isCanceled()
Replies true if the task was canceled by the userprotected void
realRun()
Called in the worker thread to do the actual work.static void
unzipFileRecursively(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 thePleaseWaitDialog
is displayedaddress
- the URL to downloadfile
- The destination filemkdir
-true
if the destination directory must be created,false
otherwiseunpack
-true
if zip archives must be unpacked recursively,false
otherwise- Throws:
java.lang.IllegalArgumentException
- ifparent
is null
-
-
Method Detail
-
closeConnectionIfNeeded
private void closeConnectionIfNeeded()
-
cancel
protected void cancel()
Description copied from class:PleaseWaitRunnable
User pressed cancel button.- Specified by:
cancel
in classPleaseWaitRunnable
-
finish
protected void finish()
Description copied from class:PleaseWaitRunnable
Finish 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:
finish
in 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:PleaseWaitRunnable
Called 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:
realRun
in 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:
true
if the task was canceled by the user,false
otherwise
-
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
-
-