Changeset 5874 in josm for trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java
- Timestamp:
- 2013-04-16T19:57:43+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java
r5587 r5874 23 23 import org.xml.sax.SAXException; 24 24 25 26 25 /** 27 26 * Asynchronous task for downloading and unpacking arbitrary file lists … … 38 37 * 39 38 * @param parent the parent component relative to which the {@link PleaseWaitDialog} is displayed 40 * @param title the title to display in the {@link PleaseWaitDialog} 41 * @throws IllegalArgumentException thrown if toUpdate is null 39 * @param address the URL to download 40 * @param file The destination file 41 * @param mkdir {@code true} if the destination directory must be created, {@code false} otherwise 42 * @param unpack {@code true} if zip archives must be unpacked recursively, {@code false} otherwise 43 * @throws IllegalArgumentException if {@code parent} is null 42 44 */ 43 45 public DownloadFileTask(Component parent, String address, File file, boolean mkdir, boolean unpack) { … … 47 49 this.mkdir = mkdir; 48 50 this.unpack = unpack; 49 50 51 } 51 52 … … 76 77 protected void finish() {} 77 78 79 /** 80 * Performs download. 81 * @throws DownloadException if the URL is invalid or if any I/O error occurs. 82 */ 78 83 public void download() throws DownloadException { 79 84 OutputStream out = null; … … 107 112 out.write(buffer, 0, read); 108 113 count+=read; 109 if (canceled) return;114 if (canceled) break; 110 115 p2 = 100 * count / size; 111 116 if (p2!=p1) { … … 114 119 } 115 120 } 116 out.close(); 117 System.out.println(tr("Download finished")); 118 if (unpack) { 119 System.out.println(tr("Unpacking {0} into {1}", file.getAbsolutePath(), file.getParent())); 120 unzipFileRecursively(file, file.getParent()); 121 file.delete(); 121 Utils.close(out); 122 if (!canceled) { 123 System.out.println(tr("Download finished")); 124 if (unpack) { 125 System.out.println(tr("Unpacking {0} into {1}", file.getAbsolutePath(), file.getParent())); 126 unzipFileRecursively(file, file.getParent()); 127 file.delete(); 128 } 122 129 } 123 130 } catch(MalformedURLException e) { … … 148 155 * Replies true if the task was canceled by the user 149 156 * 150 * @return 157 * @return {@code true} if the task was canceled by the user, {@code false} otherwise 151 158 */ 152 159 public boolean isCanceled() { … … 182 189 os.write(buffer, 0, read); 183 190 } 184 os.close(); 185 is.close(); 186 } 187 } 188 zf.close(); 191 Utils.close(os); 192 Utils.close(is); 193 } 194 } 189 195 } finally { 190 if (zf!=null) zf.close();196 Utils.close(zf); 191 197 } 192 198 }
Note:
See TracChangeset
for help on using the changeset viewer.