Skip to content

Commit ce004d2

Browse files
pjfanningjiajunmao
authored andcommitted
HADOOP-18957. Use StandardCharsets.UTF_8 (apache#6231). Contributed by PJ Fanning.
Signed-off-by: Ayush Saxena <[email protected]>
1 parent b18870e commit ce004d2

File tree

224 files changed

+671
-669
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+671
-669
lines changed

hadoop-common-project/hadoop-auth-examples/src/main/java/org/apache/hadoop/security/authentication/examples/WhoClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.io.InputStreamReader;
2020
import java.net.HttpURLConnection;
2121
import java.net.URL;
22-
import java.nio.charset.Charset;
22+
import java.nio.charset.StandardCharsets;
2323

2424
/**
2525
* Example that uses <code>AuthenticatedURL</code>.
@@ -42,7 +42,7 @@ public static void main(String[] args) {
4242
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
4343
BufferedReader reader = new BufferedReader(
4444
new InputStreamReader(
45-
conn.getInputStream(), Charset.forName("UTF-8")));
45+
conn.getInputStream(), StandardCharsets.UTF_8));
4646
String line = reader.readLine();
4747
while (line != null) {
4848
System.out.println(line);

hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/PseudoAuthenticationHandler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import javax.servlet.http.HttpServletResponse;
2424

2525
import java.io.IOException;
26-
import java.nio.charset.Charset;
26+
import java.nio.charset.StandardCharsets;
2727
import java.util.List;
2828
import java.util.Properties;
2929

@@ -53,8 +53,6 @@ public class PseudoAuthenticationHandler implements AuthenticationHandler {
5353
*/
5454
public static final String ANONYMOUS_ALLOWED = TYPE + ".anonymous.allowed";
5555

56-
private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
57-
5856
private static final String PSEUDO_AUTH = "PseudoAuth";
5957

6058
private boolean acceptAnonymous;
@@ -146,7 +144,7 @@ private String getUserName(HttpServletRequest request) {
146144
if(queryString == null || queryString.length() == 0) {
147145
return null;
148146
}
149-
List<NameValuePair> list = URLEncodedUtils.parse(queryString, UTF8_CHARSET);
147+
List<NameValuePair> list = URLEncodedUtils.parse(queryString, StandardCharsets.UTF_8);
150148
if (list != null) {
151149
for (NameValuePair nv : list) {
152150
if (PseudoAuthenticator.USER_NAME.equals(nv.getName())) {

hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/util/StringSignerSecretProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
package org.apache.hadoop.security.authentication.util;
1515

16-
import java.nio.charset.Charset;
16+
import java.nio.charset.StandardCharsets;
1717
import java.util.Properties;
1818
import javax.servlet.ServletContext;
1919

@@ -38,7 +38,7 @@ public void init(Properties config, ServletContext servletContext,
3838
long tokenValidity) throws Exception {
3939
String signatureSecret = config.getProperty(
4040
AuthenticationFilter.SIGNATURE_SECRET, null);
41-
secret = signatureSecret.getBytes(Charset.forName("UTF-8"));
41+
secret = signatureSecret.getBytes(StandardCharsets.UTF_8);
4242
secrets = new byte[][]{secret};
4343
}
4444

hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/util/TestZKSignerSecretProvider.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
package org.apache.hadoop.security.authentication.util;
1515

16-
import java.nio.charset.Charset;
16+
import java.nio.charset.StandardCharsets;
1717
import java.util.Properties;
1818
import java.util.Random;
1919
import javax.servlet.ServletContext;
@@ -140,11 +140,11 @@ public void testUpgradeChangeSecretLength() throws Exception {
140140
long seed = System.currentTimeMillis();
141141
Random rand = new Random(seed);
142142
byte[] secret2 = Long.toString(rand.nextLong())
143-
.getBytes(Charset.forName("UTF-8"));
143+
.getBytes(StandardCharsets.UTF_8);
144144
byte[] secret1 = Long.toString(rand.nextLong())
145-
.getBytes(Charset.forName("UTF-8"));
145+
.getBytes(StandardCharsets.UTF_8);
146146
byte[] secret3 = Long.toString(rand.nextLong())
147-
.getBytes(Charset.forName("UTF-8"));
147+
.getBytes(StandardCharsets.UTF_8);
148148
rand = new Random(seed);
149149
// Secrets 4 and 5 get thrown away by ZK when the new secret provider tries
150150
// to init
@@ -238,7 +238,7 @@ private class OldMockZKSignerSecretProvider
238238

239239
@Override
240240
protected byte[] generateRandomSecret() {
241-
return Long.toString(rand.nextLong()).getBytes(Charset.forName("UTF-8"));
241+
return Long.toString(rand.nextLong()).getBytes(StandardCharsets.UTF_8);
242242
}
243243
}
244244

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.net.URISyntaxException;
4444
import java.net.URL;
4545
import java.net.URLConnection;
46+
import java.nio.charset.StandardCharsets;
4647
import java.nio.file.Files;
4748
import java.util.ArrayList;
4849
import java.util.Arrays;
@@ -82,7 +83,6 @@
8283
import javax.xml.transform.dom.DOMSource;
8384
import javax.xml.transform.stream.StreamResult;
8485

85-
import org.apache.hadoop.thirdparty.com.google.common.base.Charsets;
8686
import org.apache.commons.collections.map.UnmodifiableMap;
8787
import org.apache.hadoop.classification.InterfaceAudience;
8888
import org.apache.hadoop.classification.InterfaceStability;
@@ -2903,7 +2903,7 @@ public Reader getConfResourceAsReader(String name) {
29032903
LOG.info("found resource " + name + " at " + url);
29042904
}
29052905

2906-
return new InputStreamReader(url.openStream(), Charsets.UTF_8);
2906+
return new InputStreamReader(url.openStream(), StandardCharsets.UTF_8);
29072907
} catch (Exception e) {
29082908
return null;
29092909
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ private static void runCommandOnStream(
899899
try (BufferedReader reader =
900900
new BufferedReader(
901901
new InputStreamReader(process.getInputStream(),
902-
Charset.forName("UTF-8")))) {
902+
StandardCharsets.UTF_8))) {
903903
String line;
904904
while((line = reader.readLine()) != null) {
905905
LOG.debug(line);
@@ -922,7 +922,7 @@ private static void runCommandOnStream(
922922
try (BufferedReader reader =
923923
new BufferedReader(
924924
new InputStreamReader(process.getErrorStream(),
925-
Charset.forName("UTF-8")))) {
925+
StandardCharsets.UTF_8))) {
926926
String line;
927927
while((line = reader.readLine()) != null) {
928928
LOG.debug(line);

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/impl/FileSystemMultipartUploader.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.IOException;
2121
import java.io.InputStream;
2222
import java.nio.ByteBuffer;
23+
import java.nio.charset.StandardCharsets;
2324
import java.util.ArrayList;
2425
import java.util.Comparator;
2526
import java.util.HashSet;
@@ -30,7 +31,6 @@
3031
import java.util.concurrent.CompletableFuture;
3132
import java.util.stream.Collectors;
3233

33-
import org.apache.hadoop.thirdparty.com.google.common.base.Charsets;
3434
import org.apache.hadoop.util.Preconditions;
3535
import org.slf4j.Logger;
3636
import org.slf4j.LoggerFactory;
@@ -104,7 +104,7 @@ public CompletableFuture<UploadHandle> startUpload(Path filePath)
104104
fs.mkdirs(collectorPath, FsPermission.getDirDefault());
105105

106106
ByteBuffer byteBuffer = ByteBuffer.wrap(
107-
collectorPath.toString().getBytes(Charsets.UTF_8));
107+
collectorPath.toString().getBytes(StandardCharsets.UTF_8));
108108
return BBUploadHandle.from(byteBuffer);
109109
});
110110
}
@@ -130,7 +130,7 @@ private PartHandle innerPutPart(Path filePath,
130130
byte[] uploadIdByteArray = uploadId.toByteArray();
131131
checkUploadId(uploadIdByteArray);
132132
Path collectorPath = new Path(new String(uploadIdByteArray, 0,
133-
uploadIdByteArray.length, Charsets.UTF_8));
133+
uploadIdByteArray.length, StandardCharsets.UTF_8));
134134
Path partPath =
135135
mergePaths(collectorPath, mergePaths(new Path(Path.SEPARATOR),
136136
new Path(partNumber + ".part")));
@@ -149,7 +149,7 @@ private PartHandle innerPutPart(Path filePath,
149149
cleanupWithLogger(LOG, inputStream);
150150
}
151151
return BBPartHandle.from(ByteBuffer.wrap(
152-
partPath.toString().getBytes(Charsets.UTF_8)));
152+
partPath.toString().getBytes(StandardCharsets.UTF_8)));
153153
}
154154

