@Override
    public MediaType detect(ZipFile zipFile, TikaInputStream stream) throws IOException {
        MediaType type = null;


        //as of 4.x, POI throws an exception for non-POI OPC file types
        //unless we change POI, we can't rely on POI for non-POI files
        ZipEntrySource zipEntrySource =
                new CloseShieldZipFileZipEntrySource(zipFile);

        //in POI 5.2.0, if there's an exception during detection,
        //close() is called on the pkg instead of revert(), which leads
        //to needless logging. Do a preliminary test for OPC now.
        if (zipEntrySource.getEntry("[Content_Types].xml") == null) {
            return type;
        }
        // Use POI to open and investigate it for us
        //Unfortunately, POI can throw a RuntimeException...so we
        //have to catch that.
        OPCPackage pkg = null;
        try {
            pkg = OPCPackage.open(zipEntrySource);
            type = detectOfficeOpenXML(pkg);
        } catch (SecurityException e) {
            IOUtils.closeQuietly(zipEntrySource);
            //TIKA-2571
            throw e;
        } catch (InvalidFormatException | RuntimeException e) {
            //no need to close zipEntrySource because it
            //only closes the underlying zipFile, not any other resources
            //as of this writing.... :'(
            return null;
        }
        //this will now be closed eventually when the wrapper closes
        //the pkg which will close this
        ((CloseShieldZipFileZipEntrySource)zipEntrySource).allowClose();
        //only set the open container if we made it here
        stream.setOpenContainer(new OPCPackageWrapper(pkg));
        return type;
    }
Detects the type of an OfficeOpenXML (OOXML) file from
opened Package
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/detect/microsoft/ooxml/OPCPackageDetector.java