Ignore:
Timestamp:
2013-12-28T00:30:15+01:00 (7 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/src/org/openstreetmap/josm/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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()));
Note: See TracChangeset for help on using the changeset viewer.