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:
parent
5ff22d4c3a
commit
5e013d50d1
@ -22,7 +22,7 @@
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
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.log.dir", logsDir.getAbsolutePath());
|
||||||
System.setProperty("httpfs.config.dir", confDir.getAbsolutePath());
|
System.setProperty("httpfs.config.dir", confDir.getAbsolutePath());
|
||||||
FileUtils.writeStringToFile(new File(confDir, "httpfs-signature.secret"),
|
FileUtils.writeStringToFile(new File(confDir, "httpfs-signature.secret"),
|
||||||
"foo", Charset.forName("UTF-8"));
|
"foo", StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -284,7 +285,7 @@ public void setOutput(String output) {
|
|||||||
public void createSnapshot(String snapShotName) throws IOException {
|
public void createSnapshot(String snapShotName) throws IOException {
|
||||||
String json = this.toJson();
|
String json = this.toJson();
|
||||||
File outFile = new File(getOutput() + "/" + snapShotName);
|
File outFile = new File(getOutput() + "/" + snapShotName);
|
||||||
FileUtils.writeStringToFile(outFile, json);
|
FileUtils.writeStringToFile(outFile, json, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
import static org.apache.hadoop.test.PlatformAssumptions.assumeWindows;
|
import static org.apache.hadoop.test.PlatformAssumptions.assumeWindows;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
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
|
// Create a simple script which echoes the given key plus the given
|
||||||
// expected result (so that we validate both script input and output)
|
// expected result (so that we validate both script input and output)
|
||||||
File scriptFile = new File(TEST_ROOT_DIR, "testScript.cmd");
|
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();
|
ShellDecryptionKeyProvider provider = new ShellDecryptionKeyProvider();
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,7 +62,7 @@ public void save(File dest) throws IOException {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,6 +179,6 @@ public static void writeDockerCredentialsToPath(File outConfigFile,
|
|||||||
rootNode.put(CONFIG_AUTHS_KEY, registryUrlNode);
|
rootNode.put(CONFIG_AUTHS_KEY, registryUrlNode);
|
||||||
String json =
|
String json =
|
||||||
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rootNode);
|
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rootNode);
|
||||||
FileUtils.writeStringToFile(outConfigFile, json, Charset.defaultCharset());
|
FileUtils.writeStringToFile(outConfigFile, json, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -30,6 +30,7 @@
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
@ -154,7 +155,8 @@ public void testProcessTree() throws Exception {
|
|||||||
+ " $(($1-1))\n" + "else\n" + " echo $$ > " + lowestDescendant + "\n"
|
+ " $(($1-1))\n" + "else\n" + " echo $$ > " + lowestDescendant + "\n"
|
||||||
+ "(sleep 300&\n"
|
+ "(sleep 300&\n"
|
||||||
+ "echo $! > " + lostDescendant + ")\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();
|
Thread t = new RogueTaskThread();
|
||||||
t.start();
|
t.start();
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ public void testNoMemoryCGgroupMount() throws Exception {
|
|||||||
new File(procfs, CGroupsResourceCalculator.CGROUP),
|
new File(procfs, CGroupsResourceCalculator.CGROUP),
|
||||||
"7:devices:/yarn/container_1\n" +
|
"7:devices:/yarn/container_1\n" +
|
||||||
"6:cpuacct,cpu:/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 =
|
CGroupsResourceCalculator calculator =
|
||||||
new CGroupsResourceCalculator(
|
new CGroupsResourceCalculator(
|
||||||
"1234", basePath,
|
"1234", basePath,
|
||||||
@ -84,7 +85,7 @@ public void testCGgroupNotFound() throws Exception {
|
|||||||
"7:devices:/yarn/container_1\n" +
|
"7:devices:/yarn/container_1\n" +
|
||||||
"6:cpuacct,cpu:/yarn/container_1\n" +
|
"6:cpuacct,cpu:/yarn/container_1\n" +
|
||||||
"5:pids:/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 =
|
CGroupsResourceCalculator calculator =
|
||||||
new CGroupsResourceCalculator(
|
new CGroupsResourceCalculator(
|
||||||
@ -118,12 +119,12 @@ public void testCPUParsing() throws Exception {
|
|||||||
"7:devices:/yarn/container_1\n" +
|
"7:devices:/yarn/container_1\n" +
|
||||||
"6:cpuacct,cpu:/yarn/container_1\n" +
|
"6:cpuacct,cpu:/yarn/container_1\n" +
|
||||||
"5:pids:/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(
|
FileUtils.writeStringToFile(
|
||||||
new File(cgcpuacctContainerDir, CGroupsResourceCalculator.CPU_STAT),
|
new File(cgcpuacctContainerDir, CGroupsResourceCalculator.CPU_STAT),
|
||||||
"Can you handle this?\n" +
|
"Can you handle this?\n" +
|
||||||
"user 5415\n" +
|
"user 5415\n" +
|
||||||
"system 3632");
|
"system 3632", StandardCharsets.UTF_8);
|
||||||
CGroupsResourceCalculator calculator =
|
CGroupsResourceCalculator calculator =
|
||||||
new CGroupsResourceCalculator(
|
new CGroupsResourceCalculator(
|
||||||
"1234", basePath,
|
"1234", basePath,
|
||||||
@ -159,10 +160,10 @@ public void testMemoryParsing() throws Exception {
|
|||||||
FileUtils.writeStringToFile(
|
FileUtils.writeStringToFile(
|
||||||
new File(procfs, CGroupsResourceCalculator.CGROUP),
|
new File(procfs, CGroupsResourceCalculator.CGROUP),
|
||||||
"6:cpuacct,cpu:/yarn/container_1\n" +
|
"6:cpuacct,cpu:/yarn/container_1\n" +
|
||||||
"4:memory:/yarn/container_1\n");
|
"4:memory:/yarn/container_1\n", StandardCharsets.UTF_8);
|
||||||
FileUtils.writeStringToFile(
|
FileUtils.writeStringToFile(
|
||||||
new File(cgMemoryContainerDir, CGroupsResourceCalculator.MEM_STAT),
|
new File(cgMemoryContainerDir, CGroupsResourceCalculator.MEM_STAT),
|
||||||
"418496512\n");
|
"418496512\n", StandardCharsets.UTF_8);
|
||||||
|
|
||||||
CGroupsResourceCalculator calculator =
|
CGroupsResourceCalculator calculator =
|
||||||
new CGroupsResourceCalculator(
|
new CGroupsResourceCalculator(
|
||||||
@ -182,7 +183,7 @@ public void testMemoryParsing() throws Exception {
|
|||||||
// Test the case where memsw is available
|
// Test the case where memsw is available
|
||||||
FileUtils.writeStringToFile(
|
FileUtils.writeStringToFile(
|
||||||
new File(cgMemoryContainerDir, CGroupsResourceCalculator.MEMSW_STAT),
|
new File(cgMemoryContainerDir, CGroupsResourceCalculator.MEMSW_STAT),
|
||||||
"418496513\n");
|
"418496513\n", StandardCharsets.UTF_8);
|
||||||
calculator.updateProcessTree();
|
calculator.updateProcessTree();
|
||||||
Assert.assertEquals("Incorrect swap usage",
|
Assert.assertEquals("Incorrect swap usage",
|
||||||
418496513,
|
418496513,
|
||||||
@ -206,7 +207,7 @@ public void testCPUParsingRoot() throws Exception {
|
|||||||
FileUtils.writeStringToFile(
|
FileUtils.writeStringToFile(
|
||||||
new File(cgcpuacctRootDir, CGroupsResourceCalculator.CPU_STAT),
|
new File(cgcpuacctRootDir, CGroupsResourceCalculator.CPU_STAT),
|
||||||
"user 5415\n" +
|
"user 5415\n" +
|
||||||
"system 3632");
|
"system 3632", StandardCharsets.UTF_8);
|
||||||
CGroupsResourceCalculator calculator =
|
CGroupsResourceCalculator calculator =
|
||||||
new CGroupsResourceCalculator(
|
new CGroupsResourceCalculator(
|
||||||
null, basePath,
|
null, basePath,
|
||||||
@ -241,7 +242,7 @@ public void testMemoryParsingRoot() throws Exception {
|
|||||||
try {
|
try {
|
||||||
FileUtils.writeStringToFile(
|
FileUtils.writeStringToFile(
|
||||||
new File(cgMemoryRootDir, CGroupsResourceCalculator.MEM_STAT),
|
new File(cgMemoryRootDir, CGroupsResourceCalculator.MEM_STAT),
|
||||||
"418496512\n");
|
"418496512\n", StandardCharsets.UTF_8);
|
||||||
|
|
||||||
CGroupsResourceCalculator calculator =
|
CGroupsResourceCalculator calculator =
|
||||||
new CGroupsResourceCalculator(
|
new CGroupsResourceCalculator(
|
||||||
@ -262,7 +263,7 @@ public void testMemoryParsingRoot() throws Exception {
|
|||||||
// Test the case where memsw is available
|
// Test the case where memsw is available
|
||||||
FileUtils.writeStringToFile(
|
FileUtils.writeStringToFile(
|
||||||
new File(cgMemoryRootDir, CGroupsResourceCalculator.MEMSW_STAT),
|
new File(cgMemoryRootDir, CGroupsResourceCalculator.MEMSW_STAT),
|
||||||
"418496513\n");
|
"418496513\n", StandardCharsets.UTF_8);
|
||||||
calculator.updateProcessTree();
|
calculator.updateProcessTree();
|
||||||
Assert.assertEquals("Incorrect swap usage",
|
Assert.assertEquals("Incorrect swap usage",
|
||||||
418496513,
|
418496513,
|
||||||
|
Loading…
Reference in New Issue
Block a user