Ignore:
Timestamp:
2014-10-19T01:27:04+02:00 (10 years ago)
Author:
donvip
Message:

[josm_plugins] fix java 7 warnings / global usage of try-with-resource

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/preferences/ServerParamList.java

    r30737 r30738  
    11/**
    22 *  Tracer2 - plug-in for JOSM to capture contours
    3  * 
     3 *
    44 *  This program is free software; you can redistribute it and/or modify
    55 *  it under the terms of the GNU General Public License as published by
    66 *  the Free Software Foundation; either version 2 of the License, or
    77 *  (at your option) any later version.
    8  * 
     8 *
    99 *  This program is distributed in the hope that it will be useful,
    1010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1111 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1212 *  GNU General Public License for more details.
    13  * 
     13 *
    1414 *  You should have received a copy of the GNU General Public License along
    1515 *  with this program; if not, write to the Free Software Foundation, Inc.,
     
    2828import java.util.List;
    2929
     30import org.openstreetmap.josm.Main;
     31
    3032public class ServerParamList {
    3133    ArrayList<ServerParam> m_listServerParam = new ArrayList<>();
    3234    ServerParam m_oActivParam = null;
    3335    String m_strFilename;
    34    
     36
    3537    public ServerParamList(String filename) {
    3638        this.m_strFilename = filename;
     
    4143        }
    4244    }
    43    
     45
    4446    public void load() {
    45         try {
    46             BufferedReader oReader = new BufferedReader(new InputStreamReader(new FileInputStream(m_strFilename), "UTF-8"));
     47        try (BufferedReader oReader = new BufferedReader(new InputStreamReader(new FileInputStream(m_strFilename), "UTF-8"))) {
    4748            StringBuilder oBuilder = new StringBuilder();
    4849            String strLine;
     
    5455                }
    5556            }
    56             oReader.close();
    5757        } catch (Exception e) {
    5858                loadDefault();
    5959        }
    6060    }
    61    
     61
    6262    public void loadDefault() {
    63         try {
     63        try (
    6464                InputStream oIP = getClass().getResourceAsStream("/resources/serverParam.cfg");
    6565            BufferedReader oReader = new BufferedReader(new InputStreamReader(oIP));
     66        ) {
    6667            StringBuilder oBuilder = new StringBuilder();
    6768            String strLine;
     
    7374                }
    7475            }
    75             oReader.close();
    7676        } catch (Exception e) {
    77                 System.err.println("Tracer2 warning: can't load file " + m_strFilename);
    78             //e.printStackTrace();
     77                Main.warn("Tracer2 warning: can't load file " + m_strFilename);
    7978        }
    8079    }
    8180
    8281    public void save() {
    83         try {
    84             OutputStreamWriter oWriter = new OutputStreamWriter(new FileOutputStream(m_strFilename), "UTF-8");
     82        try (OutputStreamWriter oWriter = new OutputStreamWriter(new FileOutputStream(m_strFilename), "UTF-8")) {
    8583            for (ServerParam param : m_listServerParam) {
    8684                oWriter.write(param.serialize());
    8785            }
    88             oWriter.close();
    8986        } catch (Exception e) {
    90                 System.err.println("Tracer2 warning: can't save file " + m_strFilename);
    91             //e.printStackTrace();
     87                Main.warn("Tracer2 warning: can't save file " + m_strFilename);
    9288        }
    9389    }
    94    
     90
    9591    public List<ServerParam> getParamList() {
    9692        return m_listServerParam;
    9793    }
    98    
     94
    9995    public ServerParam getActivParam() {
    10096        return m_oActivParam;
     
    105101        }
    106102    }
    107    
     103
    108104    public List<ServerParam> getEnableParamList() {
    109105        List<ServerParam> listParam = new ArrayList<>();
     
    115111        return listParam;
    116112    }
    117    
     113
    118114    public void addParam(ServerParam param) {
    119115        m_listServerParam.add(param);
    120116    }
    121    
     117
    122118    public void removeParam(ServerParam param) {
    123119        param.setEnabled(false);
    124120        m_listServerParam.remove(param);
    125121    }
    126    
    127122}
Note: See TracChangeset for help on using the changeset viewer.