src/java.base/share/classes/sun/security/x509/AVA.java

Print this page
rev 10521 : 8055723[core]: Replace concat String to append in StringBuilder parameters
Contributed-by: Otavio Santana <otaviojava@java.net>

*** 1060,1070 **** } } else { boolean quoteNeeded = false; ! StringBuilder sbuffer = new StringBuilder(); boolean previousWhite = false; final String escapees = ",+=\n<>#;\\\""; /* * Special characters (e.g. AVA list separators) cause strings --- 1060,1070 ---- } } else { boolean quoteNeeded = false; ! StringBuilder sb = new StringBuilder(); boolean previousWhite = false; final String escapees = ",+=\n<>#;\\\""; /* * Special characters (e.g. AVA list separators) cause strings
*** 1077,1087 **** && 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); continue; } if (DerValue.isPrintableStringChar(c) || escapees.indexOf(c) >= 0) { --- 1077,1087 ---- && valStr.charAt(length - 1) == '\"'); for (int i = 0; i < length; i++) { char c = valStr.charAt(i); if (alreadyQuoted && (i == 0 || i == length - 1)) { ! sb.append(c); continue; } if (DerValue.isPrintableStringChar(c) || escapees.indexOf(c) >= 0) {
*** 1094,1114 **** // quote if multiple internal whitespace if (!(c == ' ' || c == '\n')) { // escape '"' and '\' if (c == '"' || c == '\\') { ! sbuffer.append('\\'); } previousWhite = false; } else { if (!quoteNeeded && previousWhite) { quoteNeeded = true; } previousWhite = true; } ! sbuffer.append(c); } else if (debug != null && Debug.isOn("ava")) { // embed non-printable/non-escaped char // as escaped hex pairs for debugging --- 1094,1114 ---- // quote if multiple internal whitespace if (!(c == ' ' || c == '\n')) { // escape '"' and '\' if (c == '"' || c == '\\') { ! sb.append('\\'); } previousWhite = false; } else { if (!quoteNeeded && previousWhite) { quoteNeeded = true; } previousWhite = true; } ! sb.append(c); } else if (debug != null && Debug.isOn("ava")) { // embed non-printable/non-escaped char // as escaped hex pairs for debugging
*** 1117,1157 **** // embed escaped hex pairs byte[] valueBytes = Character.toString(c).getBytes("UTF8"); for (int j = 0; j < valueBytes.length; j++) { ! sbuffer.append('\\'); char hexChar = Character.forDigit (0xF & (valueBytes[j] >>> 4), 16); ! sbuffer.append(Character.toUpperCase(hexChar)); hexChar = Character.forDigit (0xF & (valueBytes[j]), 16); ! sbuffer.append(Character.toUpperCase(hexChar)); } } else { // append non-printable/non-escaped char previousWhite = false; ! sbuffer.append(c); } } // quote if trailing whitespace ! if (sbuffer.length() > 0) { ! char trailChar = sbuffer.charAt(sbuffer.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() + "\""); } else { ! retval.append(sbuffer.toString()); } } } catch (IOException e) { throw new IllegalArgumentException("DER Value conversion"); } --- 1117,1157 ---- // embed escaped hex pairs byte[] valueBytes = Character.toString(c).getBytes("UTF8"); for (int j = 0; j < valueBytes.length; j++) { ! sb.append('\\'); char hexChar = Character.forDigit (0xF & (valueBytes[j] >>> 4), 16); ! sb.append(Character.toUpperCase(hexChar)); hexChar = Character.forDigit (0xF & (valueBytes[j]), 16); ! sb.append(Character.toUpperCase(hexChar)); } } else { // append non-printable/non-escaped char previousWhite = false; ! sb.append(c); } } // quote if trailing whitespace ! 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('"').append(sb).append('"'); } else { ! retval.append(sb); } } } catch (IOException e) { throw new IllegalArgumentException("DER Value conversion"); }