8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
Reviewed-by: mullan
--- a/jdk/src/java.base/share/classes/sun/security/x509/AVA.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/AVA.java Mon May 18 17:38:38 2015 +0300
@@ -454,7 +454,7 @@
if (embeddedHex.size() > 0) {
// add space(s) before embedded hex bytes
for (int i = 0; i < spaceCount; i++) {
- temp.append(" ");
+ temp.append(' ');
}
spaceCount = 0;
@@ -472,7 +472,7 @@
} else {
// add space(s)
for (int i = 0; i < spaceCount; i++) {
- temp.append(" ");
+ temp.append(' ');
}
spaceCount = 0;
temp.append((char)c);
@@ -853,7 +853,7 @@
}
sbuffer.append(c);
}
- typeAndValue.append(sbuffer.toString());
+ typeAndValue.append(sbuffer);
}
return typeAndValue.toString();
}
@@ -1039,7 +1039,7 @@
StringBuilder retval = new StringBuilder(40);
retval.append(keyword);
- retval.append("=");
+ retval.append('=');
try {
String valStr = value.getAsString();
@@ -1147,9 +1147,11 @@
// 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(sbuffer)
+ .append('\"');
} else {
- retval.append(sbuffer.toString());
+ retval.append(sbuffer);
}
}
} catch (IOException e) {
--- a/jdk/src/java.base/share/classes/sun/security/x509/AuthorityKeyIdentifierExtension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/AuthorityKeyIdentifierExtension.java Mon May 18 17:38:38 2015 +0300
@@ -196,17 +196,20 @@
* Return the object as a string.
*/
public String toString() {
- String s = super.toString() + "AuthorityKeyIdentifier [\n";
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.toString())
+ .append("AuthorityKeyIdentifier [\n");
if (id != null) {
- s += id.toString(); // id already has a newline
+ sb.append(id); // id already has a newline
}
if (names != null) {
- s += names.toString() + "\n";
+ sb.append(names).append('\n');
}
if (serialNum != null) {
- s += serialNum.toString() + "\n";
+ sb.append(serialNum).append('\n');
}
- return (s + "]\n");
+ sb.append("]\n");
+ return sb.toString();
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/BasicConstraintsExtension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/BasicConstraintsExtension.java Mon May 18 17:38:38 2015 +0300
@@ -171,15 +171,11 @@
* Return user readable form of extension.
*/
public String toString() {
- String s = super.toString() + "BasicConstraints:[\n";
-
- s += ((ca) ? (" CA:true") : (" CA:false")) + "\n";
- if (pathLen >= 0) {
- s += " PathLen:" + pathLen + "\n";
- } else {
- s += " PathLen: undefined\n";
- }
- return (s + "]\n");
+ return super.toString() +
+ "BasicConstraints:[\n CA:" + ca +
+ "\n PathLen:" +
+ ((pathLen >= 0) ? String.valueOf(pathLen) : " undefined") +
+ "\n]\n";
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/CRLDistributionPointsExtension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/CRLDistributionPointsExtension.java Mon May 18 17:38:38 2015 +0300
@@ -231,8 +231,8 @@
distributionPoints = (List<DistributionPoint>)obj;
} else {
throw new IOException("Attribute name [" + name +
- "] not recognized by " +
- "CertAttrSet:" + extensionName + ".");
+ "] not recognized by " +
+ "CertAttrSet:" + extensionName + '.');
}
encodeThis();
}
@@ -245,8 +245,8 @@
return distributionPoints;
} else {
throw new IOException("Attribute name [" + name +
- "] not recognized by " +
- "CertAttrSet:" + extensionName + ".");
+ "] not recognized by " +
+ "CertAttrSet:" + extensionName + '.');
}
}
--- a/jdk/src/java.base/share/classes/sun/security/x509/CRLNumberExtension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/CRLNumberExtension.java Mon May 18 17:38:38 2015 +0300
@@ -146,8 +146,8 @@
}
crlNumber = (BigInteger)obj;
} else {
- throw new IOException("Attribute name not recognized by"
- + " CertAttrSet:" + extensionName + ".");
+ throw new IOException("Attribute name not recognized by" +
+ " CertAttrSet:" + extensionName + '.');
}
encodeThis();
}
@@ -172,8 +172,8 @@
if (name.equalsIgnoreCase(NUMBER)) {
crlNumber = null;
} else {
- throw new IOException("Attribute name not recognized by"
- + " CertAttrSet:" + extensionName + ".");
+ throw new IOException("Attribute name not recognized by" +
+ " CertAttrSet:" + extensionName + '.');
}
encodeThis();
}
@@ -182,10 +182,15 @@
* Returns a printable representation of the CRLNumberExtension.
*/
public String toString() {
- String s = super.toString() + extensionLabel + ": " +
- ((crlNumber == null) ? "" : Debug.toHexString(crlNumber))
- + "\n";
- return (s);
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.toString())
+ .append(extensionLabel)
+ .append(": ");
+ if (crlNumber != null) {
+ sb.append(Debug.toHexString(crlNumber));
+ }
+ sb.append('\n');
+ return sb.toString();
}
/**
@@ -195,7 +200,7 @@
* @exception IOException on encoding errors.
*/
public void encode(OutputStream out) throws IOException {
- DerOutputStream tmp = new DerOutputStream();
+ DerOutputStream tmp = new DerOutputStream();
encode(out, PKIXExtensions.CRLNumber_Id, true);
}
--- a/jdk/src/java.base/share/classes/sun/security/x509/CertException.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/CertException.java Mon May 18 17:38:38 2015 +0300
@@ -158,7 +158,7 @@
*/
public String toString()
{
- return "[Certificate Exception: " + getMessage() + "]";
+ return "[Certificate Exception: " + getMessage() + ']';
}
/**
@@ -168,6 +168,6 @@
{
return getVerfDescription()
+ ( (moreData != null)
- ? ( "\n (" + moreData + ")" ) : "" );
+ ? ( "\n (" + moreData + ')' ) : "" );
}
}
--- a/jdk/src/java.base/share/classes/sun/security/x509/CertificatePoliciesExtension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/CertificatePoliciesExtension.java Mon May 18 17:38:38 2015 +0300
@@ -160,10 +160,12 @@
if (certPolicies == null) {
return "";
}
- StringBuilder sb = new StringBuilder(super.toString());
- sb.append("CertificatePolicies [\n");
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.toString())
+ .append("CertificatePolicies [\n");
for (PolicyInformation info : certPolicies) {
- sb.append(info.toString());
+ sb.append(info);
}
sb.append("]\n");
return sb.toString();
--- a/jdk/src/java.base/share/classes/sun/security/x509/CertificateValidity.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/CertificateValidity.java Mon May 18 17:38:38 2015 +0300
@@ -134,8 +134,8 @@
public String toString() {
if (notBefore == null || notAfter == null)
return "";
- return ("Validity: [From: " + notBefore.toString() +
- ",\n To: " + notAfter.toString() + "]");
+ return "Validity: [From: " + notBefore +
+ ",\n To: " + notAfter + ']';
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/DistributionPoint.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/DistributionPoint.java Mon May 18 17:38:38 2015 +0300
@@ -380,23 +380,29 @@
*/
public String toString() {
StringBuilder sb = new StringBuilder();
+ sb.append("DistributionPoint:\n ");
if (fullName != null) {
- sb.append("DistributionPoint:\n " + fullName + "\n");
+ sb.append(fullName);
}
if (relativeName != null) {
- sb.append("DistributionPoint:\n " + relativeName + "\n");
+ sb.append(relativeName);
}
+ sb.append('\n');
if (reasonFlags != null) {
sb.append(" ReasonFlags:\n");
for (int i = 0; i < reasonFlags.length; i++) {
if (reasonFlags[i]) {
- sb.append(" " + reasonToString(i) + "\n");
+ sb.append(" ")
+ .append(reasonToString(i))
+ .append('\n');
}
}
}
if (crlIssuer != null) {
- sb.append(" CRLIssuer:" + crlIssuer + "\n");
+ sb.append(" CRLIssuer:")
+ .append(crlIssuer)
+ .append('\n');
}
return sb.toString();
}
--- a/jdk/src/java.base/share/classes/sun/security/x509/DistributionPointName.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/DistributionPointName.java Mon May 18 17:38:38 2015 +0300
@@ -230,13 +230,13 @@
*/
public String toString() {
StringBuilder sb = new StringBuilder();
+ sb.append("DistributionPointName:\n ");
if (fullName != null) {
- sb.append("DistributionPointName:\n " + fullName + "\n");
-
+ sb.append(fullName);
} else {
- sb.append("DistributionPointName:\n " + relativeName + "\n");
+ sb.append(relativeName);
}
-
+ sb.append('\n');
return sb.toString();
}
}
--- a/jdk/src/java.base/share/classes/sun/security/x509/EDIPartyName.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/EDIPartyName.java Mon May 18 17:38:38 2015 +0300
@@ -209,10 +209,15 @@
* Return the printable string.
*/
public String toString() {
- return ("EDIPartyName: " +
- ((assigner == null) ? "" :
- (" nameAssigner = " + assigner + ","))
- + " partyName = " + party);
+ StringBuilder sb = new StringBuilder("EDIPartyName: ");
+ if (assigner != null) {
+ sb.append(" nameAssigner = ")
+ .append(assigner)
+ .append(',');
+ }
+ sb.append(" partyName = ")
+ .append(party);
+ return sb.toString();
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/Extension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/Extension.java Mon May 18 17:38:38 2015 +0300
@@ -219,13 +219,8 @@
* Returns the Extension in user readable form.
*/
public String toString() {
- String s = "ObjectId: " + extensionId.toString();
- if (critical) {
- s += " Criticality=true\n";
- } else {
- s += " Criticality=false\n";
- }
- return (s);
+ return "ObjectId: " + extensionId +
+ " Criticality=" + critical + '\n';
}
// Value to mix up the hash
--- a/jdk/src/java.base/share/classes/sun/security/x509/GeneralSubtree.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/GeneralSubtree.java Mon May 18 17:38:38 2015 +0300
@@ -127,15 +127,22 @@
* Return a printable string of the GeneralSubtree.
*/
public String toString() {
- String s = "\n GeneralSubtree: [\n" +
- " GeneralName: " + ((name == null) ? "" : name.toString()) +
- "\n Minimum: " + minimum;
- if (maximum == -1) {
- s += "\t Maximum: undefined";
- } else
- s += "\t Maximum: " + maximum;
- s += " ]\n";
- return (s);
+ StringBuilder sb = new StringBuilder();
+ sb.append("\n GeneralSubtree: [")
+ .append("\n GeneralName: ");
+ if (name != null) {
+ sb.append(name);
+ }
+ sb.append("\n Minimum: ")
+ .append(minimum)
+ .append("\n Maximum: ");
+ if (maximum == -1) {
+ sb.append("undefined");
+ } else {
+ sb.append(maximum);
+ }
+ sb.append(" ]\n");
+ return sb.toString();
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/GeneralSubtrees.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/GeneralSubtrees.java Mon May 18 17:38:38 2015 +0300
@@ -124,8 +124,7 @@
* Return a printable string of the GeneralSubtree.
*/
public String toString() {
- String s = " GeneralSubtrees:\n" + trees.toString() + "\n";
- return s;
+ return " GeneralSubtrees:\n" + trees + '\n';
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/IPAddressName.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/IPAddressName.java Mon May 18 17:38:38 2015 +0300
@@ -263,7 +263,7 @@
if (address.length == 8) {
byte[] mask = new byte[4];
System.arraycopy(address, 4, mask, 0, 4);
- name = name + "/" +
+ name = name + '/' +
InetAddress.getByAddress(mask).getHostAddress();
}
} else {
@@ -285,7 +285,7 @@
if (!ba.get(i))
break;
}
- name = name + "/" + i;
+ name = name + '/' + i;
// Verify remaining bits 0
for (; i < 16*8; i++) {
if (ba.get(i)) {
--- a/jdk/src/java.base/share/classes/sun/security/x509/IssuerAlternativeNameExtension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/IssuerAlternativeNameExtension.java Mon May 18 17:38:38 2015 +0300
@@ -140,17 +140,20 @@
* Returns a printable representation of the IssuerAlternativeName.
*/
public String toString() {
-
- String result = super.toString() + "IssuerAlternativeName [\n";
- if(names == null) {
- result += " null\n";
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.toString())
+ .append("IssuerAlternativeName [\n");
+ if (names == null) {
+ sb.append(" null\n");
} else {
- for(GeneralName name: names.names()) {
- result += " "+name+"\n";
+ for (GeneralName name : names.names()) {
+ sb.append(" ")
+ .append(name)
+ .append('\n');
}
}
- result += "]\n";
- return result;
+ sb.append("]\n");
+ return sb.toString();
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/IssuingDistributionPointExtension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/IssuingDistributionPointExtension.java Mon May 18 17:38:38 2015 +0300
@@ -441,9 +441,9 @@
* Returns the extension as user readable string.
*/
public String toString() {
-
- StringBuilder sb = new StringBuilder(super.toString());
- sb.append("IssuingDistributionPoint [\n ");
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.toString())
+ .append("IssuingDistributionPoint [\n ");
if (distributionPoint != null) {
sb.append(distributionPoint);
@@ -453,23 +453,18 @@
sb.append(revocationReasons);
}
- sb.append((hasOnlyUserCerts)
- ? (" Only contains user certs: true")
- : (" Only contains user certs: false")).append("\n");
-
- sb.append((hasOnlyCACerts)
- ? (" Only contains CA certs: true")
- : (" Only contains CA certs: false")).append("\n");
-
- sb.append((hasOnlyAttributeCerts)
- ? (" Only contains attribute certs: true")
- : (" Only contains attribute certs: false")).append("\n");
-
- sb.append((isIndirectCRL)
- ? (" Indirect CRL: true")
- : (" Indirect CRL: false")).append("\n");
-
- sb.append("]\n");
+ sb.append(" Only contains user certs: ")
+ .append(hasOnlyUserCerts)
+ .append('\n')
+ .append(" Only contains CA certs: ")
+ .append(hasOnlyCACerts)
+ .append('\n')
+ .append(" Only contains attribute certs: ")
+ .append(hasOnlyAttributeCerts)
+ .append('\n')
+ .append(" Indirect CRL: ")
+ .append(isIndirectCRL)
+ .append("\n]\n");
return sb.toString();
}
--- a/jdk/src/java.base/share/classes/sun/security/x509/NameConstraintsExtension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/NameConstraintsExtension.java Mon May 18 17:38:38 2015 +0300
@@ -214,12 +214,19 @@
* Return the printable string.
*/
public String toString() {
- return (super.toString() + "NameConstraints: [" +
- ((permitted == null) ? "" :
- ("\n Permitted:" + permitted.toString())) +
- ((excluded == null) ? "" :
- ("\n Excluded:" + excluded.toString()))
- + " ]\n");
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.toString())
+ .append("NameConstraints: [");
+ if (permitted != null) {
+ sb.append("\n Permitted:")
+ .append(permitted);
+ }
+ if (excluded != null) {
+ sb.append("\n Excluded:")
+ .append(excluded);
+ }
+ sb.append(" ]\n");
+ return sb.toString();
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/PolicyConstraintsExtension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/PolicyConstraintsExtension.java Mon May 18 17:38:38 2015 +0300
@@ -175,19 +175,24 @@
* Return the extension as user readable string.
*/
public String toString() {
- String s;
- s = super.toString() + "PolicyConstraints: [" + " Require: ";
- if (require == -1)
- s += "unspecified;";
- else
- s += require + ";";
- s += "\tInhibit: ";
- if (inhibit == -1)
- s += "unspecified";
- else
- s += inhibit;
- s += " ]\n";
- return s;
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.toString())
+ .append("PolicyConstraints: [")
+ .append(" Require: ");
+ if (require == -1) {
+ sb.append("unspecified;");
+ } else {
+ sb.append(require)
+ .append(';');
+ }
+ sb.append("\tInhibit: ");
+ if (inhibit == -1) {
+ sb.append("unspecified");
+ } else {
+ sb.append(inhibit);
+ }
+ sb.append(" ]\n");
+ return sb.toString();
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/PolicyInformation.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/PolicyInformation.java Mon May 18 17:38:38 2015 +0300
@@ -258,9 +258,7 @@
* Return a printable representation of the PolicyInformation.
*/
public String toString() {
- StringBuilder s = new StringBuilder(" [" + policyIdentifier.toString());
- s.append(policyQualifiers + " ]\n");
- return s.toString();
+ return " [" + policyIdentifier + policyQualifiers + " ]\n";
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/PrivateKeyUsageExtension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/PrivateKeyUsageExtension.java Mon May 18 17:38:38 2015 +0300
@@ -175,11 +175,22 @@
* Return the printable string.
*/
public String toString() {
- return(super.toString() +
- "PrivateKeyUsage: [\n" +
- ((notBefore == null) ? "" : "From: " + notBefore.toString() + ", ")
- + ((notAfter == null) ? "" : "To: " + notAfter.toString())
- + "]\n");
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.toString())
+ .append("PrivateKeyUsage: [\n");
+ if (notBefore != null) {
+ sb.append("From: ")
+ .append(notBefore);
+ if (notAfter != null) {
+ sb.append(", ");
+ }
+ }
+ if (notAfter != null) {
+ sb.append("To: ")
+ .append(notAfter);
+ }
+ sb.append("]\n");
+ return sb.toString();
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/RDN.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/RDN.java Mon May 18 17:38:38 2015 +0300
@@ -348,14 +348,11 @@
return assertion[0].toString();
}
- StringBuilder sb = new StringBuilder();
+ StringJoiner sj = new StringJoiner(" + ");
for (int i = 0; i < assertion.length; i++) {
- if (i != 0) {
- sb.append(" + ");
- }
- sb.append(assertion[i].toString());
+ sj.add(assertion[i].toString());
}
- return sb.toString();
+ return sj.toString();
}
/*
@@ -376,14 +373,11 @@
return assertion[0].toRFC1779String(oidMap);
}
- StringBuilder sb = new StringBuilder();
+ StringJoiner sj = new StringJoiner(" + ");
for (int i = 0; i < assertion.length; i++) {
- if (i != 0) {
- sb.append(" + ");
- }
- sb.append(assertion[i].toRFC1779String(oidMap));
+ sj.add(assertion[i].toRFC1779String(oidMap));
}
- return sb.toString();
+ return sj.toString();
}
/*
--- a/jdk/src/java.base/share/classes/sun/security/x509/SerialNumber.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/SerialNumber.java Mon May 18 17:38:38 2015 +0300
@@ -101,7 +101,7 @@
* Return the SerialNumber as user readable string.
*/
public String toString() {
- return ("SerialNumber: [" + Debug.toHexString(serialNum) + "]");
+ return "SerialNumber: [" + Debug.toHexString(serialNum) + ']';
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/SubjectInfoAccessExtension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/SubjectInfoAccessExtension.java Mon May 18 17:38:38 2015 +0300
@@ -238,8 +238,8 @@
* Return the extension as user readable string.
*/
public String toString() {
- return super.toString() + "SubjectInfoAccess [\n "
- + accessDescriptions + "\n]\n";
+ return super.toString() +
+ "SubjectInfoAccess [\n " + accessDescriptions + "\n]\n";
}
}
--- a/jdk/src/java.base/share/classes/sun/security/x509/SubjectKeyIdentifierExtension.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/SubjectKeyIdentifierExtension.java Mon May 18 17:38:38 2015 +0300
@@ -115,8 +115,8 @@
* Returns a printable representation.
*/
public String toString() {
- return super.toString() + "SubjectKeyIdentifier [\n"
- + String.valueOf(id) + "]\n";
+ return super.toString() +
+ "SubjectKeyIdentifier [\n" + id + "]\n";
}
/**
--- a/jdk/src/java.base/share/classes/sun/security/x509/X500Name.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/X500Name.java Mon May 18 17:38:38 2015 +0300
@@ -31,6 +31,7 @@
import java.security.AccessController;
import java.security.Principal;
import java.util.*;
+import java.util.StringJoiner;
import sun.security.util.*;
import javax.security.auth.x500.X500Principal;
@@ -689,14 +690,11 @@
* The encodings of adjoining RelativeDistinguishedNames are separated
* by a comma character (',' ASCII 44).
*/
- StringBuilder fullname = new StringBuilder(48);
+ StringJoiner sj = new StringJoiner(",");
for (int i = names.length - 1; i >= 0; i--) {
- if (i < names.length - 1) {
- fullname.append(',');
- }
- fullname.append(names[i].toRFC2253String(oidMap));
+ sj.add(names[i].toRFC2253String(oidMap));
}
- return fullname.toString();
+ return sj.toString();
}
public String getRFC2253CanonicalName() {
@@ -722,14 +720,11 @@
* The encodings of adjoining RelativeDistinguishedNames are separated
* by a comma character (',' ASCII 44).
*/
- StringBuilder fullname = new StringBuilder(48);
+ StringJoiner sj = new StringJoiner(",");
for (int i = names.length - 1; i >= 0; i--) {
- if (i < names.length - 1) {
- fullname.append(',');
- }
- fullname.append(names[i].toRFC2253String(true));
+ sj.add(names[i].toRFC2253String(true));
}
- canonicalDn = fullname.toString();
+ canonicalDn = sj.toString();
return canonicalDn;
}
@@ -1064,16 +1059,16 @@
return;
}
- StringBuilder sb = new StringBuilder(48);
- if (names != null) {
- for (int i = names.length - 1; i >= 0; i--) {
- if (i != names.length - 1) {
- sb.append(", ");
- }
- sb.append(names[i].toString());
- }
+ if (names == null) {
+ dn = "";
+ return;
}
- dn = sb.toString();
+
+ StringJoiner sj = new StringJoiner(", ");
+ for (int i = names.length - 1; i >= 0; i--) {
+ sj.add(names[i].toString());
+ }
+ dn = sj.toString();
}
/*
@@ -1090,16 +1085,15 @@
return names[0].toRFC1779String(oidMap);
}
- StringBuilder sb = new StringBuilder(48);
- if (names != null) {
- for (int i = names.length - 1; i >= 0; i--) {
- if (i != names.length - 1) {
- sb.append(", ");
- }
- sb.append(names[i].toRFC1779String(oidMap));
- }
+ if (names == null) {
+ return "";
}
- return sb.toString();
+
+ StringJoiner sj = new StringJoiner(", ");
+ for (int i = names.length - 1; i >= 0; i--) {
+ sj.add(names[i].toRFC1779String(oidMap));
+ }
+ return sj.toString();
}
/****************************************************************/
--- a/jdk/src/java.base/share/classes/sun/security/x509/X509CRLEntryImpl.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/X509CRLEntryImpl.java Mon May 18 17:38:38 2015 +0300
@@ -291,40 +291,47 @@
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append(serialNumber.toString());
- sb.append(" On: " + revocationDate.toString());
+ sb.append(serialNumber)
+ .append(" On: ")
+ .append(revocationDate);
if (certIssuer != null) {
- sb.append("\n Certificate issuer: " + certIssuer);
+ sb.append("\n Certificate issuer: ")
+ .append(certIssuer);
}
if (extensions != null) {
Collection<Extension> allEntryExts = extensions.getAllExtensions();
Extension[] exts = allEntryExts.toArray(new Extension[0]);
- sb.append("\n CRL Entry Extensions: " + exts.length);
+ sb.append("\n CRL Entry Extensions: ")
+ .append(exts.length);
for (int i = 0; i < exts.length; i++) {
- sb.append("\n [" + (i+1) + "]: ");
+ sb.append("\n [")
+ .append(i+1)
+ .append("]: ");
Extension ext = exts[i];
try {
if (OIDMap.getClass(ext.getExtensionId()) == null) {
- sb.append(ext.toString());
+ sb.append(ext);
byte[] extValue = ext.getExtensionValue();
if (extValue != null) {
DerOutputStream out = new DerOutputStream();
out.putOctetString(extValue);
extValue = out.toByteArray();
HexDumpEncoder enc = new HexDumpEncoder();
- sb.append("Extension unknown: "
- + "DER encoded OCTET string =\n"
- + enc.encodeBuffer(extValue) + "\n");
+ sb.append("Extension unknown: ")
+ .append("DER encoded OCTET string =\n")
+ .append(enc.encodeBuffer(extValue))
+ .append('\n');
}
- } else
- sb.append(ext.toString()); //sub-class exists
+ } else {
+ sb.append(ext); //sub-class exists
+ }
} catch (Exception e) {
sb.append(", Error parsing this extension");
}
}
}
- sb.append("\n");
+ sb.append('\n');
return sb.toString();
}
--- a/jdk/src/java.base/share/classes/sun/security/x509/X509CRLImpl.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/X509CRLImpl.java Mon May 18 17:38:38 2015 +0300
@@ -537,47 +537,65 @@
*/
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append("X.509 CRL v" + (version+1) + "\n");
+ sb.append("X.509 CRL v")
+ .append(version+1)
+ .append('\n');
if (sigAlgId != null)
- sb.append("Signature Algorithm: " + sigAlgId.toString() +
- ", OID=" + (sigAlgId.getOID()).toString() + "\n");
+ sb.append("Signature Algorithm: ")
+ .append(sigAlgId)
+ .append(", OID=")
+ .append(sigAlgId.getOID())
+ .append('\n');
if (issuer != null)
- sb.append("Issuer: " + issuer.toString() + "\n");
+ sb.append("Issuer: ")
+ .append(issuer)
+ .append('\n');
if (thisUpdate != null)
- sb.append("\nThis Update: " + thisUpdate.toString() + "\n");
+ sb.append("\nThis Update: ")
+ .append(thisUpdate)
+ .append('\n');
if (nextUpdate != null)
- sb.append("Next Update: " + nextUpdate.toString() + "\n");
+ sb.append("Next Update: ")
+ .append(nextUpdate)
+ .append('\n');
if (revokedList.isEmpty())
sb.append("\nNO certificates have been revoked\n");
else {
- sb.append("\nRevoked Certificates: " + revokedList.size());
+ sb.append("\nRevoked Certificates: ")
+ .append(revokedList.size());
int i = 1;
for (X509CRLEntry entry: revokedList) {
- sb.append("\n[" + i++ + "] " + entry.toString());
+ sb.append("\n[")
+ .append(i++)
+ .append("] ")
+ .append(entry);
}
}
if (extensions != null) {
Collection<Extension> allExts = extensions.getAllExtensions();
Object[] objs = allExts.toArray();
- sb.append("\nCRL Extensions: " + objs.length);
+ sb.append("\nCRL Extensions: ")
+ .append(objs.length);
for (int i = 0; i < objs.length; i++) {
- sb.append("\n[" + (i+1) + "]: ");
+ sb.append("\n[").append(i+1).append("]: ");
Extension ext = (Extension)objs[i];
try {
- if (OIDMap.getClass(ext.getExtensionId()) == null) {
- sb.append(ext.toString());
- byte[] extValue = ext.getExtensionValue();
- if (extValue != null) {
- DerOutputStream out = new DerOutputStream();
- out.putOctetString(extValue);
- extValue = out.toByteArray();
- HexDumpEncoder enc = new HexDumpEncoder();
- sb.append("Extension unknown: "
- + "DER encoded OCTET string =\n"
- + enc.encodeBuffer(extValue) + "\n");
- }
- } else
- sb.append(ext.toString()); // sub-class exists
+ if (OIDMap.getClass(ext.getExtensionId()) == null) {
+ sb.append(ext);
+ byte[] extValue = ext.getExtensionValue();
+ if (extValue != null) {
+ DerOutputStream out = new DerOutputStream();
+ out.putOctetString(extValue);
+ extValue = out.toByteArray();
+ HexDumpEncoder enc = new HexDumpEncoder();
+ sb.append("Extension unknown: ")
+ .append("DER encoded OCTET string =\n")
+ .append(enc.encodeBuffer(extValue))
+ .append('\n');
+ }
+ } else {
+ sb.append(ext); // sub-class exists
+ }
} catch (Exception e) {
sb.append(", Error parsing this extension");
}
@@ -585,10 +603,12 @@
}
if (signature != null) {
HexDumpEncoder encoder = new HexDumpEncoder();
- sb.append("\nSignature:\n" + encoder.encodeBuffer(signature)
- + "\n");
- } else
+ sb.append("\nSignature:\n")
+ .append(encoder.encodeBuffer(signature))
+ .append('\n');
+ } else {
sb.append("NOT signed yet\n");
+ }
return sb.toString();
}
--- a/jdk/src/java.base/share/classes/sun/security/x509/X509CertImpl.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/X509CertImpl.java Mon May 18 17:38:38 2015 +0300
@@ -81,7 +81,7 @@
private static final long serialVersionUID = -3457612960190864406L;
- private static final String DOT = ".";
+ private static final char DOT = '.';
/**
* Public attribute names.
*/
@@ -799,17 +799,10 @@
if (info == null || algId == null || signature == null)
return "";
- StringBuilder sb = new StringBuilder();
-
- sb.append("[\n");
- sb.append(info.toString() + "\n");
- sb.append(" Algorithm: [" + algId.toString() + "]\n");
-
HexDumpEncoder encoder = new HexDumpEncoder();
- sb.append(" Signature:\n" + encoder.encodeBuffer(signature));
- sb.append("\n]");
-
- return sb.toString();
+ return "[\n" + info + '\n' +
+ " Algorithm: [" + algId + "]\n" +
+ " Signature:\n" + encoder.encodeBuffer(signature) + "\n]";
}
// the strongly typed gets, as per java.security.cert.X509Certificate
@@ -1941,31 +1934,30 @@
* only contains 0-9 and A-F. No small case, no colon.
*/
private String getCertificateFingerPrint(String mdAlg) {
- String fingerPrint = "";
try {
byte[] encCertInfo = getEncoded();
MessageDigest md = MessageDigest.getInstance(mdAlg);
byte[] digest = md.digest(encCertInfo);
- StringBuffer buf = new StringBuffer();
+ StringBuilder sb = new StringBuilder(digest.length * 2);
for (int i = 0; i < digest.length; i++) {
- byte2hex(digest[i], buf);
+ byte2hex(digest[i], sb);
}
- fingerPrint = buf.toString();
+ return sb.toString();
} catch (NoSuchAlgorithmException | CertificateEncodingException e) {
// ignored
}
- return fingerPrint;
+ return "";
}
/**
- * Converts a byte to hex digit and writes to the supplied buffer
+ * Converts a byte to hex digit and writes to the supplied builder
*/
- private static void byte2hex(byte b, StringBuffer buf) {
+ private static void byte2hex(byte b, StringBuilder buf) {
char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'A', 'B', 'C', 'D', 'E', 'F' };
int high = ((b & 0xf0) >> 4);
int low = (b & 0x0f);
- buf.append(hexChars[high]);
- buf.append(hexChars[low]);
+ buf.append(hexChars[high])
+ .append(hexChars[low]);
}
}
--- a/jdk/src/java.base/share/classes/sun/security/x509/X509CertInfo.java Mon May 18 17:34:48 2015 +0300
+++ b/jdk/src/java.base/share/classes/sun/security/x509/X509CertInfo.java Mon May 18 17:38:38 2015 +0300
@@ -299,55 +299,60 @@
}
StringBuilder sb = new StringBuilder();
- sb.append("[\n");
- sb.append(" " + version.toString() + "\n");
- sb.append(" Subject: " + subject.toString() + "\n");
- sb.append(" Signature Algorithm: " + algId.toString() + "\n");
- sb.append(" Key: " + pubKey.toString() + "\n");
- sb.append(" " + interval.toString() + "\n");
- sb.append(" Issuer: " + issuer.toString() + "\n");
- sb.append(" " + serialNum.toString() + "\n");
+ sb.append("[\n")
+ .append(" ").append(version).append('\n')
+ .append(" Subject: ").append(subject).append('\n')
+ .append(" Signature Algorithm: ").append(algId).append('\n')
+ .append(" Key: ").append(pubKey).append('\n')
+ .append(" ").append(interval).append('\n')
+ .append(" Issuer: ").append(issuer).append('\n')
+ .append(" ").append(serialNum).append('\n');
// optional v2, v3 extras
if (issuerUniqueId != null) {
- sb.append(" Issuer Id:\n" + issuerUniqueId.toString() + "\n");
+ sb.append(" Issuer Id:\n").append(issuerUniqueId).append('\n');
}
if (subjectUniqueId != null) {
- sb.append(" Subject Id:\n" + subjectUniqueId.toString() + "\n");
+ sb.append(" Subject Id:\n").append(subjectUniqueId).append('\n');
}
if (extensions != null) {
Collection<Extension> allExts = extensions.getAllExtensions();
Extension[] exts = allExts.toArray(new Extension[0]);
- sb.append("\nCertificate Extensions: " + exts.length);
+ sb.append("\nCertificate Extensions: ").append(exts.length);
for (int i = 0; i < exts.length; i++) {
- sb.append("\n[" + (i+1) + "]: ");
+ sb.append("\n[").append(i+1).append("]: ");
Extension ext = exts[i];
try {
if (OIDMap.getClass(ext.getExtensionId()) == null) {
- sb.append(ext.toString());
+ sb.append(ext);
byte[] extValue = ext.getExtensionValue();
if (extValue != null) {
DerOutputStream out = new DerOutputStream();
out.putOctetString(extValue);
extValue = out.toByteArray();
HexDumpEncoder enc = new HexDumpEncoder();
- sb.append("Extension unknown: "
- + "DER encoded OCTET string =\n"
- + enc.encodeBuffer(extValue) + "\n");
+ sb.append("Extension unknown: ")
+ .append("DER encoded OCTET string =\n")
+ .append(enc.encodeBuffer(extValue))
+ .append('\n');
}
- } else
- sb.append(ext.toString()); //sub-class exists
+ } else {
+ sb.append(ext); //sub-class exists
+ }
} catch (Exception e) {
sb.append(", Error parsing this extension");
}
}
Map<String,Extension> invalid = extensions.getUnparseableExtensions();
if (invalid.isEmpty() == false) {
- sb.append("\nUnparseable certificate extensions: " + invalid.size());
+ sb.append("\nUnparseable certificate extensions: ")
+ .append(invalid.size());
int i = 1;
for (Extension ext : invalid.values()) {
- sb.append("\n[" + (i++) + "]: ");
- sb.append(ext);
+ sb.append("\n[")
+ .append(i++)
+ .append("]: ")
+ .append(ext);
}
}
}