Changeset 7033 in josm for trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java
- Timestamp:
- 2014-05-01T02:34:43+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java
r6643 r7033 83 83 */ 84 84 public void download() throws DownloadException { 85 OutputStream out = null;86 InputStream in = null;87 85 try { 88 86 if (mkdir) { … … 105 103 progressMonitor.subTask(tr("Downloading File {0}: {1} bytes...", file.getName(),size)); 106 104 107 in = downloadConnection.getInputStream(); 108 out = new FileOutputStream(file); 109 byte[] buffer = new byte[32768]; 110 int count=0; 111 int p1=0, p2=0; 112 for (int read = in.read(buffer); read != -1; read = in.read(buffer)) { 113 out.write(buffer, 0, read); 114 count+=read; 115 if (canceled) break; 116 p2 = 100 * count / size; 117 if (p2!=p1) { 118 progressMonitor.setTicks(p2); 119 p1=p2; 105 try ( 106 InputStream in = downloadConnection.getInputStream(); 107 OutputStream out = new FileOutputStream(file) 108 ) { 109 byte[] buffer = new byte[32768]; 110 int count=0; 111 int p1=0, p2=0; 112 for (int read = in.read(buffer); read != -1; read = in.read(buffer)) { 113 out.write(buffer, 0, read); 114 count+=read; 115 if (canceled) break; 116 p2 = 100 * count / size; 117 if (p2!=p1) { 118 progressMonitor.setTicks(p2); 119 p1=p2; 120 } 120 121 } 121 122 } 122 Utils.close(out);123 123 if (!canceled) { 124 124 Main.info(tr("Download finished")); … … 139 139 } finally { 140 140 closeConnectionIfNeeded(); 141 Utils.close(out);142 141 } 143 142 } … … 170 169 */ 171 170 public static void unzipFileRecursively(File file, String dir) throws IOException { 172 OutputStream os = null; 173 InputStream is = null; 174 ZipFile zf = null; 175 try { 176 zf = new ZipFile(file); 177 Enumeration<?> es = zf.entries(); 178 ZipEntry ze; 171 try (ZipFile zf = new ZipFile(file)) { 172 Enumeration<? extends ZipEntry> es = zf.entries(); 179 173 while (es.hasMoreElements()) { 180 ze = (ZipEntry)es.nextElement();174 ZipEntry ze = es.nextElement(); 181 175 File newFile = new File(dir, ze.getName()); 182 176 if (ze.isDirectory()) { 183 177 newFile.mkdirs(); 184 } else { 185 is = zf.getInputStream(ze); 186 os = new BufferedOutputStream(new FileOutputStream(newFile)); 178 } else try ( 179 InputStream is = zf.getInputStream(ze); 180 OutputStream os = new BufferedOutputStream(new FileOutputStream(newFile)) 181 ) { 187 182 byte[] buffer = new byte[8192]; 188 183 int read; … … 190 185 os.write(buffer, 0, read); 191 186 } 192 Utils.close(os);193 Utils.close(is);194 187 } 195 188 } 196 } finally {197 Utils.close(zf);198 189 } 199 190 } 200 191 } 201
Note:
See TracChangeset
for help on using the changeset viewer.