protected static MediaType processResult(FileProcessResult result, Metadata metadata,
                                             boolean returnMime) {
        metadata.set(ExternalProcess.EXIT_VALUE, result.getExitValue());
        metadata.set(ExternalProcess.IS_TIMEOUT, result.isTimeout());

        if (result.isTimeout()) {
            metadata.set(SIEGFRIED_STATUS, STATUS.TIMEOUT.name());
            return MediaType.OCTET_STREAM;
        }
        if (result.getExitValue() != 0) {
            metadata.set(SIEGFRIED_STATUS, STATUS.CRASH.name());
            return MediaType.OCTET_STREAM;
        }
        JsonNode root;
        try {
            root = OBJECT_MAPPER.readTree(result.getStdout());
        } catch (JsonProcessingException e) {
            metadata.set(SIEGFRIED_STATUS, STATUS.JSON_PARSE_EXCEPTION.name());
            return MediaType.OCTET_STREAM;
        }

        if (root.has("siegfried")) {
            String siegfriedVersion = root.get("siegfried").asText(StringUtils.EMPTY);
            metadata.set(SIEGFRIED_VERSION, siegfriedVersion);
        }

        if (root.has("signature")) {
            String sig = root.get("signature").asText(StringUtils.EMPTY);
            metadata.set(SIEGFRIED_SIGNATURE, sig);
        }

        if (root.has("identifiers")) {
            for (JsonNode n : root.get("identifiers")) {
                if (n.has("name") && n.has("details")) {
                    String name = n.get("name").asText(StringUtils.EMPTY);
                    String details = n.get("details").asText(StringUtils.EMPTY);
                    metadata.add(SIEGFRIED_IDENTIFIERS_NAME, name);
                    metadata.add(SIEGFRIED_IDENTIFIERS_DETAILS, details);
                }
            }
        }
        MediaType mt = MediaType.OCTET_STREAM;
        if (root.has("files")) {
            for (JsonNode file : root.get("files")) {

                if (file.has(ERRORS)) {
                    JsonNode errors = file.get(ERRORS);
                    if (errors.isTextual()) {
                        metadata.add(SIEGFRIED_ERRORS, file.get(ERRORS).asText());
                    } else if (errors.isArray()) {
                        //is this even possible?!
                        for (JsonNode e : errors) {
                            metadata.add(SIEGFRIED_ERRORS, e.asText());
                        }
                    }
                }
                for (JsonNode match : file.get("matches")) {
                    String ns = match.has("ns") ? match.get("ns").asText(StringUtils.EMPTY) :
                            StringUtils.EMPTY;
                    addNotBlank(match, "basis", metadata, SIEGFRIED_PREFIX + ns + ":" + BASIS);
                    addNotBlank(match, "format", metadata, SIEGFRIED_PREFIX + ns + ":" + FORMAT);
                    addNotBlank(match, "id", metadata, SIEGFRIED_PREFIX + ns + ":" + ID);
                    addNotBlank(match, "mime", metadata, SIEGFRIED_PREFIX + ns + ":" + MIME);
                    addNotBlank(match, "version", metadata, SIEGFRIED_PREFIX + ns + ":" + VERSION);
                    addNotBlank(match, "warning", metadata, SIEGFRIED_PREFIX + ns + ":" + WARNING);

                    //take the first non-octet-stream
                    if (returnMime && mt.equals(MediaType.OCTET_STREAM)) {
                        if (match.has("mime")) {
                            String mimeString = match.get("mime").asText(StringUtils.EMPTY);
                            mt = MediaType.parse(mimeString);
                            if (mt == null) {
                                mt = MediaType.OCTET_STREAM;
                            }
                        }
                    }
                }
            }
        }
        return mt;
    }
As default behavior, Tika runs Siegfried to add its detection
to the metadata, but NOT to use detection in determining parsers
etc.  If this is set to <code>true</code>, this detector
will return the first mime detected by Siegfried and that
mime will be used by the AutoDetectParser to select the appropriate
parser.

@param useMime
tika-detectors/tika-detector-siegfried/src/main/java/org/apache/tika/detect/siegfried/SiegfriedDetector.java