HADOOP-15305. Replace FileUtils.writeStringToFile(File, String) with (File, String, Charset) to fix deprecation warnings.

Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
This commit is contained in:
fang zhenyi 2018-03-15 16:11:53 +09:00 committed by Akira Ajisaka
parent 5ff22d4c3a
commit 5e013d50d1
No known key found for this signature in database
GPG Key ID: C1EDBB9CA400FD50
7 changed files with 25 additions and 17 deletions

View File

@ -22,7 +22,7 @@
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import org.apache.commons.io.FileUtils;
@ -61,7 +61,7 @@ public static void beforeClass() throws Exception {
System.setProperty("httpfs.log.dir", logsDir.getAbsolutePath());
System.setProperty("httpfs.config.dir", confDir.getAbsolutePath());
FileUtils.writeStringToFile(new File(confDir, "httpfs-signature.secret"),
"foo", Charset.forName("UTF-8"));
"foo", StandardCharsets.UTF_8);
}
@Before

View File

@ -34,6 +34,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
@ -284,7 +285,7 @@ public void setOutput(String output) {
public void createSnapshot(String snapShotName) throws IOException {
String json = this.toJson();
File outFile = new File(getOutput() + "/" + snapShotName);
FileUtils.writeStringToFile(outFile, json);
FileUtils.writeStringToFile(outFile, json, StandardCharsets.UTF_8);
}
/**

View File

@ -21,6 +21,7 @@
import static org.apache.hadoop.test.PlatformAssumptions.assumeWindows;
import java.io.File;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration;
@ -65,7 +66,8 @@ public void testValidScript() throws Exception {
// Create a simple script which echoes the given key plus the given
// expected result (so that we validate both script input and output)
File scriptFile = new File(TEST_ROOT_DIR, "testScript.cmd");
FileUtils.writeStringToFile(scriptFile, "@echo %1 " + expectedResult);
FileUtils.writeStringToFile(scriptFile, "@echo %1 " + expectedResult,
StandardCharsets.UTF_8);
ShellDecryptionKeyProvider provider = new ShellDecryptionKeyProvider();
Configuration conf = new Configuration();

View File

@ -32,6 +32,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
/**
@ -61,7 +62,7 @@ public void save(File dest) throws IOException {
}
*/
public void save(File dest) throws IOException {
FileUtils.writeStringToFile(dest, asString(), Charsets.UTF_8);
FileUtils.writeStringToFile(dest, asString(), StandardCharsets.UTF_8);
}
/**

View File

@ -39,6 +39,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
/**
@ -178,6 +179,6 @@ public static void writeDockerCredentialsToPath(File outConfigFile,
rootNode.put(CONFIG_AUTHS_KEY, registryUrlNode);
String json =
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rootNode);
FileUtils.writeStringToFile(outConfigFile, json, Charset.defaultCharset());
FileUtils.writeStringToFile(outConfigFile, json, StandardCharsets.UTF_8);
}
}

View File

@ -30,6 +30,7 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Random;
import java.util.Vector;
@ -154,7 +155,8 @@ public void testProcessTree() throws Exception {
+ " $(($1-1))\n" + "else\n" + " echo $$ > " + lowestDescendant + "\n"
+ "(sleep 300&\n"
+ "echo $! > " + lostDescendant + ")\n"
+ " while true\n do\n" + " sleep 5\n" + " done\n" + "fi");
+ " while true\n do\n" + " sleep 5\n" + " done\n" + "fi",
StandardCharsets.UTF_8);
Thread t = new RogueTaskThread();
t.start();

View File

@ -26,6 +26,7 @@
import org.junit.Test;
import java.io.File;
import java.nio.charset.StandardCharsets;
import static org.mockito.Mockito.*;
@ -62,7 +63,7 @@ public void testNoMemoryCGgroupMount() throws Exception {
new File(procfs, CGroupsResourceCalculator.CGROUP),
"7:devices:/yarn/container_1\n" +
"6:cpuacct,cpu:/yarn/container_1\n" +
"5:pids:/yarn/container_1\n");
"5:pids:/yarn/container_1\n", StandardCharsets.UTF_8);
CGroupsResourceCalculator calculator =
new CGroupsResourceCalculator(
"1234", basePath,
@ -84,7 +85,7 @@ public void testCGgroupNotFound() throws Exception {
"7:devices:/yarn/container_1\n" +
"6:cpuacct,cpu:/yarn/container_1\n" +
"5:pids:/yarn/container_1\n" +
"4:memory:/yarn/container_1\n");
"4:memory:/yarn/container_1\n", StandardCharsets.UTF_8);
CGroupsResourceCalculator calculator =
new CGroupsResourceCalculator(
@ -118,12 +119,12 @@ public void testCPUParsing() throws Exception {
"7:devices:/yarn/container_1\n" +
"6:cpuacct,cpu:/yarn/container_1\n" +
"5:pids:/yarn/container_1\n" +
"4:memory:/yarn/container_1\n");
"4:memory:/yarn/container_1\n", StandardCharsets.UTF_8);
FileUtils.writeStringToFile(
new File(cgcpuacctContainerDir, CGroupsResourceCalculator.CPU_STAT),
"Can you handle this?\n" +
"user 5415\n" +
"system 3632");
"system 3632", StandardCharsets.UTF_8);
CGroupsResourceCalculator calculator =
new CGroupsResourceCalculator(
"1234", basePath,
@ -159,10 +160,10 @@ public void testMemoryParsing() throws Exception {
FileUtils.writeStringToFile(
new File(procfs, CGroupsResourceCalculator.CGROUP),
"6:cpuacct,cpu:/yarn/container_1\n" +
"4:memory:/yarn/container_1\n");
"4:memory:/yarn/container_1\n", StandardCharsets.UTF_8);
FileUtils.writeStringToFile(
new File(cgMemoryContainerDir, CGroupsResourceCalculator.MEM_STAT),
"418496512\n");
"418496512\n", StandardCharsets.UTF_8);
CGroupsResourceCalculator calculator =
new CGroupsResourceCalculator(
@ -182,7 +183,7 @@ public void testMemoryParsing() throws Exception {
// Test the case where memsw is available
FileUtils.writeStringToFile(
new File(cgMemoryContainerDir, CGroupsResourceCalculator.MEMSW_STAT),
"418496513\n");
"418496513\n", StandardCharsets.UTF_8);
calculator.updateProcessTree();
Assert.assertEquals("Incorrect swap usage",
418496513,
@ -206,7 +207,7 @@ public void testCPUParsingRoot() throws Exception {
FileUtils.writeStringToFile(
new File(cgcpuacctRootDir, CGroupsResourceCalculator.CPU_STAT),
"user 5415\n" +
"system 3632");
"system 3632", StandardCharsets.UTF_8);
CGroupsResourceCalculator calculator =
new CGroupsResourceCalculator(
null, basePath,
@ -241,7 +242,7 @@ public void testMemoryParsingRoot() throws Exception {
try {
FileUtils.writeStringToFile(
new File(cgMemoryRootDir, CGroupsResourceCalculator.MEM_STAT),
"418496512\n");
"418496512\n", StandardCharsets.UTF_8);
CGroupsResourceCalculator calculator =
new CGroupsResourceCalculator(
@ -262,7 +263,7 @@ public void testMemoryParsingRoot() throws Exception {
// Test the case where memsw is available
FileUtils.writeStringToFile(
new File(cgMemoryRootDir, CGroupsResourceCalculator.MEMSW_STAT),
"418496513\n");
"418496513\n", StandardCharsets.UTF_8);
calculator.updateProcessTree();
Assert.assertEquals("Incorrect swap usage",
418496513,