@Test
    public void testTruncatedFiles() throws Exception {
        // First up a truncated OOXML (zip) file

        // With only the data supplied, the best we can do is the container
        Metadata m = new Metadata();
        try (TikaInputStream xlsx = getTruncatedFile("testEXCEL.xlsx", 300)) {
            assertEquals(MediaType.application("x-tika-ooxml"), detector.detect(xlsx, m));
        }

        // With truncated data + filename, we can use the filename to specialise
        m = new Metadata();
        m.add(TikaCoreProperties.RESOURCE_NAME_KEY, "testEXCEL.xlsx");
        try (TikaInputStream xlsx = getTruncatedFile("testEXCEL.xlsx", 300)) {
            assertEquals(
                    MediaType.application("vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
                    detector.detect(xlsx, m));
        }

        // Now a truncated OLE2 file 
        m = new Metadata();
        try (TikaInputStream xls = getTruncatedFile("testEXCEL.xls", 400)) {
            assertEquals(MediaType.application("x-tika-msoffice"), detector.detect(xls, m));
        }

        // Finally a truncated OLE2 file, with a filename available
        m = new Metadata();
        m.add(TikaCoreProperties.RESOURCE_NAME_KEY, "testEXCEL.xls");
        try (TikaInputStream xls = getTruncatedFile("testEXCEL.xls", 400)) {
            assertEquals(MediaType.application("vnd.ms-excel"), detector.detect(xls, m));
        }
    }
Check that temporary files created by Tika are removed after
closing TikaInputStream.
tika-parsers/tika-parsers-standard/tika-parsers-standard-package/src/test/java/org/apache/tika/detect/TestContainerAwareDetector.java