protected void verifyExternalReference(InputProcessorChain inputProcessorChain, InputStream inputStream,
ReferenceType referenceType) throws XMLSecurityException, XMLStreamException {
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
try {
DigestOutputStream digestOutputStream =
createMessageDigestOutputStream(referenceType, inputProcessorChain.getSecurityContext());
UnsynchronizedBufferedOutputStream bufferedDigestOutputStream =
new UnsynchronizedBufferedOutputStream(digestOutputStream);
if (referenceType.getTransforms() != null) {
Transformer transformer =
buildTransformerChain(referenceType, bufferedDigestOutputStream, inputProcessorChain, null);
transformer.transform(bufferedInputStream);
bufferedDigestOutputStream.close();
} else {
XMLSecurityUtils.copy(bufferedInputStream, bufferedDigestOutputStream);
bufferedDigestOutputStream.close();
}
compareDigest(digestOutputStream.getDigestValue(), referenceType);
} catch (IOException e) {
throw new XMLSecurityException(e);
} finally {
try {
bufferedInputStream.close();