public String getExtension(TikaInputStream is, Metadata metadata) {
        String mimeString = metadata.get(Metadata.CONTENT_TYPE);

        //use the buffered mimetypes as default
        MimeTypes localMimeTypes = getMimeTypes();

        MimeType mimeType = null;
        boolean detected = false;
        if (mimeString != null) {
            try {
                mimeType = localMimeTypes.forName(mimeString);
            } catch (MimeTypeException e) {
                //swallow
            }
        }
        if (mimeType == null) {
            try {
                MediaType mediaType = getDetector().detect(is, metadata);
                mimeType = localMimeTypes.forName(mediaType.toString());
                detected = true;
                is.reset();
            } catch (IOException | MimeTypeException e) {
                //swallow
            }
        }
        if (mimeType != null) {
            if (detected) {
                //set or correct the mime type
                metadata.set(Metadata.CONTENT_TYPE, mimeType.toString());
            }
            return mimeType.getExtension();
        }
        return ".bin";
    }
@return Returns a {@link TikaConfig} -- trying to find it first in the ParseContext
that was included during initialization, and then creating a new one from
via {@link TikaConfig#getDefaultConfig()} if it can't find one in the
ParseContext. This caches the default config so that it only has to be created once.
tika-core/src/main/java/org/apache/tika/extractor/EmbeddedDocumentUtil.java