Skip to content

Commit 45ab789

Browse files
committed
HADOOP-19134. Use StringBuilder instead of StringBuffer.
1 parent 06db628 commit 45ab789

File tree

119 files changed

+193
-194
lines changed

Some content is hidden

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

119 files changed

+193
-194
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyShell.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected int init(String[] args) throws IOException {
169169

170170
@Override
171171
public String getCommandUsage() {
172-
StringBuffer sbuf = new StringBuffer(USAGE_PREFIX + COMMANDS);
172+
StringBuilder sbuf = new StringBuilder(USAGE_PREFIX + COMMANDS);
173173
String banner = StringUtils.repeat("=", 66);
174174
sbuf.append(banner + "\n");
175175
sbuf.append(CreateCommand.USAGE + ":\n\n" + CreateCommand.DESC + "\n");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ protected void parseExecResult(BufferedReader lines) throws IOException {
163163
@VisibleForTesting
164164
protected void parseOutput() throws IOException {
165165
if (output.size() < 2) {
166-
StringBuffer sb = new StringBuffer("Fewer lines of output than expected");
166+
StringBuilder sb = new StringBuilder("Fewer lines of output than expected");
167167
if (output.size() > 0) {
168168
sb.append(": " + output.get(0));
169169
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ private static void unTarUsingTar(InputStream inputStream, File untarDir,
10521052

10531053
private static void unTarUsingTar(File inFile, File untarDir,
10541054
boolean gzipped) throws IOException {
1055-
StringBuffer untarCommand = new StringBuffer();
1055+
StringBuilder untarCommand = new StringBuilder();
10561056
// not using canonical path here; this postpones relative path
10571057
// resolution until bash is executed.
10581058
final String source = "'" + FileUtil.makeSecureShellPath(inFile) + "'";

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/oncrpc/RpcDeniedReply.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public RejectState getRejectState() {
5858

5959
@Override
6060
public String toString() {
61-
return new StringBuffer().append("xid:").append(xid)
61+
return new StringBuilder().append("xid:").append(xid)
6262
.append(",messageType:").append(messageType).append("verifier_flavor:")
6363
.append(verifier.getFlavor()).append("rejectState:")
6464
.append(rejectState).toString();

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/ProviderUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static Configuration excludeIncompatibleCredentialProviders(
148148
if (providerPath == null) {
149149
return config;
150150
}
151-
StringBuffer newProviderPath = new StringBuffer();
151+
StringBuilder newProviderPath = new StringBuilder();
152152
String[] providers = providerPath.split(",");
153153
Path path = null;
154154
for (String provider: providers) {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/CredentialShell.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected int init(String[] args) throws IOException {
127127

128128
@Override
129129
public String getCommandUsage() {
130-
StringBuffer sbuf = new StringBuffer(USAGE_PREFIX + COMMANDS);
130+
StringBuilder sbuf = new StringBuilder(USAGE_PREFIX + COMMANDS);
131131
String banner = StringUtils.repeat("=", 66);
132132
sbuf.append(banner + "\n")
133133
.append(CreateCommand.USAGE + ":\n\n" + CreateCommand.DESC + "\n")

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/ssl/SSLHostnameVerifier.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public void check(final String[] hosts, final String[] cns,
370370
strictWithSubDomains);
371371
}
372372
// Build up lists of allowed hosts For logging/debugging purposes.
373-
StringBuffer buf = new StringBuffer(32);
373+
StringBuilder buf = new StringBuilder(32);
374374
buf.append('<');
375375
for (int i = 0; i < hosts.length; i++) {
376376
String h = hosts[i];
@@ -408,8 +408,8 @@ public void check(final String[] hosts, final String[] cns,
408408
throw new SSLException(msg);
409409
}
410410

411-
// StringBuffer for building the error message.
412-
buf = new StringBuffer();
411+
// StringBuilder for building the error message.
412+
buf = new StringBuilder();
413413

414414
boolean match = false;
415415
out:

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ private void runCommand() throws IOException {
10141014
BufferedReader inReader =
10151015
new BufferedReader(new InputStreamReader(process.getInputStream(),
10161016
StandardCharsets.UTF_8));
1017-
final StringBuffer errMsg = new StringBuffer();
1017+
final StringBuilder errMsg = new StringBuilder();
10181018

10191019
// read error and input streams as this would free up the buffers
10201020
// free the error stream buffer
@@ -1208,7 +1208,7 @@ public static class ShellCommandExecutor extends Shell
12081208
implements CommandExecutor {
12091209

12101210
private String[] command;
1211-
private StringBuffer output;
1211+
private StringBuilder output;
12121212

12131213

12141214
public ShellCommandExecutor(String[] execString) {
@@ -1289,7 +1289,7 @@ public String[] getExecString() {
12891289

12901290
@Override
12911291
protected void parseExecResult(BufferedReader lines) throws IOException {
1292-
output = new StringBuffer();
1292+
output = new StringBuilder();
12931293
char[] buf = new char[512];
12941294
int nRead;
12951295
while ( (nRead = lines.read(buf, 0, buf.length)) > 0 ) {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ public static String wrap(String str, int wrapLength, String newLineStr,
13211321

13221322
int inputLineLength = str.length();
13231323
int offset = 0;
1324-
StringBuffer wrappedLine = new StringBuffer(inputLineLength + 32);
1324+
StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32);
13251325

13261326
while(inputLineLength - offset > wrapLength) {
13271327
if(str.charAt(offset) == 32) {

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCount.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ public MockQuotaUsage() {
580580
public String toString(boolean hOption,
581581
boolean tOption, List<StorageType> types) {
582582
if (tOption) {
583-
StringBuffer result = new StringBuffer();
583+
StringBuilder result = new StringBuilder();
584584
result.append(hOption ? HUMAN : BYTES);
585585

586586
for (StorageType type : types) {

0 commit comments

Comments
 (0)