ExtractorFactory.setThreadPrefersEventExtractors(true);
try {
OOXMLExtractor extractor;
POIXMLTextExtractor poiExtractor;
TikaInputStream tis = TikaInputStream.cast(stream);
if (tis != null && tis.getOpenContainer() instanceof OPCPackage) {
poiExtractor = ExtractorFactory.createExtractor(
(OPCPackage) tis.getOpenContainer());
} else if (tis != null && tis.hasFile()) {
poiExtractor = (POIXMLTextExtractor)
ExtractorFactory.createExtractor(tis.getFile());
} else {
InputStream shield = new CloseShieldInputStream(stream);
poiExtractor = (POIXMLTextExtractor)
ExtractorFactory.createExtractor(shield);
}
POIXMLDocument document = poiExtractor.getDocument();
if (poiExtractor instanceof XSSFEventBasedExcelExtractor) {
extractor = new XSSFExcelExtractorDecorator(
context, (XSSFEventBasedExcelExtractor)poiExtractor, locale);
} else if (document == null) {
throw new TikaException(