ICU-21140 Make UTF-8 explicit for all file access.
authorDavid Beaumont <dbeaumont@google.com>
Tue, 2 Jun 2020 20:43:41 +0000 (22:43 +0200)
committerJeff Genovy <29107334+jefgen@users.noreply.github.com>
Wed, 3 Jun 2020 18:09:02 +0000 (11:09 -0700)
tools/cldr/cldr-to-icu/src/main/java/org/unicode/icu/tool/cldrtoicu/IcuTextWriter.java
tools/cldr/cldr-to-icu/src/main/java/org/unicode/icu/tool/cldrtoicu/ant/CleanOutputDirectoryTask.java
tools/cldr/cldr-to-icu/src/main/java/org/unicode/icu/tool/cldrtoicu/mapper/TransformsMapper.java

index a91ad264ec01cb15a2a457507b7940616a6214b2..54de15b3cf3a7378e579ae795e7d6cad7b88226f 100644 (file)
@@ -3,6 +3,7 @@
 package org.unicode.icu.tool.cldrtoicu;
 
 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_NEW;
 import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
@@ -49,7 +50,7 @@ final class IcuTextWriter {
             Files.createDirectories(outDir);
             Path file = outDir.resolve(icuData.getName() + ".txt");
             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)) {
                 new IcuTextWriter(icuData).writeTo(out, header);
             }
index 3c013d64bcb522ccaa9bbffeb6ea735c78c764bc..382f76db786d2ee152daa96a525e342958fc7117 100644 (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.checkState;
 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.util.stream.Collectors.joining;
 import static java.util.stream.Collectors.partitioningBy;
@@ -212,7 +213,7 @@ public final class CleanOutputDirectoryTask extends Task {
             // Directories, symbolic links, devices etc.
             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
             // treat it as optional everywhere (it's not the important thing we check here).
             r.mark(1);
@@ -274,7 +275,7 @@ public final class CleanOutputDirectoryTask extends Task {
 
     private static ImmutableList<String> readLinesFromResource(String 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) {
             throw new RuntimeException("cannot read resource: " + name, e);
         }
index f1ce048700a2c6f92323e4f5ab7793450f4cd0fe..b45fe770c4d82f038c98332b5c35a0536e629439 100644 (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.Preconditions.checkNotNull;
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static java.nio.file.StandardOpenOption.CREATE_NEW;
 import static org.unicode.cldr.api.AttributeKey.keyOf;
 import static org.unicode.cldr.api.CldrDataType.SUPPLEMENTAL;
@@ -91,7 +92,7 @@ public final class TransformsMapper {
             Path file = ruleFileOutputDir.resolve(p);
             try {
                 // 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) {
                 throw new RuntimeException("error opening file: " + file, e);
             }