public void parse(
InputStream stream, ContentHandler ignored,
Metadata metadata, ParseContext context)
throws IOException, SAXException, TikaException {
TemporaryFiles tmp = new TemporaryFiles();
try {
TikaInputStream tis = TikaInputStream.get(stream, tmp);
// Figure out what we have to process
String filename = metadata.get(Metadata.RESOURCE_NAME_KEY);
MediaType type = detector.detect(tis, metadata);
if (extractor == null) {
// Let the handler process the embedded resource
handler.handle(filename, type, tis);
} else {
// Use a temporary file to process the stream twice
File file = tis.getFile();
// Let the handler process the embedded resource
handler.handle(filename, type, TikaInputStream.get(file));
// Recurse
extractor.extract(tis, extractor, handler);
}
} finally {
tmp.dispose();
}
}