jdk/src/share/classes/sun/security/tools/KeyTool.java
changeset 2289 99207c64bf80
parent 2179 e172c13ca87a
child 2293 cb6d01cb3c3d
--- a/jdk/src/share/classes/sun/security/tools/KeyTool.java	Wed Mar 18 17:37:39 2009 -0700
+++ b/jdk/src/share/classes/sun/security/tools/KeyTool.java	Thu Mar 19 11:17:06 2009 +0800
@@ -875,6 +875,18 @@
             if (filename != null) {
                 inStream = new FileInputStream(filename);
             }
+            // Read the full stream before feeding to X509Factory,
+            // otherwise, keytool -gencert | keytool -importcert
+            // might not work properly, since -gencert is slow
+            // and there's no data in the pipe at the beginning.
+            ByteArrayOutputStream bout = new ByteArrayOutputStream();
+            byte[] b = new byte[4096];
+            while (true) {
+                int len = inStream.read(b);
+                if (len < 0) break;
+                bout.write(b, 0, len);
+            }
+            inStream = new ByteArrayInputStream(bout.toByteArray());
             try {
                 String importAlias = (alias!=null)?alias:keyAlias;
                 if (keyStore.entryInstanceOf(importAlias, KeyStore.PrivateKeyEntry.class)) {