HADOOP-17956. Replace all default Charset usage with UTF-8 (#3529)

Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
This commit is contained in:
Viraj Jasani 2021-10-14 09:37:24 +05:30 committed by GitHub
parent 7279fe8661
commit 1151edf12e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 92 additions and 124 deletions

View File

@ -46,7 +46,7 @@ import java.io.InputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress; import java.net.InetAddress;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
@ -924,7 +924,7 @@ public class KDiag extends Configured implements Tool, Closeable {
*/ */
private void dump(File file) throws IOException { private void dump(File file) throws IOException {
try (InputStream in = Files.newInputStream(file.toPath())) { try (InputStream in = Files.newInputStream(file.toPath())) {
for (String line : IOUtils.readLines(in, Charset.defaultCharset())) { for (String line : IOUtils.readLines(in, StandardCharsets.UTF_8)) {
println("%s", line); println("%s", line);
} }
} }

View File

@ -23,7 +23,7 @@ import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import org.apache.hadoop.classification.VisibleForTesting; import org.apache.hadoop.classification.VisibleForTesting;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -225,8 +225,7 @@ public final class ProviderUtils {
throw new IOException("Password file does not exist"); throw new IOException("Password file does not exist");
} }
try (InputStream is = pwdFile.openStream()) { try (InputStream is = pwdFile.openStream()) {
pass = IOUtils.toString(is, Charset.defaultCharset()).trim() pass = IOUtils.toString(is, StandardCharsets.UTF_8).trim().toCharArray();
.toCharArray();
} }
} }
} }

View File

@ -21,7 +21,6 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.Collections; import java.util.Collections;
@ -223,8 +222,7 @@ public class ShellBasedIdMapping implements IdMappingServiceProvider {
Process process = Runtime.getRuntime().exec( Process process = Runtime.getRuntime().exec(
new String[] { "bash", "-c", command }); new String[] { "bash", "-c", command });
br = new BufferedReader( br = new BufferedReader(
new InputStreamReader(process.getInputStream(), new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8));
Charset.defaultCharset()));
String line = null; String line = null;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] nameId = line.split(regex); String[] nameId = line.split(regex);

View File

@ -29,7 +29,7 @@ import java.lang.management.ThreadMXBean;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
@ -244,7 +244,7 @@ public class ReflectionUtils {
try { try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ByteArrayOutputStream buffer = new ByteArrayOutputStream();
printThreadInfo(new PrintStream(buffer, false, "UTF-8"), title); printThreadInfo(new PrintStream(buffer, false, "UTF-8"), title);
log.info(buffer.toString(Charset.defaultCharset().name())); log.info(buffer.toString(StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException ignored) { } catch (UnsupportedEncodingException ignored) {
} }
} }
@ -273,7 +273,7 @@ public class ReflectionUtils {
try { try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ByteArrayOutputStream buffer = new ByteArrayOutputStream();
printThreadInfo(new PrintStream(buffer, false, "UTF-8"), title); printThreadInfo(new PrintStream(buffer, false, "UTF-8"), title);
log.info(buffer.toString(Charset.defaultCharset().name())); log.info(buffer.toString(StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException ignored) { } catch (UnsupportedEncodingException ignored) {
} }
} }

View File

@ -23,7 +23,7 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@ -949,11 +949,11 @@ public abstract class Shell {
timeOutTimer.schedule(timeoutTimerTask, timeOutInterval); timeOutTimer.schedule(timeoutTimerTask, timeOutInterval);
} }
final BufferedReader errReader = final BufferedReader errReader =
new BufferedReader(new InputStreamReader( new BufferedReader(new InputStreamReader(process.getErrorStream(),
process.getErrorStream(), Charset.defaultCharset())); StandardCharsets.UTF_8));
BufferedReader inReader = BufferedReader inReader =
new BufferedReader(new InputStreamReader( new BufferedReader(new InputStreamReader(process.getInputStream(),
process.getInputStream(), Charset.defaultCharset())); StandardCharsets.UTF_8));
final StringBuffer errMsg = new StringBuffer(); final StringBuffer errMsg = new StringBuffer();
// read error and input streams as this would free up the buffers // read error and input streams as this would free up the buffers

View File

