--- 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)) {