155155
private Path createCollectorPath(Path filePath) {
@@ -210,7 +210,7 @@ private PathHandle innerComplete(
210210
.map(pair -> {
211211
byte[] byteArray = pair.getValue().toByteArray();
212212
return new Path(new String(byteArray, 0, byteArray.length,
213-
Charsets.UTF_8));
213+
StandardCharsets.UTF_8));
214214
})
215215
.collect(Collectors.toList());
216216

@@ -223,7 +223,7 @@ private PathHandle innerComplete(
223223
"Duplicate PartHandles");
224224
byte[] uploadIdByteArray = multipartUploadId.toByteArray();
225225
Path collectorPath = new Path(new String(uploadIdByteArray, 0,
226-
uploadIdByteArray.length, Charsets.UTF_8));
226+
uploadIdByteArray.length, StandardCharsets.UTF_8));
227227

228228
boolean emptyFile = totalPartsLen(partHandles) == 0;
229229
if (emptyFile) {
@@ -250,7 +250,7 @@ public CompletableFuture<Void> abort(UploadHandle uploadId,
250250
byte[] uploadIdByteArray = uploadId.toByteArray();
251251
checkUploadId(uploadIdByteArray);
252252
Path collectorPath = new Path(new String(uploadIdByteArray, 0,
253-
uploadIdByteArray.length, Charsets.UTF_8));
253+
uploadIdByteArray.length, StandardCharsets.UTF_8));
254254