@ -27,7 +27,7 @@ import java.io.InputStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -125,7 +125,7 @@ public class TestTextCommand {
private String inputStreamToString(InputStream stream) throws IOException { private String inputStreamToString(InputStream stream) throws IOException {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
IOUtils.copy(stream, writer, Charset.defaultCharset()); IOUtils.copy(stream, writer, StandardCharsets.UTF_8);
return writer.toString(); return writer.toString();
} }

View File

@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -236,7 +236,7 @@ public class TestKDiag extends Assert {
*/ */
private void dump(File file) throws IOException { private void dump(File file) throws IOException {
try (FileInputStream in = new FileInputStream(file)) { try (FileInputStream in = new FileInputStream(file)) {
for (String line : IOUtils.readLines(in, Charset.defaultCharset())) { for (String line : IOUtils.readLines(in, StandardCharsets.UTF_8)) {
LOG.info(line); LOG.info(line);
} }
} }

View File

@ -64,7 +64,7 @@ import java.io.IOException;
import java.io.Writer; import java.io.Writer;
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.security.Principal; import java.security.Principal;
import java.security.PrivilegedActionException; import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
@ -555,8 +555,7 @@ public class TestWebDelegationToken {
HttpURLConnection conn = aUrl.openConnection(url, token); HttpURLConnection conn = aUrl.openConnection(url, token);
Assert.assertEquals(HttpURLConnection.HTTP_OK, Assert.assertEquals(HttpURLConnection.HTTP_OK,
conn.getResponseCode()); conn.getResponseCode());
List<String> ret = IOUtils.readLines(conn.getInputStream(), List<String> ret = IOUtils.readLines(conn.getInputStream(), StandardCharsets.UTF_8);
Charset.defaultCharset());
Assert.assertEquals(1, ret.size()); Assert.assertEquals(1, ret.size());
Assert.assertEquals(FOO_USER, ret.get(0)); Assert.assertEquals(FOO_USER, ret.get(0));
@ -626,8 +625,7 @@ public class TestWebDelegationToken {
HttpURLConnection conn = aUrl.openConnection(url, token); HttpURLConnection conn = aUrl.openConnection(url, token);
Assert.assertEquals(HttpURLConnection.HTTP_OK, Assert.assertEquals(HttpURLConnection.HTTP_OK,
conn.getResponseCode()); conn.getResponseCode());
List<String> ret = IOUtils List<String> ret = IOUtils.readLines(conn.getInputStream(), StandardCharsets.UTF_8);
.readLines(conn.getInputStream(), Charset.defaultCharset());
Assert.assertEquals(1, ret.size()); Assert.assertEquals(1, ret.size());
Assert.assertEquals(FOO_USER, ret.get(0)); Assert.assertEquals(FOO_USER, ret.get(0));
@ -851,15 +849,14 @@ public class TestWebDelegationToken {
HttpURLConnection conn = HttpURLConnection conn =
(HttpURLConnection) new URL(strUrl).openConnection(); (HttpURLConnection) new URL(strUrl).openConnection();
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
List<String> ret = List<String> ret = IOUtils.readLines(conn.getInputStream(), StandardCharsets.UTF_8);
IOUtils.readLines(conn.getInputStream(), Charset.defaultCharset());
Assert.assertEquals(1, ret.size()); Assert.assertEquals(1, ret.size());
Assert.assertEquals(OK_USER, ret.get(0)); Assert.assertEquals(OK_USER, ret.get(0));
strUrl = String.format("%s?user.name=%s&DOAS=%s", url.toExternalForm(), strUrl = String.format("%s?user.name=%s&DOAS=%s", url.toExternalForm(),
FOO_USER, OK_USER); FOO_USER, OK_USER);
conn = (HttpURLConnection) new URL(strUrl).openConnection(); conn = (HttpURLConnection) new URL(strUrl).openConnection();
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
ret = IOUtils.readLines(conn.getInputStream(), Charset.defaultCharset()); ret = IOUtils.readLines(conn.getInputStream(), StandardCharsets.UTF_8);
Assert.assertEquals(1, ret.size()); Assert.assertEquals(1, ret.size());
Assert.assertEquals(OK_USER, ret.get(0)); Assert.assertEquals(OK_USER, ret.get(0));
@ -877,7 +874,7 @@ public class TestWebDelegationToken {
Assert.assertEquals(HttpURLConnection.HTTP_OK, Assert.assertEquals(HttpURLConnection.HTTP_OK,
conn.getResponseCode()); conn.getResponseCode());
List<String> ret = IOUtils List<String> ret = IOUtils
.readLines(conn.getInputStream(), Charset.defaultCharset()); .readLines(conn.getInputStream(), StandardCharsets.UTF_8);
Assert.assertEquals(1, ret.size()); Assert.assertEquals(1, ret.size());
Assert.assertEquals(OK_USER, ret.get(0)); Assert.assertEquals(OK_USER, ret.get(0));
@ -898,7 +895,7 @@ public class TestWebDelegationToken {
Assert.assertEquals(HttpURLConnection.HTTP_OK, Assert.assertEquals(HttpURLConnection.HTTP_OK,
conn.getResponseCode()); conn.getResponseCode());
ret = IOUtils ret = IOUtils
.readLines(conn.getInputStream(), Charset.defaultCharset()); .readLines(conn.getInputStream(), StandardCharsets.UTF_8);
Assert.assertEquals(1, ret.size()); Assert.assertEquals(1, ret.size());
Assert.assertEquals(FOO_USER, ret.get(0)); Assert.assertEquals(FOO_USER, ret.get(0));
@ -960,7 +957,7 @@ public class TestWebDelegationToken {
Assert.assertEquals(HttpURLConnection.HTTP_OK, Assert.assertEquals(HttpURLConnection.HTTP_OK,
conn.getResponseCode()); conn.getResponseCode());
List<String> ret = IOUtils List<String> ret = IOUtils
.readLines(conn.getInputStream(), Charset.defaultCharset()); .readLines(conn.getInputStream(), StandardCharsets.UTF_8);
Assert.assertEquals(1, ret.size()); Assert.assertEquals(1, ret.size());
Assert.assertEquals("remoteuser=" + FOO_USER+ ":ugi=" + FOO_USER, Assert.assertEquals("remoteuser=" + FOO_USER+ ":ugi=" + FOO_USER,
ret.get(0)); ret.get(0));
@ -969,8 +966,7 @@ public class TestWebDelegationToken {
conn = aUrl.openConnection(url, token, OK_USER); conn = aUrl.openConnection(url, token, OK_USER);
Assert.assertEquals(HttpURLConnection.HTTP_OK, Assert.assertEquals(HttpURLConnection.HTTP_OK,
conn.getResponseCode()); conn.getResponseCode());
ret = IOUtils ret = IOUtils.readLines(conn.getInputStream(), StandardCharsets.UTF_8);
.readLines(conn.getInputStream(), Charset.defaultCharset());
Assert.assertEquals(1, ret.size()); Assert.assertEquals(1, ret.size());
Assert.assertEquals("realugi=" + FOO_USER +":remoteuser=" + OK_USER + Assert.assertEquals("realugi=" + FOO_USER +":remoteuser=" + OK_USER +
":ugi=" + OK_USER, ret.get(0)); ":ugi=" + OK_USER, ret.get(0));
@ -1022,8 +1018,7 @@ public class TestWebDelegationToken {
HttpURLConnection conn = aUrl.openConnection(url, token, OK_USER); HttpURLConnection conn = aUrl.openConnection(url, token, OK_USER);
Assert.assertEquals(HttpURLConnection.HTTP_OK, Assert.assertEquals(HttpURLConnection.HTTP_OK,
conn.getResponseCode()); conn.getResponseCode());
List<String> ret = IOUtils List<String> ret = IOUtils.readLines(conn.getInputStream(), StandardCharsets.UTF_8);
.readLines(conn.getInputStream(), Charset.defaultCharset());
Assert.assertEquals(1, ret.size()); Assert.assertEquals(1, ret.size());
Assert.assertEquals("realugi=" + FOO_USER +":remoteuser=" + OK_USER + Assert.assertEquals("realugi=" + FOO_USER +":remoteuser=" + OK_USER +
":ugi=" + OK_USER, ret.get(0)); ":ugi=" + OK_USER, ret.get(0));

View File

@ -22,7 +22,7 @@ import org.apache.hadoop.util.Shell;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -113,10 +113,9 @@ public class StatUtils {
ExecutorService executorService = Executors.newSingleThreadExecutor(); ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.awaitTermination(2000, TimeUnit.MILLISECONDS); executorService.awaitTermination(2000, TimeUnit.MILLISECONDS);
try { try {
Future<String> future = Future<String> future = executorService.submit(() -> new BufferedReader(
executorService.submit(() -> new BufferedReader( new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)).lines()
new InputStreamReader(process.getInputStream(), .findFirst().orElse(""));
Charset.defaultCharset())).lines().findFirst().orElse(""));
return future.get(); return future.get();
} finally { } finally {
process.destroy(); process.destroy();

View File

@ -31,7 +31,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
@ -135,7 +135,7 @@ public class TestApplicationClassLoader {
InputStream in = appClassloader.getResourceAsStream("resource.txt"); InputStream in = appClassloader.getResourceAsStream("resource.txt");
assertNotNull("Resource should not be null for app classloader", in); assertNotNull("Resource should not be null for app classloader", in);
assertEquals("hello", IOUtils.toString(in, Charset.defaultCharset())); assertEquals("hello", IOUtils.toString(in, StandardCharsets.UTF_8));
} }
private File makeTestJar() throws IOException { private File makeTestJar() throws IOException {

View File

@ -49,7 +49,7 @@ import javax.security.auth.login.LoginException;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.security.Principal; import java.security.Principal;
import java.util.HashSet; import java.util.HashSet;
import java.util.Properties; import java.util.Properties;
@ -220,7 +220,7 @@ public class AbstractSecureRegistryTest extends RegistryTestHelper {
BOB_LOCALHOST, keytab_bob)); BOB_LOCALHOST, keytab_bob));
jaasFile = new File(kdcWorkDir, "jaas.txt"); jaasFile = new File(kdcWorkDir, "jaas.txt");
FileUtils.write(jaasFile, jaas.toString(), Charset.defaultCharset()); FileUtils.write(jaasFile, jaas.toString(), StandardCharsets.UTF_8);
LOG.info("\n"+ jaas); LOG.info("\n"+ jaas);
RegistrySecurity.bindJVMtoJAASFile(jaasFile); RegistrySecurity.bindJVMtoJAASFile(jaasFile);
} }

View File

@ -20,7 +20,7 @@ package org.apache.hadoop.registry.secure;
import java.io.File; import java.io.File;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.security.Principal; import java.security.Principal;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.util.HashMap; import java.util.HashMap;
@ -93,8 +93,7 @@ public class TestSecureLogins extends AbstractSecureRegistryTest {
logLoginDetails(ALICE_LOCALHOST, client); logLoginDetails(ALICE_LOCALHOST, client);
String confFilename = System.getProperty(Environment.JAAS_CONF_KEY); String confFilename = System.getProperty(Environment.JAAS_CONF_KEY);
assertNotNull("Unset: "+ Environment.JAAS_CONF_KEY, confFilename); assertNotNull("Unset: "+ Environment.JAAS_CONF_KEY, confFilename);
String config = FileUtils.readFileToString(new File(confFilename), String config = FileUtils.readFileToString(new File(confFilename), StandardCharsets.UTF_8);
Charset.defaultCharset());
LOG.info("{}=\n{}", confFilename, config); LOG.info("{}=\n{}", confFilename, config);
RegistrySecurity.setZKSaslClientProperties(ALICE, ALICE_CLIENT_CONTEXT); RegistrySecurity.setZKSaslClientProperties(ALICE, ALICE_CLIENT_CONTEXT);
} finally { } finally {
@ -133,8 +132,7 @@ public class TestSecureLogins extends AbstractSecureRegistryTest {
@Test @Test
public void testKerberosAuth() throws Throwable { public void testKerberosAuth() throws Throwable {
File krb5conf = getKdc().getKrb5conf(); File krb5conf = getKdc().getKrb5conf();
String krbConfig = FileUtils.readFileToString(krb5conf, String krbConfig = FileUtils.readFileToString(krb5conf, StandardCharsets.UTF_8);
Charset.defaultCharset());
LOG.info("krb5.conf at {}:\n{}", krb5conf, krbConfig); LOG.info("krb5.conf at {}:\n{}", krb5conf, krbConfig);
Subject subject = new Subject(); Subject subject = new Subject();
Class<?> kerb5LoginClass = Class<?> kerb5LoginClass =

View File

@ -57,7 +57,7 @@ import java.io.Writer;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URI; import java.net.URI;
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 java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -1711,8 +1711,7 @@ public class TestHttpFSServer extends HFSTestCase {
conn.connect(); conn.connect();
// Verify that we read what we wrote // Verify that we read what we wrote
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode()); Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
String content = IOUtils.toString( String content = IOUtils.toString(conn.getInputStream(), StandardCharsets.UTF_8);
conn.getInputStream(), Charset.defaultCharset());
Assert.assertEquals(testContent, content); Assert.assertEquals(testContent, content);

View File

@ -32,7 +32,7 @@ import org.apache.hadoop.hdfs.server.diskbalancer.planner.NodePlan;
import org.apache.hadoop.hdfs.tools.DiskBalancerCLI; import org.apache.hadoop.hdfs.tools.DiskBalancerCLI;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
/** /**
* Cancels a running plan. * Cancels a running plan.
@ -77,7 +77,7 @@ public class CancelCommand extends Command {
"Invalid plan file specified."); "Invalid plan file specified.");
String planData = null; String planData = null;
try (FSDataInputStream plan = open(planFile)) { try (FSDataInputStream plan = open(planFile)) {
planData = IOUtils.toString(plan, Charset.defaultCharset()); planData = IOUtils.toString(plan, StandardCharsets.UTF_8);
} }
cancelPlan(planData); cancelPlan(planData);
} }

View File

@ -32,7 +32,7 @@ import org.apache.hadoop.hdfs.server.diskbalancer.planner.NodePlan;
import org.apache.hadoop.hdfs.tools.DiskBalancerCLI; import org.apache.hadoop.hdfs.tools.DiskBalancerCLI;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
/** /**
* executes a given plan. * executes a given plan.
@ -69,7 +69,7 @@ public class ExecuteCommand extends Command {
String planData = null; String planData = null;
try (FSDataInputStream plan = open(planFile)) { try (FSDataInputStream plan = open(planFile)) {
planData = IOUtils.toString(plan, Charset.defaultCharset()); planData = IOUtils.toString(plan, StandardCharsets.UTF_8);
} }
boolean skipDateCheck = false; boolean skipDateCheck = false;

View File

@ -25,7 +25,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -107,7 +107,7 @@ public class TestHdfsTextCommand {
private String inputStreamToString(InputStream stream) throws IOException { private String inputStreamToString(InputStream stream) throws IOException {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
IOUtils.copy(stream, writer, Charset.defaultCharset()); IOUtils.copy(stream, writer, StandardCharsets.UTF_8);
return writer.toString(); return writer.toString();
} }

View File

@ -25,7 +25,7 @@ import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -126,8 +126,7 @@ public class TestOfflineImageViewerForXAttr {
assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
String content = IOUtils String content = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);
.toString(connection.getInputStream(), Charset.defaultCharset());
assertTrue("Missing user.attr1 in response ", assertTrue("Missing user.attr1 in response ",
content.contains("user.attr1")); content.contains("user.attr1"));
@ -152,8 +151,7 @@ public class TestOfflineImageViewerForXAttr {
connection.connect(); connection.connect();
assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
String content = IOUtils String content = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);
.toString(connection.getInputStream(), Charset.defaultCharset());
assertTrue("Missing user.attr1 in response ", assertTrue("Missing user.attr1 in response ",
content.contains("user.attr1")); content.contains("user.attr1"));
@ -186,8 +184,7 @@ public class TestOfflineImageViewerForXAttr {
connection.connect(); connection.connect();
assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
String content = IOUtils String content = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);
.toString(connection.getInputStream(), Charset.defaultCharset());
assertEquals(attr1JSon, content); assertEquals(attr1JSon, content);
} }
} }
@ -209,8 +206,7 @@ public class TestOfflineImageViewerForXAttr {
connection.connect(); connection.connect();
assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
String content = IOUtils String content = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);
.toString(connection.getInputStream(), Charset.defaultCharset());
assertEquals(attr1JSon, content); assertEquals(attr1JSon, content);
} }

View File

@ -48,7 +48,6 @@ import java.net.SocketTimeoutException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.util.Arrays; import java.util.Arrays;
@ -1554,7 +1553,7 @@ public class TestWebHDFS {
conn.setRequestMethod(TYPE); conn.setRequestMethod(TYPE);
conn.setInstanceFollowRedirects(false); conn.setInstanceFollowRedirects(false);
String response = String response =
IOUtils.toString(conn.getInputStream(), Charset.defaultCharset()); IOUtils.toString(conn.getInputStream(), StandardCharsets.UTF_8);
LOG.info("Response was : " + response); LOG.info("Response was : " + response);
Assert.assertEquals( Assert.assertEquals(
"Response wasn't " + HttpURLConnection.HTTP_OK, "Response wasn't " + HttpURLConnection.HTTP_OK,

View File

@ -23,7 +23,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.Iterator; import java.util.Iterator;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@ -135,8 +135,7 @@ public class TestJavaSerialization {
new Utils.OutputFileUtils.OutputFilesFilter())); new Utils.OutputFileUtils.OutputFilesFilter()));
assertEquals(1, outputFiles.length); assertEquals(1, outputFiles.length);
try (InputStream is = fs.open(outputFiles[0])) { try (InputStream is = fs.open(outputFiles[0])) {
String reduceOutput = String reduceOutput = org.apache.commons.io.IOUtils.toString(is, StandardCharsets.UTF_8);
org.apache.commons.io.IOUtils.toString(is, Charset.defaultCharset());
String[] lines = reduceOutput.split("\n"); String[] lines = reduceOutput.split("\n");
assertEquals("Unexpected output; received output '" + reduceOutput + "'", assertEquals("Unexpected output; received output '" + reduceOutput + "'",
"a\t1", lines[0]); "a\t1", lines[0]);

View File

@ -44,7 +44,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.HashMap; import java.util.HashMap;
@ -437,8 +437,7 @@ public class TestFrameworkUploader {
// Create a target file // Create a target file
File targetFile = new File(parent, "a.txt"); File targetFile = new File(parent, "a.txt");
try(FileOutputStream os = new FileOutputStream(targetFile)) { try(FileOutputStream os = new FileOutputStream(targetFile)) {
IOUtils.writeLines(Lists.newArrayList("a", "b"), null, os, IOUtils.writeLines(Lists.newArrayList("a", "b"), null, os, StandardCharsets.UTF_8);
Charset.defaultCharset());
} }
Assert.assertFalse(uploader.checkSymlink(targetFile)); Assert.assertFalse(uploader.checkSymlink(targetFile));

View File

@ -24,7 +24,7 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays; import java.util.Arrays;
@ -114,7 +114,7 @@ public class ResourceGzMojo extends AbstractMojo {
BufferedReader is = Files.newBufferedReader(path) BufferedReader is = Files.newBufferedReader(path)
) { ) {
getLog().info("Compressing " + path + " to " + outFile); getLog().info("Compressing " + path + " to " + outFile);
IOUtils.copy(is, os, Charset.defaultCharset()); IOUtils.copy(is, os, StandardCharsets.UTF_8);
} }
} else { } else {
throw new IOException("Directory " + outFile.getParent() throw new IOException("Directory " + outFile.getParent()

View File

@ -42,7 +42,7 @@ import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.Random; import java.util.Random;
public class TestHadoopArchiveLogs { public class TestHadoopArchiveLogs {
@ -279,8 +279,7 @@ public class TestHadoopArchiveLogs {
Assert.assertFalse(localScript.exists()); Assert.assertFalse(localScript.exists());
hal.generateScript(localScript); hal.generateScript(localScript);
Assert.assertTrue(localScript.exists()); Assert.assertTrue(localScript.exists());
String script = String script = IOUtils.toString(localScript.toURI(), StandardCharsets.UTF_8);
IOUtils.toString(localScript.toURI(), Charset.defaultCharset());
String[] lines = script.split("\n"); String[] lines = script.split("\n");
Assert.assertEquals(22, lines.length); Assert.assertEquals(22, lines.length);
Assert.assertEquals("#!/bin/bash", lines[0]); Assert.assertEquals("#!/bin/bash", lines[0]);

View File

@ -21,7 +21,7 @@ package org.apache.hadoop.fs.s3a;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
import java.io.IOException; import java.io.IOException;
import java.net.SocketException; import java.net.SocketException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import com.amazonaws.SdkClientException; import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.model.GetObjectRequest; import com.amazonaws.services.s3.model.GetObjectRequest;
@ -200,8 +200,7 @@ public class TestS3AInputStreamRetry extends AbstractS3AMockTest {
* @return mocked object. * @return mocked object.
*/ */
private S3ObjectInputStream getMockedInputStream(boolean triggerFailure) { private S3ObjectInputStream getMockedInputStream(boolean triggerFailure) {
return new S3ObjectInputStream( return new S3ObjectInputStream(IOUtils.toInputStream(INPUT, StandardCharsets.UTF_8), null) {
IOUtils.toInputStream(INPUT, Charset.defaultCharset()), null) {
private final IOException exception = private final IOException exception =
new SSLException(new SocketException("Connection reset")); new SSLException(new SocketException("Connection reset"));

View File

@ -22,7 +22,7 @@ import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import org.junit.Assume; import org.junit.Assume;
@ -168,8 +168,7 @@ public class ITestS3SelectCLI extends AbstractS3SelectTest {
o(OPT_OUTPUT), localFile.toString(), o(OPT_OUTPUT), localFile.toString(),
landsatSrc, landsatSrc,
SELECT_SUNNY_ROWS_NO_LIMIT); SELECT_SUNNY_ROWS_NO_LIMIT);
List<String> lines = IOUtils.readLines(new FileInputStream(localFile), List<String> lines = IOUtils.readLines(new FileInputStream(localFile), StandardCharsets.UTF_8);
Charset.defaultCharset());
LOG.info("Result from select:\n{}", lines.get(0)); LOG.info("Result from select:\n{}", lines.get(0));
assertEquals(lineCount, lines.size()); assertEquals(lineCount, lines.size());
selectCount.assertDiffEquals("select count", 1); selectCount.assertDiffEquals("select count", 1);

View File

@ -97,7 +97,7 @@ import java.net.InetSocketAddress;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -549,7 +549,7 @@ public class ServiceScheduler extends CompositeService {
case TEMPLATE: case TEMPLATE:
try (FSDataInputStream fileInput = fileSystem try (FSDataInputStream fileInput = fileSystem
.open(new Path(key.getSrcFile()))) { .open(new Path(key.getSrcFile()))) {
return IOUtils.toString(fileInput, Charset.defaultCharset()); return IOUtils.toString(fileInput, StandardCharsets.UTF_8);
} }
default: default:
return null; return null;

View File

@ -48,7 +48,7 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -466,8 +466,7 @@ public class ProviderUtils implements YarnServiceConstants {
content = substituteStrWithTokens(content, tokensForSubstitution); content = substituteStrWithTokens(content, tokensForSubstitution);
try (OutputStream output = fs.create(remoteFile)) { try (OutputStream output = fs.create(remoteFile)) {
org.apache.commons.io.IOUtils org.apache.commons.io.IOUtils.write(content, output, StandardCharsets.UTF_8);
.write(content, output, Charset.defaultCharset());
} catch (IOException e) { } catch (IOException e) {
log.info("Failed to create " + remoteFile); log.info("Failed to create " + remoteFile);
} }

View File

@ -87,7 +87,7 @@ public final class DockerClientConfigHandler {
if (fs != null) { if (fs != null) {
FSDataInputStream fileHandle = fs.open(configFile); FSDataInputStream fileHandle = fs.open(configFile);
if (fileHandle != null) { if (fileHandle != null) {
contents = IOUtils.toString(fileHandle, Charset.defaultCharset()); contents = IOUtils.toString(fileHandle, StandardCharsets.UTF_8);
} }
} }
if (contents == null) { if (contents == null) {

View File

@ -19,7 +19,7 @@
package org.apache.hadoop.yarn.server.federation.resolver; package org.apache.hadoop.yarn.server.federation.resolver;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;
import java.nio.file.Path; import java.nio.file.Path;
@ -107,7 +107,7 @@ public class DefaultSubClusterResolverImpl extends AbstractSubClusterResolver
} }
try { try {
reader = Files.newBufferedReader(file, Charset.defaultCharset()); reader = Files.newBufferedReader(file, StandardCharsets.UTF_8);
String line = null; String line = null;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
String[] tokens = line.split(","); String[] tokens = line.split(",");

View File

@ -54,7 +54,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.StreamingOutput; import javax.ws.rs.core.StreamingOutput;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -420,7 +420,7 @@ public class LogServlet extends Configured {
private static StreamingOutput createEmptyStream() { private static StreamingOutput createEmptyStream() {
return outputStream -> outputStream.write( return outputStream -> outputStream.write(
"".getBytes(Charset.defaultCharset())); "".getBytes(StandardCharsets.UTF_8));
} }
/** /**

View File

@ -24,7 +24,7 @@ import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -350,8 +350,7 @@ public abstract class ContainerExecutor implements Configurable {
} }
try { try {
return Integer.parseInt( return Integer.parseInt(FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim());
FileUtils.readFileToString(file, Charset.defaultCharset()).trim());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new IOException("Error parsing exit code from pid " + pid, e); throw new IOException("Error parsing exit code from pid " + pid, e);
} }

View File

@ -34,7 +34,7 @@ import org.apache.hadoop.yarn.util.MonotonicClock;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@ -269,9 +269,8 @@ public class CGroupElasticMemoryController extends Thread {
// Listen to any errors in the background. We do not expect this to // Listen to any errors in the background. We do not expect this to
// be large in size, so it will fit into a string. // be large in size, so it will fit into a string.
Future<String> errorListener = executor.submit( Future<String> errorListener =
() -> IOUtils.toString(process.getErrorStream(), executor.submit(() -> IOUtils.toString(process.getErrorStream(), StandardCharsets.UTF_8));
Charset.defaultCharset()));
// We get Linux event increments (8 bytes) forwarded from the event stream // We get Linux event increments (8 bytes) forwarded from the event stream
// The events cannot be split, so it is safe to read them as a whole // The events cannot be split, so it is safe to read them as a whole

View File

@ -20,7 +20,7 @@ package org.apache.hadoop.yarn.server.nodemanager;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
@ -270,16 +270,14 @@ public class TestContainerExecutor {
try { try {
int writtenExitCode = 10; int writtenExitCode = 10;
FileUtils.writeStringToFile(pidFile, "2992", FileUtils.writeStringToFile(pidFile, "2992", StandardCharsets.UTF_8, false);
Charset.defaultCharset(), false);
TimerTask task = new java.util.TimerTask() { TimerTask task = new java.util.TimerTask() {
@Override @Override
public void run() { public void run() {
try { try {
FileUtils.writeStringToFile(exitCodeFile, FileUtils.writeStringToFile(exitCodeFile, Integer.toString(writtenExitCode),
Integer.toString(writtenExitCode), StandardCharsets.UTF_8, false);
Charset.defaultCharset(), false);
} catch (IOException ioe) { } catch (IOException ioe) {
LOG.warn("Could not write pid file"); LOG.warn("Could not write pid file");
} }

View File

@ -26,7 +26,7 @@ import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -97,8 +97,7 @@ public class TestCGroupElasticMemoryController {
script.getAbsolutePath()); script.getAbsolutePath());
try { try {
FileUtils.writeStringToFile(script, FileUtils.writeStringToFile(script,
"#!/bin/bash\nprintf oomevent;printf oomevent;\n", "#!/bin/bash\nprintf oomevent;printf oomevent;\n", StandardCharsets.UTF_8, false);
Charset.defaultCharset(), false);
assertTrue("Could not set executable", assertTrue("Could not set executable",
script.setExecutable(true)); script.setExecutable(true));
@ -138,9 +137,8 @@ public class TestCGroupElasticMemoryController {
conf.set(YarnConfiguration.NM_ELASTIC_MEMORY_CONTROL_OOM_LISTENER_PATH, conf.set(YarnConfiguration.NM_ELASTIC_MEMORY_CONTROL_OOM_LISTENER_PATH,
script.getAbsolutePath()); script.getAbsolutePath());
try { try {
FileUtils.writeStringToFile(script, FileUtils.writeStringToFile(script, "#!/bin/bash\nprintf oomevent;printf oomevent;\n",
"#!/bin/bash\nprintf oomevent;printf oomevent;\n", StandardCharsets.UTF_8, false);
Charset.defaultCharset(), false);
assertTrue("Could not set executable", assertTrue("Could not set executable",
script.setExecutable(true)); script.setExecutable(true));
@ -181,9 +179,8 @@ public class TestCGroupElasticMemoryController {
script.getAbsolutePath()); script.getAbsolutePath());
Runnable handler = mock(Runnable.class); Runnable handler = mock(Runnable.class);
try { try {
FileUtils.writeStringToFile(script, FileUtils.writeStringToFile(script, "#!/bin/bash\nprintf oomevent;sleep 1000;\n",
"#!/bin/bash\nprintf oomevent;sleep 1000;\n", StandardCharsets.UTF_8, false);
Charset.defaultCharset(), false);
assertTrue("Could not set executable", assertTrue("Could not set executable",
script.setExecutable(true)); script.setExecutable(true));
@ -223,9 +220,8 @@ public class TestCGroupElasticMemoryController {
script.getAbsolutePath()); script.getAbsolutePath());
Runnable handler = mock(Runnable.class); Runnable handler = mock(Runnable.class);
try { try {
FileUtils.writeStringToFile(script, FileUtils.writeStringToFile(script, "#!/bin/bash\nprintf oomevent;sleep 1000;\n",
"#!/bin/bash\nprintf oomevent;sleep 1000;\n", StandardCharsets.UTF_8, false);
Charset.defaultCharset(), false);
assertTrue("Could not set executable", assertTrue("Could not set executable",
script.setExecutable(true)); script.setExecutable(true));

View File

@ -31,7 +31,7 @@ import org.w3c.dom.Element;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -194,8 +194,7 @@ public class TestPlacementRuleFS {
Document doc = null; Document doc = null;
try { try {
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
doc = builder.parse(IOUtils.toInputStream(str, doc = builder.parse(IOUtils.toInputStream(str, StandardCharsets.UTF_8));
Charset.defaultCharset()));
} catch (Exception ex) { } catch (Exception ex) {
fail("Element creation failed, failing test"); fail("Element creation failed, failing test");
} }