private TikaInputStream getTruncatedFile(String name, int n) throws IOException {
        try (InputStream input = getResourceAsStream("/test-documents/" + name)) {
            byte[] bytes = new byte[n];
            int m = 0;
            while (m < bytes.length) {
                int i = input.read(bytes, m, bytes.length - m);
                if (i != -1) {
                    m += i;
                } else {
                    throw new IOException("Unexpected end of stream");
                }
            }
            return TikaInputStream.get(bytes);
        }
    }
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