Changeset 9829 in josm for trunk/src/org


Ignore:
Timestamp:
2016-02-19T02:34:18+01:00 (9 years ago)
Author:
Don-vip
Message:

fix warnings, add unit test

File:
1 edited

Legend:

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

    r9827 r9829  
    14181418     */
    14191419    public String toXML(Collection<Entry<String, Setting<?>>> settings, boolean nopass, boolean defaults) {
    1420         StringWriter sw = new StringWriter();
    1421         PrintWriter pw = new PrintWriter(sw);
    1422         PreferencesWriter prefWriter = new PreferencesWriter(pw, nopass, defaults);
    1423         prefWriter.write(settings);
    1424         sw.flush();
    1425         StringBuffer sb = sw.getBuffer();
    1426         return sb.toString();
     1420        try (
     1421            StringWriter sw = new StringWriter();
     1422            PreferencesWriter prefWriter = new PreferencesWriter(new PrintWriter(sw), nopass, defaults);
     1423        ) {
     1424            prefWriter.write(settings);
     1425            sw.flush();
     1426            return sw.toString();
     1427        } catch (IOException e) {
     1428            Main.error(e);
     1429            return null;
     1430        }
    14271431    }
    14281432
Note: See TracChangeset for help on using the changeset viewer.