private MediaType detectOnPath(Path path, Metadata metadata) throws IOException {

        String[] args =
                new String[]{ProcessUtils.escapeCommandLine(fileCommandPath), "-b", "--mime-type",
                        ProcessUtils.escapeCommandLine(path.toAbsolutePath().toString())};
        ProcessBuilder builder = new ProcessBuilder(args);
        FileProcessResult result = ProcessUtils.execute(builder, timeoutMs, 10000, 10000);
        if (result.isTimeout()) {
            metadata.set(ExternalProcess.IS_TIMEOUT, true);
            return MediaType.OCTET_STREAM;
        }
        if (result.getExitValue() != 0) {
            metadata.set(ExternalProcess.EXIT_VALUE, result.getExitValue());
            return MediaType.OCTET_STREAM;
        }
        String mimeString = result.getStdout();
        if (StringUtils.isBlank(mimeString)) {
            return MediaType.OCTET_STREAM;
        }
        metadata.set(FILE_MIME, mimeString);
        if (useMime) {
            MediaType mt = MediaType.parse(mimeString);
            if (mt == null) {
                return MediaType.OCTET_STREAM;
            } else {
                return mt;
            }
        }
        return MediaType.OCTET_STREAM;
    }
@param input    document input stream, or <code>null</code>
@param metadata input metadata for the document
@return mime as identified by the file command or application/octet-stream otherwise
@throws IOException
tika-core/src/main/java/org/apache/tika/detect/FileCommandDetector.java