Changeset 14746 in josm


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

Refactoring: use StandardCharsets

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/TagInfoExtract.java

    r14651 r14746  
    55import java.io.BufferedReader;
    66import java.io.IOException;
    7 import java.io.InputStream;
    87import java.io.OutputStream;
    98import java.io.StringWriter;
     
    321320         */
    322321        private void parseStyleSheet() throws IOException, ParseException {
    323             try (InputStream stream = options.inputFile.getInputStream()) {
    324                 MapCSSParser parser = new MapCSSParser(stream, "UTF-8", MapCSSParser.LexicalState.DEFAULT);
     322            try (BufferedReader reader = options.inputFile.getContentReader()) {
     323                MapCSSParser parser = new MapCSSParser(reader, MapCSSParser.LexicalState.DEFAULT);
    325324                styleSource = new MapCSSStyleSource("");
    326325                styleSource.url = "";
  • 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")
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTestIT.java

    r14235 r14746  
    22package org.openstreetmap.josm.gui.mappaint.mapcss;
    33
    4 import java.io.IOException;
    5 import java.net.URL;
    6 
     4import org.junit.Ignore;
    75import org.junit.Rule;
    86import org.junit.Test;
     
    2624    /**
    2725     * Checks Kothic stylesheets
    28      * @throws IOException if an I/O error occurs
    2926     */
    3027    @Test
    31     public void testKothicStylesheets() throws IOException {
    32         new MapCSSParser(new URL("https://raw.githubusercontent.com/kothic/kothic/master/src/styles/default.mapcss").openStream(), "UTF-8");
    33         new MapCSSParser(new URL("https://raw.githubusercontent.com/kothic/kothic/master/src/styles/mapink.mapcss").openStream(), "UTF-8");
     28    @Ignore("parsing fails")
     29    public void testKothicStylesheets() {
     30        new MapCSSStyleSource("https://raw.githubusercontent.com/kothic/kothic/master/src/styles/default.mapcss").loadStyleSource();
     31        new MapCSSStyleSource("https://raw.githubusercontent.com/kothic/kothic/master/src/styles/mapink.mapcss").loadStyleSource();
    3432    }
    3533}
  • trunk/test/unit/org/openstreetmap/josm/io/OsmWriterTest.java

    r14274 r14746  
    6868        }
    6969        assertEquals("<?xml version='1.0' encoding='UTF-8'?>" + expected,
    70                 baos.toString("UTF-8").replaceAll("\r", "").replaceAll("\n", ""));
     70                new String(baos.toByteArray(), StandardCharsets.UTF_8)
     71                        .replaceAll("\r", "")
     72                        .replaceAll("\n", ""));
    7173    }
    7274
     
    8587        }
    8688        assertEquals("<?xml version='1.0' encoding='UTF-8'?><osm version='0.6' locked='true' generator='JOSM'></osm>",
    87                 baos.toString("UTF-8").replaceAll("\r", "").replaceAll("\n", ""));
     89                new String(baos.toByteArray(), StandardCharsets.UTF_8)
     90                        .replaceAll("\r", "")
     91                        .replaceAll("\n", ""));
    8892    }
    8993}
Note: See TracChangeset for help on using the changeset viewer.