Changeset 6552 in josm for trunk


Ignore:
Timestamp:
2013-12-28T00:30:15+01:00 (10 years ago)
Author:
simon04
Message:

Refactoring: introduce Utils.UTF_8 charset to avoid handling of UnsupportedEncodingException

According to the Javadoc of Charset, every implementation of the Java
platform is required to support UTF-8.

Location:
trunk
Files:
34 edited

Legend:

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

    r6362 r6552  
    232232        try {
    233233            String toXML = Main.pref.toXML(true);
    234             InputStream is = new ByteArrayInputStream(toXML.getBytes("UTF-8"));
     234            InputStream is = new ByteArrayInputStream(toXML.getBytes(Utils.UTF_8));
    235235            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    236236            builderFactory.setValidating(false);
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r6380 r6552  
    596596
    597597        final PrintWriter out = new PrintWriter(new OutputStreamWriter(
    598                 new FileOutputStream(prefFile + "_tmp"), "utf-8"), false);
     598                new FileOutputStream(prefFile + "_tmp"), Utils.UTF_8), false);
    599599        out.print(toXML(false));
    600600        Utils.close(out);
     
    621621        if (!Main.applet) {
    622622            File pref = getPreferenceFile();
    623             BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(pref), "utf-8"));
     623            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(pref), Utils.UTF_8));
    624624            try {
    625625                validateXML(in);
    626626                Utils.close(in);
    627                 in = new BufferedReader(new InputStreamReader(new FileInputStream(pref), "utf-8"));
     627                in = new BufferedReader(new InputStreamReader(new FileInputStream(pref), Utils.UTF_8));
    628628                fromXML(in);
    629629            } finally {
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r6551 r6552  
    66import java.io.InputStreamReader;
    77import java.io.Reader;
    8 import java.io.UnsupportedEncodingException;
    98import java.util.ArrayList;
    109import java.util.Collection;
     
    368367     * @param internalConfigFile the filename in data/validator
    369368     * @throws ParseException if the config file does not match MapCSS syntax
    370      * @throws UnsupportedEncodingException if UTF-8 charset is not supported on the platform
    371369     */
    372     private void addMapCSS(String internalConfigFile) throws ParseException, UnsupportedEncodingException {
    373         addMapCSS(new InputStreamReader(getClass().getResourceAsStream("/data/validator/" + internalConfigFile + ".mapcss"), "UTF-8"));
     370    private void addMapCSS(String internalConfigFile) throws ParseException {
     371        addMapCSS(new InputStreamReader(getClass().getResourceAsStream("/data/validator/" + internalConfigFile + ".mapcss"), Utils.UTF_8));
    374372    }
    375373
  • trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java

    r6533 r6552  
    2626import org.openstreetmap.josm.data.validation.TestError;
    2727import org.openstreetmap.josm.io.MirroredInputStream;
     28import org.openstreetmap.josm.tools.Utils;
    2829
    2930/**
     
    5354        super.initialize();
    5455        if (ENGINE != null) {
    55             ENGINE.eval(new InputStreamReader(new MirroredInputStream("resource://data/validator/opening_hours.js"), "UTF-8"));
     56            ENGINE.eval(new InputStreamReader(new MirroredInputStream("resource://data/validator/opening_hours.js"), Utils.UTF_8));
    5657            // fake country/state to not get errors on holidays
    5758            ENGINE.eval("var nominatimJSON = {address: {state: 'Bayern', country_code: 'de'}};");
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r6529 r6552  
    1414import java.io.IOException;
    1515import java.io.InputStreamReader;
    16 import java.io.UnsupportedEncodingException;
    1716import java.text.MessageFormat;
    1817import java.util.ArrayList;
     
    211210            try {
    212211                MirroredInputStream s = new MirroredInputStream(source);
    213                 InputStreamReader r;
    214                 try {
    215                     r = new InputStreamReader(s, "UTF-8");
    216                 } catch (UnsupportedEncodingException e) {
    217                     r = new InputStreamReader(s);
    218                 }
    219                 reader = new BufferedReader(r);
     212                reader = new BufferedReader(new InputStreamReader(s, Utils.UTF_8));
    220213
    221214                String okValue = null;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    r6529 r6552  
    128128                    }
    129129                    if (en.hasTag("highway", "turning_circle", "bus_stop")
     130                            || en.hasTag("amenity", "parking_entrance")
    130131                            || en.hasTag("railway", "buffer_stop")
    131132                            || OsmUtils.isTrue(en.get("noexit"))
     133                            || en.hasKey("entrance")
    132134                            || en.hasKey("barrier")) {
    133135                        continue;
  • trunk/src/org/openstreetmap/josm/gui/GettingStarted.java

    r6525 r6552  
    1010import java.awt.event.KeyEvent;
    1111import java.io.IOException;
    12 import java.io.UnsupportedEncodingException;
    1312import java.net.URL;
    1413import java.util.regex.Matcher;
     
    3130import org.openstreetmap.josm.tools.LanguageInfo;
    3231import org.openstreetmap.josm.tools.OpenBrowser;
     32import org.openstreetmap.josm.tools.Utils;
    3333import org.openstreetmap.josm.tools.WikiReader;
    3434
     
    9090            Main.pref.put("cache.motd.html.java", myJava);
    9191            Main.pref.put("cache.motd.html.lang", myLang);
    92             try {
    93                 return motd.getBytes("utf-8");
    94             } catch(UnsupportedEncodingException e){
    95                 e.printStackTrace();
    96                 return new byte[0];
    97             }
     92            return motd.getBytes(Utils.UTF_8);
    9893        }
    9994
  • trunk/src/org/openstreetmap/josm/gui/download/BookmarkList.java

    r6380 r6552  
    188188                    Main.info("Try loading obsolete bookmarks file");
    189189                    BufferedReader in = new BufferedReader(new InputStreamReader(
    190                             new FileInputStream(bookmarkFile), "utf-8"));
     190                            new FileInputStream(bookmarkFile), Utils.UTF_8));
    191191
    192192                    for (String line = in.readLine(); line != null; line = in.readLine()) {
  • trunk/src/org/openstreetmap/josm/gui/download/PlaceSelection.java

    r6316 r6552  
    370370                connection.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect",15)*1000);
    371371                InputStream inputStream = connection.getInputStream();
    372                 InputSource inputSource = new InputSource(new InputStreamReader(inputStream, "UTF-8"));
     372                InputSource inputSource = new InputSource(new InputStreamReader(inputStream, Utils.UTF_8));
    373373                NameFinderResultParser parser = new NameFinderResultParser();
    374374                SAXParserFactory.newInstance().newSAXParser().parse(inputSource, parser);
  • trunk/src/org/openstreetmap/josm/gui/help/HelpContentReader.java

    r5939 r6552  
    5050            con = Utils.openHttpConnection(u);
    5151            con.connect();
    52             in = new BufferedReader(new InputStreamReader(con.getInputStream(),"utf-8"));
     52            in = new BufferedReader(new InputStreamReader(con.getInputStream(), Utils.UTF_8));
    5353            return prepareHelpContent(in, dotest, u);
    5454        } catch(MalformedURLException e) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r6289 r6552  
    9595    public InputStream getSourceInputStream() throws IOException {
    9696        if (css != null) {
    97             return new ByteArrayInputStream(css.getBytes("UTF-8"));
     97            return new ByteArrayInputStream(css.getBytes(Utils.UTF_8));
    9898        }
    9999        MirroredInputStream in = new MirroredInputStream(url);
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r6380 r6552  
    2424import java.io.IOException;
    2525import java.io.InputStreamReader;
    26 import java.io.UnsupportedEncodingException;
    2726import java.net.MalformedURLException;
    2827import java.net.URL;
     
    12291228
    12301229                MirroredInputStream stream = new MirroredInputStream(url);
    1231                 InputStreamReader r;
    1232                 try {
    1233                     r = new InputStreamReader(stream, "UTF-8");
    1234                 } catch (UnsupportedEncodingException e) {
    1235                     r = new InputStreamReader(stream);
    1236                 }
    1237                 reader = new BufferedReader(r);
     1230                reader = new BufferedReader(new InputStreamReader(stream, Utils.UTF_8));
    12381231
    12391232                String line;
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java

    r6360 r6552  
    1010import java.io.InputStreamReader;
    1111import java.io.Reader;
    12 import java.io.UnsupportedEncodingException;
    1312import java.util.Collection;
    1413import java.util.LinkedList;
     
    162161                zipIcons = s.getFile();
    163162            }
    164             InputStreamReader r;
    165             try {
    166                 r = new InputStreamReader(zip == null ? s : zip, "UTF-8");
    167             } catch (UnsupportedEncodingException e) {
    168                 r = new InputStreamReader(zip == null ? s: zip);
    169             }
     163            InputStreamReader r = new InputStreamReader(zip == null ? s : zip, Utils.UTF_8);
    170164            try {
    171165                tp = readAll(new BufferedReader(r), validate);
  • trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java

    r6102 r6552  
    88import java.io.FileOutputStream;
    99import java.io.IOException;
    10 import java.io.UnsupportedEncodingException;
    1110
    1211import org.openstreetmap.josm.Main;
     
    120119    public String updateForceString() throws T {
    121120        updateForce();
    122         try {
    123             return new String(data, "utf-8");
    124         } catch (UnsupportedEncodingException e){
    125             e.printStackTrace();
    126             return "";
    127         }
     121        return new String(data, Utils.UTF_8);
    128122    }
    129123
     
    144138     */
    145139    public String getDataString() throws T {
    146         try {
    147             return new String(getData(), "utf-8");
    148         } catch(UnsupportedEncodingException e){
    149             e.printStackTrace();
    150             return "";
    151         }
     140        return new String(getData(), Utils.UTF_8);
    152141    }
    153142
  • trunk/src/org/openstreetmap/josm/io/GeoJSONExporter.java

    r6070 r6552  
    2929        if (layer instanceof OsmDataLayer) {
    3030            String json = new GeoJSONWriter((OsmDataLayer) layer).write();
    31             Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
     31            Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), Utils.UTF_8));
    3232            try {
    3333                out.write(json);
  • trunk/src/org/openstreetmap/josm/io/GpxWriter.java

    r6380 r6552  
    88import java.io.OutputStreamWriter;
    99import java.io.PrintWriter;
    10 import java.io.UnsupportedEncodingException;
    1110import java.util.Collection;
    1211import java.util.Map;
     
    2423import org.openstreetmap.josm.data.gpx.IWithAttributes;
    2524import org.openstreetmap.josm.data.gpx.WayPoint;
     25import org.openstreetmap.josm.tools.Utils;
    2626
    2727/**
     
    3434    }
    3535
    36     public GpxWriter(OutputStream out) throws UnsupportedEncodingException {
    37         super(new PrintWriter(new BufferedWriter(new OutputStreamWriter(out, "UTF-8"))));
     36    public GpxWriter(OutputStream out) {
     37        super(new PrintWriter(new BufferedWriter(new OutputStreamWriter(out, Utils.UTF_8))));
    3838    }
    3939
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r6349 r6552  
    627627                    // even if there is no payload.
    628628                    if (requestBody != null) {
    629                         BufferedWriter bwr = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
     629                        BufferedWriter bwr = new BufferedWriter(new OutputStreamWriter(out, Utils.UTF_8));
    630630                        try {
    631631                            bwr.write(requestBody);
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetContentParser.java

    r6380 r6552  
    88import java.io.InputStreamReader;
    99import java.io.StringReader;
    10 import java.io.UnsupportedEncodingException;
    1110
    1211import javax.xml.parsers.ParserConfigurationException;
     
    1918import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2019import org.openstreetmap.josm.tools.CheckParameterUtil;
     20import org.openstreetmap.josm.tools.Utils;
    2121import org.xml.sax.Attributes;
    2222import org.xml.sax.InputSource;
     
    105105     *
    106106     * @param source the input stream with the changeset content as XML document. Must not be null.
    107      * @throws UnsupportedEncodingException if {@code UTF-8} charset is missing
    108107     * @throws IllegalArgumentException if source is {@code null}.
    109108     */
    110     public OsmChangesetContentParser(InputStream source) throws UnsupportedEncodingException {
     109    public OsmChangesetContentParser(InputStream source) {
    111110        CheckParameterUtil.ensureParameterNotNull(source, "source");
    112         this.source = new InputSource(new InputStreamReader(source, "UTF-8"));
     111        this.source = new InputSource(new InputStreamReader(source, Utils.UTF_8));
    113112    }
    114113
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java

    r6362 r6552  
    1818import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1919import org.openstreetmap.josm.tools.DateUtils;
     20import org.openstreetmap.josm.tools.Utils;
    2021import org.xml.sax.Attributes;
    2122import org.xml.sax.InputSource;
     
    214215            progressMonitor.beginTask("");
    215216            progressMonitor.indeterminateSubTask(tr("Parsing list of changesets..."));
    216             InputSource inputSource = new InputSource(new InputStreamReader(source, "UTF-8"));
     217            InputSource inputSource = new InputSource(new InputStreamReader(source, Utils.UTF_8));
    217218            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, parser.new Parser());
    218219            return parser.getChangesets();
  • trunk/src/org/openstreetmap/josm/io/OsmConnection.java

    r6380 r6552  
    2222import org.openstreetmap.josm.io.auth.CredentialsManager;
    2323import org.openstreetmap.josm.tools.Base64;
     24import org.openstreetmap.josm.tools.Utils;
    2425
    2526/**
     
    7374     */
    7475    protected void addBasicAuthorizationHeader(HttpURLConnection con) throws OsmTransferException {
    75         CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
     76        CharsetEncoder encoder = Utils.UTF_8.newEncoder();
    7677        CredentialsAgentResponse response;
    7778        String token;
  • trunk/src/org/openstreetmap/josm/io/OsmExporter.java

    r5926 r6552  
    6969            // create outputstream and wrap it with gzip or bzip, if necessary
    7070            OutputStream out = getOutputStream(file);
    71             Writer writer = new OutputStreamWriter(out, "UTF-8");
     71            Writer writer = new OutputStreamWriter(out, Utils.UTF_8);
    7272
    7373            OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, layer.data.getVersion());
  • trunk/src/org/openstreetmap/josm/io/OsmHistoryReader.java

    r6380 r6552  
    1616import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1717import org.openstreetmap.josm.tools.CheckParameterUtil;
     18import org.openstreetmap.josm.tools.Utils;
    1819import org.xml.sax.Attributes;
    1920import org.xml.sax.InputSource;
     
    8081     */
    8182    public HistoryDataSet parse(ProgressMonitor progressMonitor) throws SAXException, IOException {
    82         InputSource inputSource = new InputSource(new InputStreamReader(in, "UTF-8"));
     83        InputSource inputSource = new InputSource(new InputStreamReader(in, Utils.UTF_8));
    8384        progressMonitor.beginTask(tr("Parsing OSM history data ..."));
    8485        try {
  • trunk/src/org/openstreetmap/josm/io/OsmServerChangesetReader.java

    r6362 r6552  
    66
    77import java.io.InputStream;
    8 import java.io.UnsupportedEncodingException;
    98import java.text.MessageFormat;
    109import java.util.ArrayList;
     
    185184            ChangesetDataSet ds = parser.parse(monitor.createSubTaskMonitor(1, true));
    186185            return ds;
    187         } catch(UnsupportedEncodingException e) {
    188             throw new OsmTransferException(e);
    189186        } catch(OsmDataParsingException e) {
    190187            throw new OsmTransferException(e);
  • trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java

    r6310 r6552  
    2121import org.openstreetmap.josm.io.MirroredInputStream;
    2222import org.openstreetmap.josm.io.UTFInputStreamReader;
     23import org.openstreetmap.josm.tools.Utils;
    2324import org.xml.sax.Attributes;
    2425import org.xml.sax.InputSource;
  • trunk/src/org/openstreetmap/josm/io/session/GpxTracksSessionExporter.java

    r6150 r6552  
    1717import java.io.OutputStreamWriter;
    1818import java.io.PrintWriter;
    19 import java.io.UnsupportedEncodingException;
    2019import java.io.Writer;
    2120import java.net.MalformedURLException;
     
    3938import org.openstreetmap.josm.io.session.SessionWriter.ExportSupport;
    4039import org.openstreetmap.josm.tools.GBC;
     40import org.openstreetmap.josm.tools.Utils;
    4141import org.w3c.dom.Element;
    4242
     
    180180
    181181    protected void addDataFile(OutputStream out) throws IOException {
    182         Writer writer = null;
    183         try {
    184             writer = new OutputStreamWriter(out, "UTF-8");
    185         } catch (UnsupportedEncodingException e) {
    186             throw new RuntimeException(e);
    187         }
     182        Writer writer = new OutputStreamWriter(out, Utils.UTF_8);
    188183        GpxWriter w = new GpxWriter(new PrintWriter(writer));
    189184        w.write(layer.data);
  • trunk/src/org/openstreetmap/josm/io/session/MarkerSessionExporter.java

    r5874 r6552  
    88import java.io.OutputStreamWriter;
    99import java.io.PrintWriter;
    10 import java.io.UnsupportedEncodingException;
    1110import java.io.Writer;
    1211import java.util.Collection;
     
    1817import javax.swing.SwingConstants;
    1918
     19import org.openstreetmap.josm.tools.Utils;
    2020import org.w3c.dom.Element;
    2121
     
    8686
    8787    protected void addDataFile(OutputStream out) throws IOException {
    88         Writer writer = null;
    89         try {
    90             writer = new OutputStreamWriter(out, "UTF-8");
    91         } catch (UnsupportedEncodingException e) {
    92             throw new RuntimeException(e);
    93         }
     88        Writer writer = new OutputStreamWriter(out, Utils.UTF_8);
    9489        MarkerWriter w = new MarkerWriter(new PrintWriter(writer));
    9590        w.write(layer);
  • trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java

    r6084 r6552  
    1717import java.io.OutputStreamWriter;
    1818import java.io.PrintWriter;
    19 import java.io.UnsupportedEncodingException;
    2019import java.io.Writer;
    2120import java.net.MalformedURLException;
     
    3433import javax.swing.SwingConstants;
    3534
     35import org.openstreetmap.josm.tools.Utils;
    3636import org.w3c.dom.Element;
    3737
     
    214214
    215215    protected void addDataFile(OutputStream out) throws IOException {
    216         Writer writer = null;
    217         try {
    218             writer = new OutputStreamWriter(out, "UTF-8");
    219         } catch (UnsupportedEncodingException e) {
    220             throw new RuntimeException(e);
    221         }
     216        Writer writer = new OutputStreamWriter(out, Utils.UTF_8);
    222217        OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, layer.data.getVersion());
    223218        layer.data.getReadLock().lock();
  • trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java

    r6271 r6552  
    225225    public void writeJos(Document doc, OutputStream out) throws IOException {
    226226        try {
    227             OutputStreamWriter writer = new OutputStreamWriter(out, "utf-8");
     227            OutputStreamWriter writer = new OutputStreamWriter(out, Utils.UTF_8);
    228228            writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
    229229            TransformerFactory transfac = TransformerFactory.newInstance();
  • trunk/src/org/openstreetmap/josm/plugins/PluginListParser.java

    r6296 r6552  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins;
     3
     4import org.openstreetmap.josm.tools.Utils;
    35
    46import static org.openstreetmap.josm.tools.I18n.tr;
     
    911import java.io.InputStream;
    1012import java.io.InputStreamReader;
    11 import java.io.UnsupportedEncodingException;
    1213import java.util.LinkedList;
    1314import java.util.List;
     
    3536        try {
    3637            return new PluginInformation(
    37                     new ByteArrayInputStream(manifest.getBytes("utf-8")),
     38                    new ByteArrayInputStream(manifest.getBytes(Utils.UTF_8)),
    3839                    name.substring(0, name.length() - 4),
    3940                    url
    4041                    );
    41         } catch(UnsupportedEncodingException e) {
    42             throw new PluginListParseException(tr("Failed to create plugin information from manifest for plugin ''{0}''", name), e);
    4342        } catch (PluginException e) {
    4443            throw new PluginListParseException(tr("Failed to create plugin information from manifest for plugin ''{0}''", name), e);
     
    6160        BufferedReader r = null;
    6261        try {
    63             r = new BufferedReader(new InputStreamReader(in, "utf-8"));
     62            r = new BufferedReader(new InputStreamReader(in, Utils.UTF_8));
    6463            String name = null;
    6564            String url = null;
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r6257 r6552  
    1717import java.io.OutputStreamWriter;
    1818import java.io.PrintWriter;
    19 import java.io.UnsupportedEncodingException;
    2019import java.net.HttpURLConnection;
    2120import java.net.MalformedURLException;
     
    174173                connection.setRequestProperty("Accept-Charset", "utf-8");
    175174            }
    176             in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
     175            in = new BufferedReader(new InputStreamReader(connection.getInputStream(), Utils.UTF_8));
    177176            StringBuilder sb = new StringBuilder();
    178177            while ((line = in.readLine()) != null) {
     
    207206            try {
    208207                String line;
    209                 err = new BufferedReader(new InputStreamReader(errStream, "UTF-8"));
     208                err = new BufferedReader(new InputStreamReader(errStream, Utils.UTF_8));
    210209                while ((line = err.readLine()) != null) {
    211210                    sb.append(line).append("\n");
     
    319318            File cacheFile = createSiteCacheFile(pluginDir, site, CacheType.PLUGIN_LIST);
    320319            getProgressMonitor().subTask(tr("Writing plugin list to local cache ''{0}''", cacheFile.toString()));
    321             writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(cacheFile), "utf-8"));
     320            writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(cacheFile), Utils.UTF_8));
    322321            writer.write(list);
    323322        } catch(IOException e) {
     
    363362        try {
    364363            getProgressMonitor().subTask(tr("Parsing plugin list from site ''{0}''", site));
    365             InputStream in = new ByteArrayInputStream(doc.getBytes("UTF-8"));
     364            InputStream in = new ByteArrayInputStream(doc.getBytes(Utils.UTF_8));
    366365            List<PluginInformation> pis = new PluginListParser().parse(in);
    367366            availablePlugins.addAll(filterDeprecatedPlugins(pis));
    368         } catch (UnsupportedEncodingException e) {
    369             Main.error(tr("Failed to parse plugin list document from site ''{0}''. Skipping site. Exception was: {1}", site, e.toString()));
    370             e.printStackTrace();
    371367        } catch (PluginListParseException e) {
    372368            Main.error(tr("Failed to parse plugin list document from site ''{0}''. Skipping site. Exception was: {1}", site, e.toString()));
  • trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java

    r6380 r6552  
    194194            ByteArrayOutputStream out = new ByteArrayOutputStream();
    195195            GZIPOutputStream gzip = new GZIPOutputStream(out);
    196             gzip.write(debugText.getBytes("UTF-8"));
     196            gzip.write(debugText.getBytes(Utils.UTF_8));
    197197            Utils.close(gzip);
    198198
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r6380 r6552  
    548548                        if(rval != val) /* file corrupt */
    549549                            return false;
    550                         enstrings[i] = new String(str, 0, val, "utf-8");
     550                        enstrings[i] = new String(str, 0, val, Utils.UTF_8);
    551551                    }
    552552                    for(int i = 0; i < trnum; ++i)
     
    562562                        if(rval != val) /* file corrupt */
    563563                            return false;
    564                         trstrings[i] = new String(str, 0, val, "utf-8");
     564                        trstrings[i] = new String(str, 0, val, Utils.UTF_8);
    565565                    }
    566566                    if(trnum > 0 && !p.containsKey(enstrings[0])) {
     
    600600                        if(val != enval) /* file corrupt */
    601601                            return false;
    602                         String enstr = new String(str, 0, enval, "utf-8");
     602                        String enstr = new String(str, 0, enval, Utils.UTF_8);
    603603                        if(trval != 0)
    604604                        {
     
    606606                            if(val != trval) /* file corrupt */
    607607                                return false;
    608                             String trstr = new String(str, 0, trval, "utf-8");
     608                            String trstr = new String(str, 0, trval, Utils.UTF_8);
    609609                            if(!s.containsKey(enstr))
    610610                                s.put(enstr, trstr);
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6538 r6552  
    2323import java.io.InputStreamReader;
    2424import java.io.OutputStream;
    25 import java.io.UnsupportedEncodingException;
    2625import java.net.HttpURLConnection;
    2726import java.net.URL;
    2827import java.net.URLConnection;
    2928import java.nio.channels.FileChannel;
     29import java.nio.charset.Charset;
    3030import java.security.MessageDigest;
    3131import java.security.NoSuchAlgorithmException;
     
    5656    }
    5757
     58    /**
     59     * UTF-8 (UCS Transformation Format—8-bit).
     60     *
     61     * <p>Every implementation of the Java platform is required to support UTF-8 (see {@link Charset}).</p>
     62     */
     63    public static final Charset UTF_8 = Charset.forName("UTF-8");
     64
    5865    public static <T> boolean exists(Iterable<? extends T> collection, Predicate<? super T> predicate) {
    5966        for (T item : collection) {
     
    436443     */
    437444    public static String md5Hex(String data) {
    438         byte[] byteData = null;
    439         try {
    440             byteData = data.getBytes("UTF-8");
    441         } catch (UnsupportedEncodingException e) {
    442             throw new RuntimeException();
    443         }
     445        byte[] byteData = data.getBytes(UTF_8);
    444446        MessageDigest md = null;
    445447        try {
     
    707709     */
    708710    public static BufferedReader openURLReaderAndDecompress(final URL url, final boolean decompress) throws IOException {
    709         return new BufferedReader(new InputStreamReader(openURLAndDecompress(url, decompress), "utf-8"));
     711        return new BufferedReader(new InputStreamReader(openURLAndDecompress(url, decompress), UTF_8));
    710712    }
    711713
  • trunk/test/unit/org/openstreetmap/josm/io/OsmChangesetContentParserTest.groovy

    r2690 r6552  
    22package org.openstreetmap.josm.io;
    33
    4 import org.junit.Test
     4import org.junit.Test
     5import org.openstreetmap.josm.tools.Utils
    56
    67import static org.junit.Assert.*;
     
    4243               
    4344                // should be OK
    44                 parser = new OsmChangesetContentParser(new ByteArrayInputStream(doc.getBytes("UTF-8")))
     45                parser = new OsmChangesetContentParser(new ByteArrayInputStream(doc.getBytes(Utils.UTF_8)))
    4546                parser.parse null
    4647               
    4748                // should be OK
    48                 parser = new OsmChangesetContentParser(new ByteArrayInputStream(doc.getBytes("UTF-8")))         
     49                parser = new OsmChangesetContentParser(new ByteArrayInputStream(doc.getBytes(Utils.UTF_8)))
    4950                parser.parse NullProgressMonitor.INSTANCE
    5051               
Note: See TracChangeset for help on using the changeset viewer.