Changeset 7033 in josm for trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
- Timestamp:
- 2014-05-01T02:34:43+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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();
Note:
See TracChangeset
for help on using the changeset viewer.
