Changeset 7037 in josm
- Timestamp:
- 2014-05-01T16:28:25+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java
r7033 r7037 301 301 } 302 302 } 303 Utils.close(reader);304 303 } catch (Exception e) { 305 304 Main.error(e); -
trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
r7033 r7037 304 304 if (pidFile.exists()) { 305 305 try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(pidFile), Utils.UTF_8))) { 306 try { 307 String jvmId = reader.readLine(); 308 if (jvmId != null) { 309 String pid = jvmId.split("@")[0]; 310 skipFile = jvmPerfDataFileExists(pid); 311 } 312 } catch (Throwable t) { 313 Main.error(t); 314 } finally { 315 Utils.close(reader); 306 String jvmId = reader.readLine(); 307 if (jvmId != null) { 308 String pid = jvmId.split("@")[0]; 309 skipFile = jvmPerfDataFileExists(pid); 316 310 } 317 311 } catch (Throwable t) { -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java
r7005 r7037 74 74 MirroredInputStream.cleanup(source); 75 75 } 76 MirroredInputStream stream = null;77 76 try { 78 77 ImageryReader reader = new ImageryReader(source); … … 80 79 defaultLayers.addAll(result); 81 80 } catch (IOException ex) { 82 Utils.close(stream);83 81 Main.error(ex, false); 84 82 continue; 85 83 } catch (SAXException ex) { 86 Utils.close(stream);87 84 Main.error(ex); 88 85 continue; -
trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFile.java
r7025 r7037 155 155 topLevelSubGrid = createSubGridTree(subGrid); 156 156 lastSubGrid = topLevelSubGrid[0]; 157 158 Utils.close(in);159 157 } 160 158 -
trunk/src/org/openstreetmap/josm/gui/help/HelpContentReader.java
r6987 r7037 45 45 throw new MissingHelpContentException(helpTopicUrl); 46 46 HttpURLConnection con = null; 47 BufferedReader in = null;48 47 try { 49 48 URL u = new URL(helpTopicUrl); 50 49 con = Utils.openHttpConnection(u); 51 50 con.connect(); 52 in = new BufferedReader(new InputStreamReader(con.getInputStream(), Utils.UTF_8)); 53 return prepareHelpContent(in, dotest, u); 51 try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), Utils.UTF_8))) { 52 return prepareHelpContent(in, dotest, u); 53 } 54 54 } catch(MalformedURLException e) { 55 55 throw new HelpContentReaderException(e); … … 64 64 } 65 65 throw ex; 66 } finally {67 Utils.close(in);68 66 } 69 67 } -
trunk/src/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClient.java
r7005 r7037 7 7 import java.io.DataOutputStream; 8 8 import java.io.IOException; 9 import java.io.InputStream; 9 10 import java.io.InputStreamReader; 10 11 import java.io.UnsupportedEncodingException; … … 197 198 198 199 protected String extractToken(HttpURLConnection connection) { 199 BufferedReader r = null; 200 try { 201 r = new BufferedReader(new InputStreamReader(connection.getInputStream(), Utils.UTF_8)); 200 try ( 201 InputStream is = connection.getInputStream(); 202 BufferedReader r = new BufferedReader(new InputStreamReader(is, Utils.UTF_8)) 203 ) { 202 204 String c; 203 205 Pattern p = Pattern.compile(".*authenticity_token.*value=\"([^\"]+)\".*"); … … 211 213 Main.error(e); 212 214 return null; 213 } finally {214 Utils.close(r);215 215 } 216 216 return null; … … 364 364 365 365 protected void authenticateOsmSession(SessionId sessionId, String userName, String password) throws OsmLoginFailedException { 366 DataOutputStream dout = null;367 366 try { 368 367 URL url = new URL(buildOsmLoginUrl()); … … 392 391 connection.connect(); 393 392 394 dout = new DataOutputStream(connection.getOutputStream());395 dout.writeBytes(request);396 dout.flush();397 Utils.close(dout);393 try (DataOutputStream dout = new DataOutputStream(connection.getOutputStream())) { 394 dout.writeBytes(request); 395 dout.flush(); 396 } 398 397 399 398 // after a successful login the OSM website sends a redirect to a follow up page. Everything … … 409 408 throw new OsmLoginFailedException(e); 410 409 } finally { 411 Utils.close(dout);412 410 synchronized(this) { 413 411 connection = null; … … 456 454 parameters.put("allow_read_prefs", "yes"); 457 455 } 458 if (privileges.isAllowModifyNotes()) {456 if (privileges.isAllowModifyNotes()) { 459 457 parameters.put("allow_write_notes", "yes"); 460 458 } … … 463 461 464 462 String request = buildPostRequest(parameters); 465 DataOutputStream dout = null;466 463 try { 467 464 URL url = new URL(oauthProviderParameters.getAuthoriseUrl()); … … 480 477 connection.connect(); 481 478 482 dout = new DataOutputStream(connection.getOutputStream()); 483 dout.writeBytes(request); 484 dout.flush(); 479 try (DataOutputStream dout = new DataOutputStream(connection.getOutputStream())) { 480 dout.writeBytes(request); 481 dout.flush(); 482 } 485 483 486 484 int retCode = connection.getResponseCode(); 487 485 if (retCode != HttpURLConnection.HTTP_OK) 488 486 throw new OsmOAuthAuthorizationException(tr("Failed to authorize OAuth request ''{0}''", requestToken.getKey())); 489 } catch(IOException e) { 490 throw new OsmOAuthAuthorizationException(e); 491 } finally { 492 Utils.close(dout); 487 } catch (IOException e) { 488 throw new OsmOAuthAuthorizationException(e); 489 } finally { 493 490 synchronized(this) { 494 491 connection = null; -
trunk/src/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTask.java
r6995 r7037 165 165 @Override 166 166 protected void realRun() throws SAXException, IOException, OsmTransferException { 167 BufferedReader bin = null;168 167 try { 169 168 try { … … 195 194 } 196 195 StringBuilder changesets = new StringBuilder(); 197 bin = new BufferedReader(new InputStreamReader(connection.getInputStream(), Utils.UTF_8)); 198 String line; 199 while ((line = bin.readLine()) != null) { 200 changesets.append(line).append("\n"); 196 try (BufferedReader bin = new BufferedReader(new InputStreamReader(connection.getInputStream(), Utils.UTF_8))) { 197 String line; 198 while ((line = bin.readLine()) != null) { 199 changesets.append(line).append("\n"); 200 } 201 201 } 202 202 if (! (changesets.toString().contains("<osm") && changesets.toString().contains("</osm>"))) { … … 215 215 alertConnectionFailed(); 216 216 return; 217 } finally {218 Utils.close(bin);219 217 } 220 218 } -
trunk/src/org/openstreetmap/josm/io/GpxExporter.java
r7005 r7037 36 36 import org.openstreetmap.josm.tools.CheckParameterUtil; 37 37 import org.openstreetmap.josm.tools.GBC; 38 import org.openstreetmap.josm.tools.Utils;39 38 40 39 public class GpxExporter extends FileExporter implements GpxConstants { … … 176 175 } 177 176 178 OutputStream fo = null; 179 try { 180 fo = Compression.getCompressedFileOutputStream(file); 177 178 try (OutputStream fo = Compression.getCompressedFileOutputStream(file)) { 181 179 new GpxWriter(fo).write(gpxData); 182 180 fo.flush(); … … 185 183 JOptionPane.showMessageDialog(Main.parent, tr("Error while exporting {0}:\n{1}", fn, x.getMessage()), 186 184 tr("Error"), JOptionPane.ERROR_MESSAGE); 187 } finally {188 Utils.close(fo);189 185 } 190 186 } -
trunk/src/org/openstreetmap/josm/io/NmeaReader.java
r7012 r7037 174 174 Collection<Collection<WayPoint>> currentTrack = new ArrayList<>(); 175 175 176 BufferedReader rd = null; 177 try { 178 rd = new BufferedReader(new InputStreamReader(source, Utils.UTF_8)); 179 176 try (BufferedReader rd = new BufferedReader(new InputStreamReader(source, Utils.UTF_8))) { 180 177 StringBuilder sb = new StringBuilder(1024); 181 178 int loopstart_char = rd.read(); … … 209 206 } catch (Exception e) { 210 207 Main.warn(e); 211 } finally { 212 Utils.close(rd); 213 } 214 } 208 } 209 } 210 215 211 private static class NMEAParserState { 216 212 protected Collection<WayPoint> waypoints = new ArrayList<>(); -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r7033 r7037 629 629 activeConnection.setDoOutput(true); 630 630 activeConnection.setRequestProperty("Content-type", "text/xml"); 631 OutputStream out = activeConnection.getOutputStream();632 633 // It seems that certain bits of the Ruby API are very unhappy upon634 // receipt of a PUT/POST message without a Content-length header,635 // even if the request has no payload.636 // Since Java will not generate a Content-length header unless637 // we use the output stream, we create an output stream for PUT/POST638 // even if there is no payload.639 if (requestBody != null) {640 try (BufferedWriter bwr = new BufferedWriter(new OutputStreamWriter(out, Utils.UTF_8))) {641 bwr.write(requestBody);642 bwr.flush();631 try (OutputStream out = activeConnection.getOutputStream()) { 632 // It seems that certain bits of the Ruby API are very unhappy upon 633 // receipt of a PUT/POST message without a Content-length header, 634 // even if the request has no payload. 635 // Since Java will not generate a Content-length header unless 636 // we use the output stream, we create an output stream for PUT/POST 637 // even if there is no payload. 638 if (requestBody != null) { 639 try (BufferedWriter bwr = new BufferedWriter(new OutputStreamWriter(out, Utils.UTF_8))) { 640 bwr.write(requestBody); 641 bwr.flush(); 642 } 643 643 } 644 644 } 645 Utils.close(out);646 645 } 647 646 -
trunk/src/org/openstreetmap/josm/io/OsmImporter.java
r6798 r7037 62 62 @Override 63 63 public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 64 InputStream in = null; 65 try { 66 in = Compression.getUncompressedFileInputStream(file); 64 try (InputStream in = Compression.getUncompressedFileInputStream(file)) { 67 65 importData(in, file, progressMonitor); 68 66 } catch (FileNotFoundException e) { 69 67 Main.error(e); 70 68 throw new IOException(tr("File ''{0}'' does not exist.", file.getName()), e); 71 } finally {72 Utils.close(in);73 69 } 74 70 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControlHttpsServer.java
r7034 r7037 29 29 30 30 import org.openstreetmap.josm.Main; 31 import org.openstreetmap.josm.tools.Utils;32 31 33 32 /** … … 60 59 Main.error(tr("Unable to find JOSM keystore at {0}. Remote control will not be available on HTTPS.", KEYSTORE_PATH)); 61 60 } else { 62 try { 63 ks.load(in, password); 64 } finally { 65 Utils.close(in); 66 } 61 ks.load(in, password); 67 62 68 63 if (Main.isDebugEnabled()) { -
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r7033 r7037 153 153 */ 154 154 protected String downloadPluginList(String site, final ProgressMonitor monitor) { 155 BufferedReader in = null;156 157 155 /* replace %<x> with empty string or x=plugins (separated with comma) */ 158 156 String pl = Utils.join(",", Main.pref.getCollection("plugins")); … … 174 172 connection.setRequestProperty("Accept-Charset", "utf-8"); 175 173 } 176 in = new BufferedReader(new InputStreamReader(connection.getInputStream(), Utils.UTF_8)); 177 StringBuilder sb = new StringBuilder(); 178 String line; 179 while ((line = in.readLine()) != null) { 180 sb.append(line).append("\n"); 181 } 182 return sb.toString(); 174 try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), Utils.UTF_8))) { 175 StringBuilder sb = new StringBuilder(); 176 String line; 177 while ((line = in.readLine()) != null) { 178 sb.append(line).append("\n"); 179 } 180 return sb.toString(); 181 } 183 182 } catch (MalformedURLException e) { 184 183 if (canceled) return null; … … 197 196 connection = null; 198 197 } 199 Utils.close(in);200 198 monitor.finishTask(); 201 199 } … … 206 204 try (InputStream errStream = connection.getErrorStream()) { 207 205 if (errStream != null) { 208 BufferedReader err = null; 209 try { 206 try (BufferedReader err = new BufferedReader(new InputStreamReader(errStream, Utils.UTF_8))) { 210 207 String line; 211 err = new BufferedReader(new InputStreamReader(errStream, Utils.UTF_8));212 208 while ((line = err.readLine()) != null) { 213 209 sb.append(line).append("\n"); … … 216 212 Main.error(e); 217 213 Main.error(ex); 218 } finally {219 Utils.close(err);220 214 } 221 215 } -
trunk/src/org/openstreetmap/josm/tools/AudioUtil.java
r7033 r7037 38 38 * audioFormat.getFrameSize() /* bytes per frame */; 39 39 double naturalLength = filesize / bytesPerSecond; 40 Utils.close(audioInputStream);41 40 double calibration = Main.pref.getDouble("audio.calibration", 1.0 /* default, ratio */); 42 41 return naturalLength / calibration; -
trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r6925 r7037 211 211 */ 212 212 public static URL getBugReportUrl(String debugText) { 213 try {213 try ( 214 214 ByteArrayOutputStream out = new ByteArrayOutputStream(); 215 GZIPOutputStream gzip = new GZIPOutputStream(out); 215 GZIPOutputStream gzip = new GZIPOutputStream(out) 216 ) { 216 217 gzip.write(debugText.getBytes(Utils.UTF_8)); 217 Utils.close(gzip);218 218 219 219 return new URL(Main.getJOSMWebsite()+"/josmticket?" + -
trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java
r7033 r7037 200 200 // Try lsb_release (only available on LSB-compliant Linux systems, see https://www.linuxbase.org/lsb-cert/productdir.php?by_prod ) 201 201 Process p = Runtime.getRuntime().exec("lsb_release -ds"); 202 BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream(), Utils.UTF_8));203 String line = Utils.strip(input.readLine());204 Utils.close(input);205 if (line != null && !line.isEmpty()) {206 line = line.replaceAll("\"+","");207 line = line.replaceAll("NAME=",""); // strange code for some Gentoo's208 if(line.startsWith("Linux ")) // e.g. Linux Mint209 return line;210 else if(!line.isEmpty())211 return "Linux " + line;202 try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream(), Utils.UTF_8))) { 203 String line = Utils.strip(input.readLine()); 204 if (line != null && !line.isEmpty()) { 205 line = line.replaceAll("\"+",""); 206 line = line.replaceAll("NAME=",""); // strange code for some Gentoo's 207 if(line.startsWith("Linux ")) // e.g. Linux Mint 208 return line; 209 else if(!line.isEmpty()) 210 return "Linux " + line; 211 } 212 212 } 213 213 } catch (IOException e) { -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r7019 r7037 801 801 } 802 802 Process p = new ProcessBuilder(command).start(); 803 BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream(), UTF_8));804 StringBuilder all = null;805 String line;806 while ((line = input.readLine()) != null) {807 if (all == null) {808 all = new StringBuilder(line);809 } else {810 all.append("\n");811 all.append(line);812 }813 }814 Utils.close(input);815 return all != null ? all.toString() : null;803 try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream(), UTF_8))) { 804 StringBuilder all = null; 805 String line; 806 while ((line = input.readLine()) != null) { 807 if (all == null) { 808 all = new StringBuilder(line); 809 } else { 810 all.append("\n"); 811 all.append(line); 812 } 813 } 814 return all != null ? all.toString() : null; 815 } 816 816 } 817 817
Note:
See TracChangeset
for help on using the changeset viewer.