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/data/validation
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r7005 r7033  
    171171            File file = new File(getValidatorDir() + "ignorederrors");
    172172            if (file.exists()) {
    173                 BufferedReader in = null;
    174                 try {
    175                     in = new BufferedReader(new InputStreamReader(new FileInputStream(file), Utils.UTF_8));
     173                try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), Utils.UTF_8))) {
    176174                    for (String line = in.readLine(); line != null; line = in.readLine()) {
    177175                        ignoredErrors.add(line);
     
    181179                } catch (final IOException e) {
    182180                    Main.error(e);
    183                 } finally {
    184                     Utils.close(in);
    185181                }
    186182            }
     
    197193
    198194    public static void saveIgnoredErrors() {
    199         PrintWriter out = null;
    200         try {
    201             out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(getValidatorDir() + "ignorederrors"), Utils.UTF_8), false);
     195        try (PrintWriter out = new PrintWriter(new OutputStreamWriter(
     196                new FileOutputStream(getValidatorDir() + "ignorederrors"), Utils.UTF_8), false)) {
    202197            for (String e : ignoredErrors) {
    203198                out.println(e);
     
    205200        } catch (IOException e) {
    206201            Main.error(e);
    207         } finally {
    208             Utils.close(out);
    209202        }
    210203    }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r7027 r7033  
    453453                    Main.info(tr("Adding {0} to tag checker", i));
    454454                }
    455                 MirroredInputStream s = new MirroredInputStream(i);
    456                 try {
     455                try (MirroredInputStream s = new MirroredInputStream(i)) {
    457456                    addMapCSS(new BufferedReader(UTFInputStreamReader.create(s)));
    458                 } finally {
    459                     Utils.close(s);
    460457                }
    461458            } catch (IOException ex) {
  • trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java

    r7005 r7033  
    55
    66import java.io.InputStreamReader;
     7import java.io.Reader;
    78import java.util.ArrayList;
    89import java.util.Arrays;
     
    5152        super.initialize();
    5253        if (ENGINE != null) {
    53             ENGINE.eval(new InputStreamReader(new MirroredInputStream("resource://data/validator/opening_hours.js"), Utils.UTF_8));
    54             // fake country/state to not get errors on holidays
    55             ENGINE.eval("var nominatimJSON = {address: {state: 'Bayern', country_code: 'de'}};");
    56             ENGINE.eval(
    57                     "var oh = function (value, mode) {" +
    58                     " try {" +
    59                     "    var r= new opening_hours(value, nominatimJSON, mode);" +
    60                     "    r.getErrors = function() {return [];};" +
    61                     "    return r;" +
    62                     "  } catch(err) {" +
    63                     "    return {" +
    64                     "      getWarnings: function() {return [];}," +
    65                     "      getErrors: function() {return [err.toString()]}" +
    66                     "    };" +
    67                     "  }" +
    68                     "};");
     54            try (Reader reader = new InputStreamReader(
     55                    new MirroredInputStream("resource://data/validator/opening_hours.js"), Utils.UTF_8)) {
     56                ENGINE.eval(reader);
     57                // fake country/state to not get errors on holidays
     58                ENGINE.eval("var nominatimJSON = {address: {state: 'Bayern', country_code: 'de'}};");
     59                ENGINE.eval(
     60                        "var oh = function (value, mode) {" +
     61                        " try {" +
     62                        "    var r= new opening_hours(value, nominatimJSON, mode);" +
     63                        "    r.getErrors = function() {return [];};" +
     64                        "    return r;" +
     65                        "  } catch(err) {" +
     66                        "    return {" +
     67                        "      getWarnings: function() {return [];}," +
     68                        "      getErrors: function() {return [err.toString()]}" +
     69                        "    };" +
     70                        "  }" +
     71                        "};");
     72            }
    6973        } else {
    7074            Main.warn("Unable to initialize OpeningHourTest because no JavaScript engine has been found");
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r7025 r7033  
    5454import org.openstreetmap.josm.tools.GBC;
    5555import org.openstreetmap.josm.tools.MultiMap;
    56 import org.openstreetmap.josm.tools.Utils;
    5756
    5857/**
     
    165164        String errorSources = "";
    166165        for (String source : Main.pref.getCollection(PREF_SOURCES, DEFAULT_SOURCES)) {
    167             BufferedReader reader = null;
    168             try {
     166            try (
    169167                MirroredInputStream s = new MirroredInputStream(source);
    170                 reader = new BufferedReader(UTFInputStreamReader.create(s));
    171 
     168                BufferedReader reader = new BufferedReader(UTFInputStreamReader.create(s));
     169            ) {
    172170                String okValue = null;
    173171                boolean tagcheckerfile = false;
     
    242240            } catch (IOException e) {
    243241                errorSources += source + "\n";
    244             } finally {
    245                 Utils.close(reader);
    246242            }
    247243        }
Note: See TracChangeset for help on using the changeset viewer.