Ignore:
Timestamp:
2014-05-01T02:34:43+02:00 (12 years ago)
Author:
Don-vip
Message:

see #8465 - global use of try-with-resources, according to

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r7025 r7033  
    504504
    505505    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())) {
    510508            switch (type) {
    511509            case SVG:
     
    526524        } catch (IOException e) {
    527525            return null;
    528         } finally {
    529             Utils.close(is);
    530526        }
    531527    }
     
    603599
    604600    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)) {
    608602            if (inArchiveDir == null || ".".equals(inArchiveDir)) {
    609603                inArchiveDir = "";
     
    613607            String entryName = inArchiveDir + fullName;
    614608            ZipEntry entry = zipFile.getEntry(entryName);
    615             if(entry != null)
    616             {
     609            if (entry != null) {
    617610                int size = (int)entry.getSize();
    618611                int offs = 0;
    619612                byte[] buf = new byte[size];
    620                 InputStream is = null;
    621                 try {
    622                     is = zipFile.getInputStream(entry);
     613                try (InputStream is = zipFile.getInputStream(entry)) {
    623614                    switch (type) {
    624615                    case SVG:
     
    641632                        return img == null ? null : new ImageResource(img);
    642633                    default:
    643                         throw new AssertionError();
     634                        throw new AssertionError("Unknown ImageType: "+type);
    644635                    }
    645                 } finally {
    646                     Utils.close(is);
    647636                }
    648637            }
    649638        } catch (Exception e) {
    650639            Main.warn(tr("Failed to handle zip file ''{0}''. Exception was: {1}", archive.getName(), e.toString()));
    651         } finally {
    652             Utils.close(zipFile);
    653640        }
    654641        return null;
     
    785772            });
    786773
    787             parser.parse(new InputSource(new MirroredInputStream(
     774            try (InputStream is = new MirroredInputStream(
    788775                    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            }
    791780        } catch (SAXReturnException r) {
    792781            return r.getResult();
Note: See TracChangeset for help on using the changeset viewer.