Changeset 16098 in josm for trunk


Ignore:
Timestamp:
2020-03-09T00:35:01+01:00 (4 years ago)
Author:
simon04
Message:

SyncEditorLayerIndex: use Files.newBufferedReader and Files.newBufferedWriter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/SyncEditorLayerIndex.java

    r15879 r16098  
    55
    66import java.io.BufferedReader;
     7import java.io.BufferedWriter;
    78import java.io.IOException;
    8 import java.io.InputStreamReader;
    9 import java.io.OutputStream;
    109import java.io.OutputStreamWriter;
     10import java.io.Writer;
    1111import java.lang.reflect.Field;
    1212import java.net.MalformedURLException;
    1313import java.net.URL;
     14import java.nio.charset.Charset;
    1415import java.nio.file.Files;
    1516import java.nio.file.Paths;
     
    9899    private static String josmInputFile = "imagery_josm.imagery.xml";
    99100    private static String ignoreInputFile = "imagery_josm.ignores.txt";
    100     private static OutputStream outputFile;
    101     private static OutputStreamWriter outputStream;
     101    private static Writer outputStream;
    102102    private static String optionOutput;
    103103    private static boolean optionShorten;
     
    132132        script.loadJosmEntries();
    133133        if (optionJosmXml != null) {
    134             try (OutputStreamWriter stream = new OutputStreamWriter(Files.newOutputStream(Paths.get(optionJosmXml)), UTF_8)) {
    135                 script.printentries(script.josmEntries, stream);
     134            try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(optionJosmXml), UTF_8)) {
     135                script.printentries(script.josmEntries, writer);
    136136            }
    137137        }
    138138        script.loadELIEntries();
    139139        if (optionEliXml != null) {
    140             try (OutputStreamWriter stream = new OutputStreamWriter(Files.newOutputStream(Paths.get(optionEliXml)), UTF_8)) {
    141                 script.printentries(script.eliEntries, stream);
     140            try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(optionEliXml), UTF_8)) {
     141                script.printentries(script.eliEntries, writer);
    142142            }
    143143        }
     
    147147        if (outputStream != null) {
    148148            outputStream.close();
    149         }
    150         if (outputFile != null) {
    151             outputFile.close();
    152149        }
    153150    }
     
    216213
    217214        if (optionOutput != null && !"-".equals(optionOutput)) {
    218             outputFile = Files.newOutputStream(Paths.get(optionOutput));
    219             outputStream = new OutputStreamWriter(outputFile, optionEncoding != null ? optionEncoding : "UTF-8");
     215            outputStream = Files.newBufferedWriter(Paths.get(optionOutput), optionEncoding != null ? Charset.forName(optionEncoding) : UTF_8);
    220216        } else if (optionEncoding != null) {
    221217            outputStream = new OutputStreamWriter(System.out, optionEncoding);
     
    244240    void loadSkip() throws IOException {
    245241        final Pattern pattern = Pattern.compile("^\\|\\| *(ELI|Ignore) *\\|\\| *\\{\\{\\{(.+)\\}\\}\\} *\\|\\|");
    246         try (BufferedReader fr = new BufferedReader(new InputStreamReader(Files.newInputStream(Paths.get(ignoreInputFile)), UTF_8))) {
     242        try (BufferedReader fr = Files.newBufferedReader(Paths.get(ignoreInputFile), UTF_8)) {
    247243            String line;
    248244
     
    342338
    343339    void loadELIEntries() throws IOException {
    344         try (JsonReader jr = Json.createReader(new InputStreamReader(Files.newInputStream(Paths.get(eliInputFile)), UTF_8))) {
     340        try (JsonReader jr = Json.createReader(Files.newBufferedReader(Paths.get(eliInputFile), UTF_8))) {
    345341            eliEntries = jr.readObject().getJsonArray("features");
    346342        }
     
    408404    }
    409405
    410     void printentries(List<?> entries, OutputStreamWriter stream) throws IOException {
     406    void printentries(List<?> entries, Writer stream) throws IOException {
    411407        DecimalFormat df = new DecimalFormat("#.#######");
    412408        df.setRoundingMode(java.math.RoundingMode.CEILING);
Note: See TracChangeset for help on using the changeset viewer.