8049244: XML Signature performance issue caused by unbuffered signature data
Reviewed-by: xuelei
--- a/jdk/src/share/classes/org/jcp/xml/dsig/internal/dom/DOMSignedInfo.java Mon Jul 07 15:06:00 2014 +0200
+++ b/jdk/src/share/classes/org/jcp/xml/dsig/internal/dom/DOMSignedInfo.java Tue Jul 08 14:35:05 2014 -0400
@@ -221,8 +221,17 @@
}
OutputStream os = new UnsyncBufferedOutputStream(bos);
+
+ DOMSubTreeData subTree = new DOMSubTreeData(localSiElem, true);
try {
- os.close();
+ ((DOMCanonicalizationMethod)
+ canonicalizationMethod).canonicalize(subTree, context, os);
+ } catch (TransformException te) {
+ throw new XMLSignatureException(te);
+ }
+
+ try {
+ os.flush();
} catch (IOException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, e.getMessage(), e);
@@ -230,15 +239,6 @@
// Impossible
}
- DOMSubTreeData subTree = new DOMSubTreeData(localSiElem, true);
-
- try {
- ((DOMCanonicalizationMethod)
- canonicalizationMethod).canonicalize(subTree, context, bos);
- } catch (TransformException te) {
- throw new XMLSignatureException(te);
- }
-
byte[] signedInfoBytes = bos.toByteArray();
// this whole block should only be done if logging is enabled
@@ -253,6 +253,15 @@
}
this.canonData = new ByteArrayInputStream(signedInfoBytes);
+
+ try {
+ os.close();
+ } catch (IOException e) {
+ if (log.isLoggable(java.util.logging.Level.FINE)) {
+ log.log(java.util.logging.Level.FINE, e.getMessage(), e);
+ }
+ // Impossible
+ }
}
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)