aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar Florian Weikert <fwe@google.com>2015-08-01 20:03:46 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-08-04 09:07:14 +0000
commit75037576b6bb97fa970ace22d72ddc3d5d0d61bb (patch)
tree31fdf763a23bdefbe718faaecf138eb2f072df8e /src/main/java/com/google/devtools/build/lib
parentd75bf4da5748b251f09d73e0f977e35698e779df (diff)
TemplateExpansionAction now consistently uses UTF-8 instead of mixing UTF-8 with Latin-1
-- MOS_MIGRATED_REVID=99651466
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java7
2 files changed, 13 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java
index 0a806825c5..30ff2fb453 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java
@@ -14,8 +14,6 @@
package com.google.devtools.build.lib.analysis.actions;
-import static java.nio.charset.StandardCharsets.UTF_8;
-
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
@@ -33,6 +31,8 @@ import com.google.devtools.build.lib.vfs.Path;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.List;
@@ -145,6 +145,8 @@ public class TemplateExpansionAction extends AbstractFileWriteAction {
*/
public abstract static class Template {
+ private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
+
/**
* We only allow subclasses in this file.
*/
@@ -218,7 +220,7 @@ public class TemplateExpansionAction extends AbstractFileWriteAction {
protected String getContent() throws IOException {
Path templatePath = templateArtifact.getPath();
try {
- return new String(FileSystemUtils.readContentAsLatin1(templatePath));
+ return FileSystemUtils.readContent(templatePath, DEFAULT_CHARSET);
} catch (IOException e) {
throw new IOException("failed to load template file '" + templatePath.getPathString()
+ "' due to I/O error: " + e.getMessage(), e);
@@ -320,7 +322,7 @@ public class TemplateExpansionAction extends AbstractFileWriteAction {
@Override
public DeterministicWriter newDeterministicWriter(EventHandler eventHandler,
Executor executor) throws IOException {
- final byte[] bytes = getFileContents().getBytes(UTF_8);
+ final byte[] bytes = getFileContents().getBytes(Template.DEFAULT_CHARSET);
return new DeterministicWriter() {
@Override
public void writeOutputFile(OutputStream out) throws IOException {
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java
index 6ce67aeac2..840433a11e 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java
@@ -936,6 +936,13 @@ public class FileSystemUtils {
}
/**
+ * Reads the entire file using the given charset and returns the contents as a string
+ */
+ public static String readContent(Path inputFile, Charset charset) throws IOException {
+ return asByteSource(inputFile).asCharSource(charset).read();
+ }
+
+ /**
* Reads at most {@code limit} bytes from {@code inputFile} and returns it as a byte array.
*
* @throws IOException if there was an error.