Changeset 7033 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2014-05-01T02:34:43+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/AudioUtil.java
r7029 r7033 31 31 */ 32 32 public static double getCalibratedDuration(File wavFile) { 33 try { 34 AudioInputStream audioInputStream = AudioSystem.getAudioInputStream( 35 new URL("file:".concat(wavFile.getAbsolutePath()))); 33 try (AudioInputStream audioInputStream = AudioSystem.getAudioInputStream( 34 new URL("file:".concat(wavFile.getAbsolutePath())))) { 36 35 AudioFormat audioFormat = audioInputStream.getFormat(); 37 36 long filesize = wavFile.length(); -
trunk/src/org/openstreetmap/josm/tools/I18n.java
r7012 r7033 397 397 if ("en".equals(loadedCode)) 398 398 return; 399 FileInputStream fis = null;400 JarInputStream jar = null;401 FileInputStream fisTrans = null;402 JarInputStream jarTrans = null;403 399 String enfile = "data/en.lang"; 404 400 String langfile = "data/"+loadedCode+".lang"; 405 try 406 { 401 try ( 402 FileInputStream fis = new FileInputStream(source); 403 JarInputStream jar = new JarInputStream(fis) 404 ) { 407 405 ZipEntry e; 408 fis = new FileInputStream(source);409 jar = new JarInputStream(fis);410 406 boolean found = false; 411 while(!found && (e = jar.getNextEntry()) != null) 412 { 407 while (!found && (e = jar.getNextEntry()) != null) { 413 408 String name = e.getName(); 414 409 if(name.equals(enfile)) 415 410 found = true; 416 411 } 417 if(found) 418 { 419 fisTrans = new FileInputStream(source); 420 jarTrans = new JarInputStream(fisTrans); 421 found = false; 422 while(!found && (e = jarTrans.getNextEntry()) != null) 423 { 424 String name = e.getName(); 425 if(name.equals(langfile)) 426 found = true; 412 if (found) { 413 try ( 414 FileInputStream fisTrans = new FileInputStream(source); 415 JarInputStream jarTrans = new JarInputStream(fisTrans) 416 ) { 417 found = false; 418 while(!found && (e = jarTrans.getNextEntry()) != null) { 419 String name = e.getName(); 420 if (name.equals(langfile)) 421 found = true; 422 } 423 if (found) 424 load(jar, jarTrans, true); 427 425 } 428 if(found) 429 load(jar, jarTrans, true); 430 } 431 } catch(IOException e) { 426 } 427 } catch (IOException e) { 432 428 // Ignore 433 } finally {434 Utils.close(jar);435 Utils.close(fis);436 Utils.close(jarTrans);437 Utils.close(fisTrans);438 429 } 439 430 } … … 460 451 return false; 461 452 } 462 InputStream enStream = null; 463 InputStream trStream = null; 464 try { 465 enStream = en.openStream(); 466 trStream = tr.openStream(); 453 try ( 454 InputStream enStream = en.openStream(); 455 InputStream trStream = tr.openStream() 456 ) { 467 457 if (load(enStream, trStream, false)) { 468 458 pluralMode = languages.get(l); … … 470 460 return true; 471 461 } 472 } catch(IOException e) { 462 } catch (IOException e) { 473 463 // Ignore exception 474 } finally {475 Utils.close(trStream);476 Utils.close(enStream);477 464 } 478 465 return false; -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r7025 r7033 504 504 505 505 private static ImageResource getIfAvailableHttp(String url, ImageType type) { 506 MirroredInputStream is = null; 507 try { 508 is = new MirroredInputStream(url, 509 new File(Main.pref.getCacheDirectory(), "images").getPath()); 506 try (MirroredInputStream is = new MirroredInputStream(url, 507 new File(Main.pref.getCacheDirectory(), "images").getPath())) { 510 508 switch (type) { 511 509 case SVG: … … 526 524 } catch (IOException e) { 527 525 return null; 528 } finally {529 Utils.close(is);530 526 } 531 527 } … … 603 599 604 600 private static ImageResource getIfAvailableZip(String fullName, File archive, String inArchiveDir, ImageType type) { 605 ZipFile zipFile = null; 606 try { 607 zipFile = new ZipFile(archive); 601 try (ZipFile zipFile = new ZipFile(archive)) { 608 602 if (inArchiveDir == null || ".".equals(inArchiveDir)) { 609 603 inArchiveDir = ""; … … 613 607 String entryName = inArchiveDir + fullName; 614 608 ZipEntry entry = zipFile.getEntry(entryName); 615 if(entry != null) 616 { 609 if (entry != null) { 617 610 int size = (int)entry.getSize(); 618 611 int offs = 0; 619 612 byte[] buf = new byte[size]; 620 InputStream is = null; 621 try { 622 is = zipFile.getInputStream(entry); 613 try (InputStream is = zipFile.getInputStream(entry)) { 623 614 switch (type) { 624 615 case SVG: … … 641 632 return img == null ? null : new ImageResource(img); 642 633 default: 643 throw new AssertionError(); 634 throw new AssertionError("Unknown ImageType: "+type); 644 635 } 645 } finally {646 Utils.close(is);647 636 } 648 637 } 649 638 } catch (Exception e) { 650 639 Main.warn(tr("Failed to handle zip file ''{0}''. Exception was: {1}", archive.getName(), e.toString())); 651 } finally {652 Utils.close(zipFile);653 640 } 654 641 return null; … … 785 772 }); 786 773 787 parser.parse(new InputSource(new MirroredInputStream(774 try (InputStream is = new MirroredInputStream( 788 775 base + fn, 789 new File(Main.pref.getPreferencesDir(), "images").toString() 790 ))); 776 new File(Main.pref.getPreferencesDir(), "images").toString()) 777 ) { 778 parser.parse(new InputSource(is)); 779 } 791 780 } catch (SAXReturnException r) { 792 781 return r.getResult(); -
trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java
r7012 r7033 283 283 File file = new File(path); 284 284 if (file.exists()) { 285 BufferedReader reader = null; 286 try { 287 reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), Utils.UTF_8)); 285 try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), Utils.UTF_8))) { 288 286 String id = null; 289 287 String release = null; … … 313 311 } catch (IOException e) { 314 312 // Ignore 315 } finally {316 Utils.close(reader);317 313 } 318 314 } -
trunk/src/org/openstreetmap/josm/tools/WikiReader.java
r6898 r7033 43 43 public String read(String url) throws IOException { 44 44 URL u = new URL(url); 45 BufferedReader in = Utils.openURLReader(u); 46 try { 45 try (BufferedReader in = Utils.openURLReader(u)) { 47 46 if (url.startsWith(baseurl) && !url.endsWith("?format=txt")) 48 47 return readFromTrac(in, u); 49 48 return readNormal(in); 50 } finally {51 Utils.close(in);52 49 } 53 50 } … … 84 81 85 82 private String readLang(URL url) throws IOException { 86 BufferedReader in; 87 try { 88 in = Utils.openURLReader(url); 83 try (BufferedReader in = Utils.openURLReader(url)) { 84 return readFromTrac(in, url); 89 85 } catch (IOException e) { 90 86 Main.addNetworkError(url, Utils.getRootCause(e)); 91 87 throw e; 92 }93 try {94 return readFromTrac(in, url);95 } finally {96 Utils.close(in);97 88 } 98 89 } -
trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java
r7012 r7033 5 5 6 6 import java.io.IOException; 7 import java.io.InputStream; 7 8 import java.io.Reader; 8 9 import java.lang.reflect.Field; … … 17 18 import java.util.Stack; 18 19 20 import javax.xml.XMLConstants; 19 21 import javax.xml.parsers.ParserConfigurationException; 20 22 import javax.xml.parsers.SAXParser; … … 278 280 279 281 public Iterable<Object> startWithValidation(final Reader in, String namespace, String schemaSource) throws SAXException { 280 try {281 SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");282 Schema schema = factory.newSchema(new StreamSource( new MirroredInputStream(schemaSource)));282 SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 283 try (InputStream mis = new MirroredInputStream(schemaSource)) { 284 Schema schema = factory.newSchema(new StreamSource(mis)); 283 285 ValidatorHandler validator = schema.newValidatorHandler(); 284 286 validator.setContentHandler(parser);
Note:
See TracChangeset
for help on using the changeset viewer.