255255
return FutureIO.eval(() -> {
256256
// force a check for a file existing; raises FNFE if not found

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CopyCommands.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.InputStream;
2323
import java.net.URI;
2424
import java.net.URISyntaxException;
25+
import java.nio.charset.StandardCharsets;
2526
import java.nio.file.Files;
2627
import java.util.Iterator;
2728
import java.util.LinkedList;
@@ -114,7 +115,7 @@ protected void processArguments(LinkedList<PathData> items)
114115

115116
private void writeDelimiter(FSDataOutputStream out) throws IOException {
116117
if (delimiter != null) {
117-
out.write(delimiter.getBytes("UTF-8"));
118+
out.write(delimiter.getBytes(StandardCharsets.UTF_8));
118119
}
119120
}
120121

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HtmlQuoting.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public static String quoteHtmlChars(String item) {
120120
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
121121
try {
122122
quoteHtmlChars(buffer, bytes, 0, bytes.length);
123-
return buffer.toString("UTF-8");
123+
return new String(buffer.toByteArray(), StandardCharsets.UTF_8);
124124
} catch (IOException ioe) {
125125
// Won't happen, since it is a bytearrayoutputstream
126126
return null;

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DefaultStringifier.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.io.IOException;
2222
import java.nio.charset.StandardCharsets;
23-
import java.nio.charset.UnsupportedCharsetException;
2423
import java.util.ArrayList;
2524

2625
import org.apache.commons.codec.binary.Base64;
@@ -75,14 +74,10 @@ public DefaultStringifier(Configuration conf, Class<T> c) {
7574

7675
@Override
7776
public T fromString(String str) throws IOException {
78-
try {
79-
byte[] bytes = Base64.decodeBase64(str.getBytes("UTF-8"));
80-
inBuf.reset(bytes, bytes.length);
81-
T restored = deserializer.deserialize(null);
82-
return restored;
83-
} catch (UnsupportedCharsetException ex) {
84-
throw new IOException(ex.toString());
85-
}
77+
byte[] bytes = Base64.decodeBase64(str.getBytes(StandardCharsets.UTF_8));
78+
inBuf.reset(bytes, bytes.length);
79+
T restored = deserializer.deserialize(null);
80+
return restored;
8681
}
8782

8883
@Override

0 commit comments

Comments
 (0)