8179389: X509Certificate generateCRLs is extremely slow using a PEM crl list
authorweijun
Thu, 11 May 2017 07:33:23 +0800
changeset 45063 0909d3bcbacb
parent 45062 37ed4313c8c1
child 45064 b1b45177051b
8179389: X509Certificate generateCRLs is extremely slow using a PEM crl list Reviewed-by: mullan
jdk/src/java.base/share/classes/sun/security/provider/X509Factory.java
--- a/jdk/src/java.base/share/classes/sun/security/provider/X509Factory.java	Wed May 10 15:12:43 2017 -0700
+++ b/jdk/src/java.base/share/classes/sun/security/provider/X509Factory.java	Thu May 11 07:33:23 2017 +0800
@@ -553,8 +553,7 @@
             return bout.toByteArray();
         } else {
             // Read BASE64 encoded data, might skip info at the beginning
-            char[] data = new char[2048];
-            int pos = 0;
+            ByteArrayOutputStream data = new ByteArrayOutputStream();
 
             // Step 1: Read until header is found
             int hyphen = (c=='-') ? 1: 0;   // count of consequent hyphens
@@ -598,7 +597,10 @@
                         end = '\n';
                     } else {
                         end = '\r';
-                        data[pos++] = (char)next;
+                        // Skip all white space chars
+                        if (next != 9 && next != 10 && next != 13 && next != 32) {
+                            data.write(next);
+                        }
                     }
                     break;
                 }
@@ -612,9 +614,9 @@
                     throw new IOException("Incomplete data");
                 }
                 if (next != '-') {
-                    data[pos++] = (char)next;
-                    if (pos >= data.length) {
-                        data = Arrays.copyOf(data, data.length+1024);
+                    // Skip all white space chars
+                    if (next != 9 && next != 10 && next != 13 && next != 32) {
+                        data.write(next);
                     }
                 } else {
                     break;
@@ -635,7 +637,11 @@
 
             checkHeaderFooter(header.toString(), footer.toString());
 
-            return Pem.decode(new String(data, 0, pos));
+            try {
+                return Base64.getDecoder().decode(data.toByteArray());
+            } catch (IllegalArgumentException e) {
+                throw new IOException(e);
+            }
         }
     }