Changeset 30436 in osm for applications/editors/josm/plugins
- Timestamp:
- 2014-05-09T05:21:14+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java
r30203 r30436 549 549 550 550 if (tracks) { 551 final GpxWriter gpxWriter = new GpxWriter(printWriter); 552 GpxFilter gpxFilter = new GpxFilter(); 553 gpxFilter.initBboxFilter(bbox); 554 List<GpxLayer> gpxLayers = Main.map.mapView.getLayersOfType(GpxLayer.class); 555 for (GpxLayer gpxLayer : gpxLayers) { 556 gpxFilter.addGpxData(gpxLayer.data); 557 } 558 gpxWriter.write(gpxFilter.getGpxData()); 559 Utils.close(gpxWriter); 551 try (GpxWriter gpxWriter = new GpxWriter(printWriter)) { 552 GpxFilter gpxFilter = new GpxFilter(); 553 gpxFilter.initBboxFilter(bbox); 554 List<GpxLayer> gpxLayers = Main.map.mapView.getLayersOfType(GpxLayer.class); 555 for (GpxLayer gpxLayer : gpxLayers) { 556 gpxFilter.addGpxData(gpxLayer.data); 557 } 558 gpxWriter.write(gpxFilter.getGpxData()); 559 } catch (IOException e) { 560 Main.warn(e); 561 } 560 562 } 561 563 Utils.close(osmWriter); -
applications/editors/josm/plugins/mirrored_download/src/mirrored_download/UrlSelectionDialog.java
r30354 r30436 26 26 import org.openstreetmap.josm.Main; 27 27 import org.openstreetmap.josm.io.MirroredInputStream; 28 import org.openstreetmap.josm.tools.Utils;29 28 30 29 public class UrlSelectionDialog … … 106 105 String src = Main.pref.get("plugin.mirrored_download.url-src", "https://josm.openstreetmap.de/mirrored_download_info"); 107 106 Collection<String> urls = new ArrayList<String>(); 108 InputStream in = null;109 try {110 in= newMirroredInputStream(src, 24*60*60);111 BufferedReader reader = new BufferedReader(new InputStreamReader(in));107 try ( 108 InputStream in = new MirroredInputStream(src, 24*60*60); 109 BufferedReader reader = new BufferedReader(new InputStreamReader(in)) 110 ) { 112 111 String line = null; 113 112 while ((line = reader.readLine()) != null) { … … 117 116 } 118 117 } 119 Utils.close(reader);120 118 } catch (IOException e) { 121 e.printStackTrace(); 122 } finally { 123 Utils.close(in); 119 Main.error(e); 124 120 } 125 121 for (String url : Main.pref.getCollection("plugin.mirrored_download.custom-urls")) { … … 136 132 cbSelectUrl.getSelectedItem().toString()); 137 133 } 138 139 134 } 140 135 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/SevenZipReader.java
r30340 r30436 35 35 public SevenZipReader(InputStream in, AbstractDataSetHandler handler, boolean promptUser) throws IOException { 36 36 super(handler, handler != null ? handler.getArchiveHandler() : null, promptUser); 37 OutputStream out = null; 38 try { 39 // Write entire 7z file as a temp file on disk as we need random access later, and "in" can be a network stream 40 File tmpFile = File.createTempFile("7z_", ".7z", OdUtils.createTempDir()); 41 out = new FileOutputStream(tmpFile); 37 // Write entire 7z file as a temp file on disk as we need random access later, and "in" can be a network stream 38 File tmpFile = File.createTempFile("7z_", ".7z", OdUtils.createTempDir()); 39 try (OutputStream out = new FileOutputStream(tmpFile)) { 42 40 Utils.copyStream(in, out); 43 Utils.close(out); 44 out = null; 45 IInStream random = new MyRandomAccessFile(tmpFile.getPath(), "r"); 46 if (archive.Open(random) != 0) { 47 String message = "Unable to open 7z archive: "+tmpFile.getPath(); 48 Main.warn(message); 49 random.close(); 50 if (!tmpFile.delete()) { 51 tmpFile.deleteOnExit(); 52 } 53 throw new IOException(message); 41 } 42 IInStream random = new MyRandomAccessFile(tmpFile.getPath(), "r"); 43 if (archive.Open(random) != 0) { 44 String message = "Unable to open 7z archive: "+tmpFile.getPath(); 45 Main.warn(message); 46 random.close(); 47 if (!tmpFile.delete()) { 48 tmpFile.deleteOnExit(); 54 49 } 55 } finally { 56 Utils.close(out); 50 throw new IOException(message); 57 51 } 58 52 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ModuleDownloadTask.java
r30340 r30436 22 22 import org.openstreetmap.josm.plugins.opendata.OdPlugin; 23 23 import org.openstreetmap.josm.tools.CheckParameterUtil; 24 import org.openstreetmap.josm.tools.Utils;25 24 import org.xml.sax.SAXException; 26 25 … … 92 91 93 92 protected void download(ModuleInformation pi, File file) throws ModuleDownloadException{ 94 OutputStream out = null;95 InputStream in = null;96 93 try { 97 94 if (pi.downloadlink == null) { … … 108 105 downloadConnection.connect(); 109 106 } 110 in = downloadConnection.getInputStream(); 111 out = new FileOutputStream(file); 112 byte[] buffer = new byte[8192]; 113 for (int read = in.read(buffer); read != -1; read = in.read(buffer)) { 114 out.write(buffer, 0, read); 107 try ( 108 InputStream in = downloadConnection.getInputStream(); 109 OutputStream out = new FileOutputStream(file) 110 ) { 111 byte[] buffer = new byte[8192]; 112 for (int read = in.read(buffer); read != -1; read = in.read(buffer)) { 113 out.write(buffer, 0, read); 114 } 115 115 } 116 out.close();117 in.close();118 116 } catch(MalformedURLException e) { 119 117 String msg = tr("Warning: Cannot download module ''{0}''. Its download link ''{1}'' is not a valid URL. Skipping download.", pi.name, pi.downloadlink); … … 125 123 throw new ModuleDownloadException(e); 126 124 } finally { 127 Utils.close(in);128 125 synchronized(this) { 129 126 downloadConnection = null; 130 127 } 131 Utils.close(out);132 128 } 133 129 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ReadLocalModuleInformationTask.java
r30340 r30436 174 174 175 175 protected void processLocalModuleInformationFile(File file) throws ModuleListParseException{ 176 FileInputStream fin = null; 177 try { 178 fin = new FileInputStream(file); 176 try (FileInputStream fin = new FileInputStream(file)) { 179 177 List<ModuleInformation> pis = new ModuleListParser().parse(fin); 180 178 for (ModuleInformation pi : pis) { … … 187 185 } catch(IOException e) { 188 186 throw new ModuleListParseException(e); 189 } finally {190 Utils.close(fin);191 187 } 192 188 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ReadRemoteModuleInformationTask.java
r30340 r30436 33 33 import org.openstreetmap.josm.plugins.opendata.core.OdConstants; 34 34 import org.openstreetmap.josm.tools.ImageProvider; 35 import org.openstreetmap.josm.tools.Utils;36 35 import org.xml.sax.SAXException; 37 36 … … 142 141 */ 143 142 protected String downloadModuleList(String site, ProgressMonitor monitor) { 144 BufferedReader in = null;145 143 StringBuilder sb = new StringBuilder(); 146 144 try { … … 159 157 connection.setRequestProperty("Accept-Charset", "utf-8"); 160 158 } 161 in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); 162 String line; 163 while((line = in.readLine()) != null) { 164 sb.append(line).append("\n"); 165 } 166 return sb.toString(); 159 try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"))) { 160 String line; 161 while((line = in.readLine()) != null) { 162 sb.append(line).append("\n"); 163 } 164 return sb.toString(); 165 } 167 166 } catch(MalformedURLException e) { 168 167 if (canceled) return null; … … 180 179 connection = null; 181 180 } 182 Utils.close(in);183 181 monitor.finishTask(); 184 182 } … … 192 190 */ 193 191 protected void downloadModuleIcons(String site, File destFile, ProgressMonitor monitor) { 194 InputStream in = null;195 OutputStream out = null;196 192 try { 197 193 site = site.replaceAll("%<(.*)>", ""); … … 207 203 connection.setRequestProperty("Host", url.getHost()); 208 204 } 209 in = connection.getInputStream(); 210 out = new FileOutputStream(destFile); 211 byte[] buffer = new byte[8192]; 212 for (int read = in.read(buffer); read != -1; read = in.read(buffer)) { 213 out.write(buffer, 0, read); 214 } 215 out.close(); 216 in.close(); 205 try ( 206 InputStream in = connection.getInputStream(); 207 OutputStream out = new FileOutputStream(destFile) 208 ) { 209 byte[] buffer = new byte[8192]; 210 for (int read = in.read(buffer); read != -1; read = in.read(buffer)) { 211 out.write(buffer, 0, read); 212 } 213 } 217 214 } catch(MalformedURLException e) { 218 215 if (canceled) return; … … 230 227 connection = null; 231 228 } 232 Utils.close(in);233 229 monitor.finishTask(); 234 230 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/util/HttpUtils.java
r29736 r30436 42 42 int length = -1; 43 43 byte[] b = new byte[1024]; 44 InputStream in = Utils.openURL(new URL(url)); 45 while( (length = in.read(b)) > 0 ) { 46 bos.write(b, 0, length); 44 try (InputStream in = Utils.openURL(new URL(url))) { 45 while( (length = in.read(b)) > 0 ) { 46 bos.write(b, 0, length); 47 } 47 48 } 48 Utils.close(in);49 49 50 50 return new String(bos.toByteArray(), charset); … … 66 66 67 67 //send the post 68 OutputStream os = con.getOutputStream(); 69 os.write(content.getBytes("UTF-8")); 70 os.flush(); 68 try (OutputStream os = con.getOutputStream()) { 69 os.write(content.getBytes("UTF-8")); 70 os.flush(); 71 } 71 72 72 73 // read the response … … 74 75 int length = -1; 75 76 byte[] b = new byte[1024]; 76 InputStream in = con.getInputStream(); 77 while( (length = in.read(b)) > 0 ) { 78 bos.write(b, 0, length); 77 try (InputStream in = con.getInputStream()) { 78 while( (length = in.read(b)) > 0 ) { 79 bos.write(b, 0, length); 80 } 79 81 } 80 Utils.close(in);81 Utils.close(os);82 82 83 83 return new String(bos.toByteArray(), responseCharset); -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerAbstract.java
r29531 r30436 56 56 import org.openstreetmap.josm.plugins.piclayer.actions.SavePictureCalibrationAction; 57 57 import org.openstreetmap.josm.plugins.piclayer.transform.PictureTransform; 58 import org.openstreetmap.josm.tools.Utils;59 58 60 59 /** … … 457 456 458 457 public void loadWorldfile(InputStream is) throws IOException { 459 BufferedReader br = null;460 try {458 459 try ( 461 460 Reader reader = new InputStreamReader(is); 462 br = new BufferedReader(reader); 461 BufferedReader br = new BufferedReader(reader) 462 ) { 463 463 double e[] = new double[6]; 464 464 for (int i=0; i<6; ++i) { … … 488 488 initialImageScale = 1; 489 489 Main.map.mapView.repaint(); 490 } finally {491 Utils.close(br);492 490 } 493 491 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/layer/PicLayerFromFile.java
r27120 r30436 23 23 import static org.openstreetmap.josm.tools.I18n.tr; 24 24 25 import org.openstreetmap.josm.Main;26 27 25 import java.awt.Image; 28 26 import java.io.File; … … 38 36 import javax.swing.JOptionPane; 39 37 40 import org.openstreetmap.josm. tools.Utils;38 import org.openstreetmap.josm.Main; 41 39 /** 42 40 * Layer displaying a picture loaded from a file. … … 96 94 if (imgEntry != null) { 97 95 imgNameInZip = imgEntry.getName(); 98 InputStream is = null; 99 try { 100 is = zipFile.getInputStream(imgEntry); 101 image = ImageIO.read(is); 102 return image; 103 } finally { 104 Utils.close(is); 96 try (InputStream is = zipFile.getInputStream(imgEntry)) { 97 return ImageIO.read(is); 105 98 } 106 99 } -
applications/editors/josm/plugins/reverter/src/reverter/OsmServerMultiObjectReader.java
r29548 r30436 12 12 import org.openstreetmap.josm.io.OsmServerReader; 13 13 import org.openstreetmap.josm.io.OsmTransferException; 14 import org.openstreetmap.josm.tools.Utils;15 14 import org.xml.sax.SAXException; 16 15 … … 30 29 sb.append(version); 31 30 progressMonitor.beginTask("", 1); 32 InputStream in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true)); 33 try { 31 try (InputStream in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true))) { 34 32 rdr.addData(in); 35 33 } catch (Exception e) { … … 37 35 } finally { 38 36 progressMonitor.finishTask(); 39 Utils.close(in);40 37 } 41 38 } -
applications/editors/josm/plugins/reverter/src/reverter/corehacks/OsmServerChangesetReader.java
r30319 r30436 70 70 return null; 71 71 monitor.indeterminateSubTask(tr("Downloading changesets ...")); 72 List<Changeset> changesets = OsmChangesetParser.parse(in, monitor.createSubTaskMonitor(1, true)); 73 return changesets; 72 return OsmChangesetParser.parse(in, monitor.createSubTaskMonitor(1, true)); 74 73 } catch(OsmTransferException e) { 75 74 throw e;
Note:
See TracChangeset
for help on using the changeset viewer.