src/java.base/share/classes/sun/security/x509/AVA.java
Print this page
rev 10552 : 8055723[core]: Replace concat String to append in StringBuilder parameters
Contributed-by: Otavio Santana <otaviojava@java.net>
@@ -1060,11 +1060,11 @@
}
} else {
boolean quoteNeeded = false;
- StringBuilder sbuffer = new StringBuilder();
+ StringBuilder sb = new StringBuilder();
boolean previousWhite = false;
final String escapees = ",+=\n<>#;\\\"";
/*
* Special characters (e.g. AVA list separators) cause strings
@@ -1077,11 +1077,11 @@
&& valStr.charAt(length - 1) == '\"');
for (int i = 0; i < length; i++) {
char c = valStr.charAt(i);
if (alreadyQuoted && (i == 0 || i == length - 1)) {
- sbuffer.append(c);
+ sb.append(c);
continue;
}
if (DerValue.isPrintableStringChar(c) ||
escapees.indexOf(c) >= 0) {
@@ -1094,21 +1094,21 @@
// quote if multiple internal whitespace
if (!(c == ' ' || c == '\n')) {
// escape '"' and '\'
if (c == '"' || c == '\\') {
- sbuffer.append('\\');
+ sb.append('\\');
}
previousWhite = false;
} else {
if (!quoteNeeded && previousWhite) {
quoteNeeded = true;
}
previousWhite = true;
}
- sbuffer.append(c);
+ sb.append(c);
} else if (debug != null && Debug.isOn("ava")) {
// embed non-printable/non-escaped char
// as escaped hex pairs for debugging
@@ -1117,41 +1117,41 @@
// embed escaped hex pairs
byte[] valueBytes =
Character.toString(c).getBytes("UTF8");
for (int j = 0; j < valueBytes.length; j++) {
- sbuffer.append('\\');
+ sb.append('\\');
char hexChar = Character.forDigit
(0xF & (valueBytes[j] >>> 4), 16);
- sbuffer.append(Character.toUpperCase(hexChar));
+ sb.append(Character.toUpperCase(hexChar));
hexChar = Character.forDigit
(0xF & (valueBytes[j]), 16);
- sbuffer.append(Character.toUpperCase(hexChar));
+ sb.append(Character.toUpperCase(hexChar));
}
} else {
// append non-printable/non-escaped char
previousWhite = false;
- sbuffer.append(c);
+ sb.append(c);
}
}
// quote if trailing whitespace
- if (sbuffer.length() > 0) {
- char trailChar = sbuffer.charAt(sbuffer.length() - 1);
+ if (sb.length() > 0) {
+ char trailChar = sb.charAt(sb.length() - 1);
if (trailChar == ' ' || trailChar == '\n') {
quoteNeeded = true;
}
}
// Emit the string ... quote it if needed
// if string is already quoted, don't re-quote
if (!alreadyQuoted && quoteNeeded) {
- retval.append("\"" + sbuffer.toString() + "\"");
+ retval.append('"').append(sb).append('"');
} else {
- retval.append(sbuffer.toString());
+ retval.append(sb);
}
}
} catch (IOException e) {
throw new IllegalArgumentException("DER Value conversion");
}