Interface/enum listing standard mime-type constants

前端 未结 11 1995
-上瘾入骨i
-上瘾入骨i 2020-12-13 11:35

I am looking among the standard libraries (like apache commons, jax, jboss, javax) for an interface or enum that lists the values of all the standard mime-type (aka content-

11条回答
  •  一向
    一向 (楼主)
    2020-12-13 12:01

    If you're on android you have multiple choices, where only the first is a kind of "enum":

    • HTTP (which has been deprecated in API 22), for example
      HTTP.PLAIN_TEXT_TYPE or
    • MimeTypeMap, for example
      final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
      See also FileProvider.getType().
    • URLConnection that provides the following methods:
      • guessContentTypeFromStream(InputStream is)
      • guessContentTypeFromName(String url)
      • getFileNameMap()

    For example

    @Override
    public String getType(Uri uri) {
        return URLConnection.getFileNameMap().getContentTypeFor(
                uri.getLastPathSegment());
    }
    

提交回复
热议问题