ICU-21140 Make UTF-8 explicit for all file access.

This commit is contained in:
David Beaumont 2020-06-02 22:43:41 +02:00 committed by Jeff Genovy
parent 87bbd3d067
commit a29369b586
3 changed files with 7 additions and 4 deletions

View File

@ -3,6 +3,7 @@
package org.unicode.icu.tool.cldrtoicu; package org.unicode.icu.tool.cldrtoicu;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardOpenOption.CREATE; import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.CREATE_NEW; import static java.nio.file.StandardOpenOption.CREATE_NEW;
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
@ -49,7 +50,7 @@ final class IcuTextWriter {
Files.createDirectories(outDir); Files.createDirectories(outDir);
Path file = outDir.resolve(icuData.getName() + ".txt"); Path file = outDir.resolve(icuData.getName() + ".txt");
OpenOption[] fileOptions = allowOverwrite ? OVERWRITE_FILES : ONLY_NEW_FILES; OpenOption[] fileOptions = allowOverwrite ? OVERWRITE_FILES : ONLY_NEW_FILES;
try (Writer w = Files.newBufferedWriter(file, fileOptions); try (Writer w = Files.newBufferedWriter(file, UTF_8, fileOptions);
PrintWriter out = new PrintWriter(w)) { PrintWriter out = new PrintWriter(w)) {
new IcuTextWriter(icuData).writeTo(out, header); new IcuTextWriter(icuData).writeTo(out, header);
} }

View File

@ -5,6 +5,7 @@ package org.unicode.icu.tool.cldrtoicu.ant;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.LinkOption.NOFOLLOW_LINKS; import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.partitioningBy; import static java.util.stream.Collectors.partitioningBy;
@ -212,7 +213,7 @@ public final class CleanOutputDirectoryTask extends Task {
// Directories, symbolic links, devices etc. // Directories, symbolic links, devices etc.
return false; return false;
} }
try (BufferedReader r = Files.newBufferedReader(path)) { try (BufferedReader r = Files.newBufferedReader(path, UTF_8)) {
// A byte-order-mark (BOM) is added to ICU data files, but not JSON deps files, so just // A byte-order-mark (BOM) is added to ICU data files, but not JSON deps files, so just
// treat it as optional everywhere (it's not the important thing we check here). // treat it as optional everywhere (it's not the important thing we check here).
r.mark(1); r.mark(1);
@ -274,7 +275,7 @@ public final class CleanOutputDirectoryTask extends Task {
private static ImmutableList<String> readLinesFromResource(String name) { private static ImmutableList<String> readLinesFromResource(String name) {
try (InputStream in = CleanOutputDirectoryTask.class.getResourceAsStream(name)) { try (InputStream in = CleanOutputDirectoryTask.class.getResourceAsStream(name)) {
return ImmutableList.copyOf(CharStreams.readLines(new InputStreamReader(in))); return ImmutableList.copyOf(CharStreams.readLines(new InputStreamReader(in, UTF_8)));
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("cannot read resource: " + name, e); throw new RuntimeException("cannot read resource: " + name, e);
} }

View File

@ -4,6 +4,7 @@ package org.unicode.icu.tool.cldrtoicu.mapper;
import static com.google.common.base.CharMatcher.whitespace; import static com.google.common.base.CharMatcher.whitespace;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardOpenOption.CREATE_NEW; import static java.nio.file.StandardOpenOption.CREATE_NEW;
import static org.unicode.cldr.api.AttributeKey.keyOf; import static org.unicode.cldr.api.AttributeKey.keyOf;
import static org.unicode.cldr.api.CldrDataType.SUPPLEMENTAL; import static org.unicode.cldr.api.CldrDataType.SUPPLEMENTAL;
@ -91,7 +92,7 @@ public final class TransformsMapper {
Path file = ruleFileOutputDir.resolve(p); Path file = ruleFileOutputDir.resolve(p);
try { try {
// Specify "CREATE_NEW" since we don't want to overwrite any existing files. // Specify "CREATE_NEW" since we don't want to overwrite any existing files.
return new PrintWriter(Files.newBufferedWriter(file, CREATE_NEW)); return new PrintWriter(Files.newBufferedWriter(file, UTF_8, CREATE_NEW));
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("error opening file: " + file, e); throw new RuntimeException("error opening file: " + file, e);
} }