當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaType.getBaseType方法代碼示例

本文整理匯總了Java中org.apache.tika.mime.MediaType.getBaseType方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaType.getBaseType方法的具體用法?Java MediaType.getBaseType怎麽用?Java MediaType.getBaseType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.tika.mime.MediaType的用法示例。


在下文中一共展示了MediaType.getBaseType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: guessMimetype

import org.apache.tika.mime.MediaType; //導入方法依賴的package包/類
/**
 * Uses Tika to try to identify the mimetype of the file, falling back on
 * {@link #guessMimetype(String)} for an extension based one if Tika can't
 * help.
 */
public String guessMimetype(String filename, InputStream input)
{
    MediaType type = detectType(filename, input);
    String filenameGuess = guessMimetype(filename);

    // If Tika doesn't know what the type is, or file is password protected, go with the filename one
    if (type == null || MediaType.OCTET_STREAM.equals(type) || MIMETYPE_ENCRYPTED_OFFICE.equals(type.toString())) { return filenameGuess; }

    // If Tika has supplied a very generic type, go with the filename one,
    // as it's probably a custom Text or XML format known only to Alfresco
    if ((MediaType.TEXT_PLAIN.equals(type) || MediaType.APPLICATION_XML.equals(type)) && (! filenameGuess.equals(MIMETYPE_BINARY)))
    { 
        return filenameGuess; 
    }

    // Alfresco doesn't support mimetype parameters
    // Use the form of the mimetype without any
    if (type.hasParameters())
    {
        type = type.getBaseType();
    }

    // Not all the mimetypes we use are the Tika Canonical one.
    // So, detect when this happens and use ours in preference
    String tikaType = type.toString();
    if (mimetypes.contains(tikaType))
    {
        // Alfresco and Tika agree!
        return tikaType;
    }

    // Check the aliases
    SortedSet<MediaType> aliases = tikaConfig.getMediaTypeRegistry().getAliases(type);
    for (MediaType alias : aliases)
    {
        String aliasType = alias.toString();
        if (mimetypes.contains(aliasType)) { return aliasType; }
    }

    // If we get here, then Tika has identified something that
    // Alfresco doesn't really know about. Just trust Tika on it
    logger.info("Tika detected a type of " + tikaType + " for file " + filename
            + " which Alfresco doesn't know about. Consider " + " adding that type to your configuration");
    return tikaType;
}
 
開發者ID:Alfresco,項目名稱:alfresco-data-model,代碼行數:51,代碼來源:MimetypeMap.java

示例2: parseMediaType

import org.apache.tika.mime.MediaType; //導入方法依賴的package包/類
private MediaType parseMediaType(String mediaTypeStr) {
  MediaType mediaType = MediaType.parse(mediaTypeStr.trim().toLowerCase(Locale.ROOT));
  return mediaType.getBaseType();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:5,代碼來源:SolrCellBuilder.java


注:本文中的org.apache.tika.mime.MediaType.getBaseType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。