public void parse(
InputStream stream, ContentHandler handler,
Metadata metadata, ParseContext context)
throws IOException, SAXException, TikaException {
try {
CMSSignedDataParser parser =
new CMSSignedDataParser(new CloseShieldInputStream(stream));
try {
CMSTypedStream content = parser.getSignedContent();
if (content == null) {
throw new TikaException("cannot parse detached pkcs7 signature (no signed data to parse)");
}
InputStream input = content.getContentStream();
try {
Parser delegate =
context.get(Parser.class, EmptyParser.INSTANCE);
delegate.parse(input, handler, metadata, context);
} finally {
input.close();
}
} finally {
parser.close();
}
} catch (CMSException e) {
throw new TikaException("Unable to parse pkcs7 signed data", e);
}
}