- Timestamp:
- 2014-04-29T18:06:29+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r7005 r7030 658 658 try { 659 659 InputStream is = s.getSourceInputStream(); 660 try { 661 BufferedReader reader = new BufferedReader(new InputStreamReader(is, Utils.UTF_8)); 662 try { 663 String line; 664 while ((line = reader.readLine()) != null) { 665 txtSource.append(line + "\n"); 666 } 667 } finally { 668 reader.close(); 660 try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, Utils.UTF_8))) { 661 String line; 662 while ((line = reader.readLine()) != null) { 663 txtSource.append(line + "\n"); 669 664 } 670 665 } finally { -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r7005 r7030 235 235 return new XmlStyleSource(entry); 236 236 else { 237 InputStreamReader reader = new InputStreamReader(in, Utils.UTF_8); 238 try { 237 try (InputStreamReader reader = new InputStreamReader(in, Utils.UTF_8)) { 239 238 WHILE: while (true) { 240 239 int c = reader.read(); … … 253 252 } 254 253 } 255 } finally {256 reader.close();257 254 } 258 255 Main.warn("Could not detect style type. Using default (xml)."); -
trunk/src/org/openstreetmap/josm/io/GeoJSONWriter.java
r7005 r7030 60 60 Map<String, Object> config = new HashMap<>(1); 61 61 config.put(JsonGenerator.PRETTY_PRINTING, pretty); 62 JsonWriter writer = Json.createWriterFactory(config).createWriter(stringWriter); 63 JsonObjectBuilder object = Json.createObjectBuilder() 64 .add("type", "FeatureCollection") 65 .add("generator", "JOSM"); 66 appendLayerBounds(layer.data, object); 67 appendLayerFeatures(layer.data, object); 68 writer.writeObject(object.build()); 69 String result = stringWriter.toString(); 70 writer.close(); 71 return result; 62 try (JsonWriter writer = Json.createWriterFactory(config).createWriter(stringWriter)) { 63 JsonObjectBuilder object = Json.createObjectBuilder() 64 .add("type", "FeatureCollection") 65 .add("generator", "JOSM"); 66 appendLayerBounds(layer.data, object); 67 appendLayerFeatures(layer.data, object); 68 writer.writeObject(object.build()); 69 return stringWriter.toString(); 70 } 72 71 } 73 72 -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r7012 r7030 632 632 // even if there is no payload. 633 633 if (requestBody != null) { 634 BufferedWriter bwr = new BufferedWriter(new OutputStreamWriter(out, Utils.UTF_8)); 635 try { 634 try (BufferedWriter bwr = new BufferedWriter(new OutputStreamWriter(out, Utils.UTF_8))) { 636 635 bwr.write(requestBody); 637 636 bwr.flush(); 638 } finally {639 bwr.close();640 637 } 641 638 } … … 671 668 // Unauthorized, see #3887. 672 669 // 673 BufferedReader in = new BufferedReader(new InputStreamReader(i, Utils.UTF_8));674 670 String s; 675 try {671 try (BufferedReader in = new BufferedReader(new InputStreamReader(i, Utils.UTF_8))) { 676 672 while((s = in.readLine()) != null) { 677 673 responseBody.append(s); 678 674 responseBody.append("\n"); 679 675 } 680 } finally {681 in.close();682 676 } 683 677 } -
trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java
r7005 r7030 141 141 URLConnection openConnection = Utils.openHttpConnection(getCapabilitiesUrl); 142 142 InputStream inputStream = openConnection.getInputStream(); 143 BufferedReader br = new BufferedReader(UTFInputStreamReader.create(inputStream));144 String line;145 143 StringBuilder ba = new StringBuilder(); 146 try { 144 try (BufferedReader br = new BufferedReader(UTFInputStreamReader.create(inputStream))) { 145 String line; 147 146 while ((line = br.readLine()) != null) { 148 147 ba.append(line); 149 148 ba.append("\n"); 150 149 } 151 } finally {152 br.close();153 150 } 154 151 String incomingData = ba.toString(); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java
r7005 r7030 383 383 384 384 public static String getHandlerInfoAsJSON(String cmd) { 385 StringWriter w = new StringWriter(); 386 PrintWriter r = new PrintWriter(w); 387 RequestHandler handler = null; 388 try { 389 Class<?> c = handlers.get(cmd); 390 if (c==null) return null; 391 handler = handlers.get(cmd).newInstance(); 392 } catch (Exception ex) { 393 Main.error(ex); 385 try (StringWriter w = new StringWriter()) { 386 PrintWriter r = new PrintWriter(w); 387 RequestHandler handler = null; 388 try { 389 Class<?> c = handlers.get(cmd); 390 if (c==null) return null; 391 handler = handlers.get(cmd).newInstance(); 392 } catch (InstantiationException | IllegalAccessException ex) { 393 Main.error(ex); 394 return null; 395 } 396 397 printJsonInfo(cmd, r, handler); 398 return w.toString(); 399 } catch (IOException e) { 400 Main.error(e); 394 401 return null; 395 402 } 396 403 } 404 405 private static void printJsonInfo(String cmd, PrintWriter r, RequestHandler handler) { 397 406 r.printf("{ \"request\" : \"%s\"", cmd); 398 407 if (handler.getUsage() != null) { … … 438 447 } 439 448 r.append("]}"); 440 try {441 return w.toString();442 } finally {443 try {444 w.close();445 } catch (IOException ex) {446 Main.warn(ex);447 }448 }449 449 } 450 450
Note:
See TracChangeset
for help on using the changeset viewer.