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

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

Location:
trunk/src/org/openstreetmap/josm/gui/layer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r7024 r7033  
    326326            protected byte[] updateData() throws IOException {
    327327                URL u = getAttributionUrl();
    328                 UTFInputStreamReader in = UTFInputStreamReader.create(Utils.openURL(u));
    329                 String r = new Scanner(in).useDelimiter("\\A").next();
    330                 Utils.close(in);
    331                 Main.info("Successfully loaded Bing attribution data.");
    332                 return r.getBytes("utf-8");
     328                try (Scanner scanner = new Scanner(UTFInputStreamReader.create(Utils.openURL(u)))) {
     329                    String r = scanner.useDelimiter("\\A").next();
     330                    Main.info("Successfully loaded Bing attribution data.");
     331                    return r.getBytes("UTF-8");
     332                }
    333333            }
    334334        }
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r7025 r7033  
    2121import java.io.File;
    2222import java.io.FileInputStream;
     23import java.io.FileNotFoundException;
    2324import java.io.IOException;
    2425import java.io.InputStream;
     
    171172                }
    172173                GpxData data = null;
    173                 try {
    174                     InputStream iStream;
    175                     if (sel.getName().toLowerCase().endsWith(".gpx.gz")) {
    176                         iStream = new GZIPInputStream(new FileInputStream(sel));
    177                     } else {
    178                         iStream = new FileInputStream(sel);
    179                     }
     174                try (InputStream iStream = createInputStream(sel)) {
    180175                    GpxReader reader = new GpxReader(iStream);
    181176                    reader.parse(false);
     
    211206            } finally {
    212207                outerPanel.setCursor(Cursor.getDefaultCursor());
     208            }
     209        }
     210
     211        private InputStream createInputStream(File sel) throws IOException, FileNotFoundException {
     212            if (sel.getName().toLowerCase().endsWith(".gpx.gz")) {
     213                return new GZIPInputStream(new FileInputStream(sel));
     214            } else {
     215                return new FileInputStream(sel);
    213216            }
    214217        }
Note: See TracChangeset for help on using the changeset viewer.