Changeset 14746 in josm for trunk/src/org


Ignore:
Timestamp:
2019-01-27T22:26:35+01:00 (6 years ago)
Author:
simon04
Message:

Refactoring: use StandardCharsets

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AboutAction.java

    r14745 r14746  
    2020import java.io.InputStream;
    2121import java.io.InputStreamReader;
     22import java.nio.charset.StandardCharsets;
    2223import java.util.Map.Entry;
    2324
     
    236237            displayErrorMessage(ta, tr("Failed to locate resource ''{0}''.", filePath));
    237238        } else {
    238             try (InputStreamReader reader = new InputStreamReader(is, "UTF-8");
    239                  BufferedReader br = new BufferedReader(reader)) {
     239            try (BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
    240240                String line;
    241241                while ((line = br.readLine()) != null) {
  • trunk/src/org/openstreetmap/josm/data/imagery/CachedAttributionBingAerialTileSource.java

    r12620 r14746  
    66import java.net.MalformedURLException;
    77import java.net.URL;
     8import java.nio.charset.StandardCharsets;
    89import java.util.List;
    910import java.util.concurrent.Callable;
     
    5859            final String r = HttpClient.create(u).connect().fetchContent();
    5960            Logging.info("Successfully loaded Bing attribution data.");
    60             return r.getBytes("UTF-8");
     61            return r.getBytes(StandardCharsets.UTF_8);
    6162        }
    6263
  • trunk/src/org/openstreetmap/josm/gui/layer/AutosaveTask.java

    r13852 r14746  
    1010import java.io.FileFilter;
    1111import java.io.IOException;
    12 import java.io.PrintStream;
    1312import java.lang.management.ManagementFactory;
    1413import java.nio.charset.StandardCharsets;
     
    1615import java.nio.file.Path;
    1716import java.util.ArrayList;
     17import java.util.Collections;
    1818import java.util.Date;
    1919import java.util.Deque;
     
    223223    private static void createNewPidFile(File autosaveDir, String filename) {
    224224        File pidFile = new File(autosaveDir, filename+".pid");
    225         try (PrintStream ps = new PrintStream(pidFile, "UTF-8")) {
    226             ps.println(ManagementFactory.getRuntimeMXBean().getName());
     225        try {
     226            final String content = ManagementFactory.getRuntimeMXBean().getName();
     227            Files.write(pidFile.toPath(), Collections.singleton(content), StandardCharsets.UTF_8);
    227228        } catch (IOException | SecurityException t) {
    228229            Logging.error(t);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    r14489 r14746  
    8989     * @param initState initial state
    9090     */
     91    @Deprecated
    9192    public MapCSSParser(InputStream in, String encoding, LexicalState initState) {
    9293        this(createTokenManager(in, encoding, initState));
     
    9495    }
    9596
     97    @Deprecated
    9698    protected static MapCSSParserTokenManager createTokenManager(InputStream in, String encoding, LexicalState initState) {
    9799        SimpleCharStream scs;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r14474 r14746  
    55
    66import java.awt.Color;
     7import java.io.BufferedReader;
    78import java.io.ByteArrayInputStream;
    89import java.io.File;
    910import java.io.IOException;
    1011import java.io.InputStream;
     12import java.io.Reader;
     13import java.io.StringReader;
    1114import java.lang.reflect.Field;
    1215import java.nio.charset.StandardCharsets;
     
    6265import org.openstreetmap.josm.gui.mappaint.styleelement.LineElement;
    6366import org.openstreetmap.josm.io.CachedFile;
     67import org.openstreetmap.josm.io.UTFInputStreamReader;
    6468import org.openstreetmap.josm.tools.CheckParameterUtil;
    6569import org.openstreetmap.josm.tools.I18n;
     
    426430            canvasRules.clear();
    427431            try (InputStream in = getSourceInputStream()) {
    428                 try {
     432                try (Reader reader = new BufferedReader(UTFInputStreamReader.create(in))) {
    429433                    // evaluate @media { ... } blocks
    430                     MapCSSParser preprocessor = new MapCSSParser(in, "UTF-8", MapCSSParser.LexicalState.PREPROCESSOR);
     434                    MapCSSParser preprocessor = new MapCSSParser(reader, MapCSSParser.LexicalState.PREPROCESSOR);
    431435                    String mapcss = preprocessor.pp_root(this);
    432436
    433437                    // do the actual mapcss parsing
    434                     InputStream in2 = new ByteArrayInputStream(mapcss.getBytes(StandardCharsets.UTF_8));
    435                     MapCSSParser parser = new MapCSSParser(in2, "UTF-8", MapCSSParser.LexicalState.DEFAULT);
     438                    Reader in2 = new StringReader(mapcss);
     439                    MapCSSParser parser = new MapCSSParser(in2, MapCSSParser.LexicalState.DEFAULT);
    436440                    parser.sheet(this);
    437441
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportSender.java

    r14273 r14746  
    55import java.io.InputStream;
    66import java.net.URL;
    7 import java.net.URLEncoder;
    87import java.nio.charset.StandardCharsets;
    98import java.util.Base64;
     
    116115            String text = Utils.strip(statusText);
    117116            String pdata = Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8));
    118             String postQuery = "pdata=" + URLEncoder.encode(pdata, "UTF-8");
     117            String postQuery = "pdata=" + Utils.encodeUrl(pdata);
    119118            HttpClient client = HttpClient.create(new URL(getJOSMTicketURL()), "POST")
    120119                    .setHeader("Content-Type", "application/x-www-form-urlencoded")
Note: See TracChangeset for help on using the changeset viewer.