Interface/enum listing standard mime-type constants

前端 未结 11 1988
-上瘾入骨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:16

    As pointed out by an answer above, you can use javax.ws.rs.core.MediaType which has the required constants.

    I also wanted to share a really cool and handy link which I found that gives a reference to all the Javax constants in one place - https://docs.oracle.com/javaee/7/api/constant-values.html.

    0 讨论(0)
  • 2020-12-13 12:18

    There's also a MediaType class in androidannotations in case you want to use with android! See here.

    0 讨论(0)
  • 2020-12-13 12:19

    There is now also the class org.apache.http.entity.ContentType from package org.apache.httpcomponents.httpcore, starting from 4.2 up.

    0 讨论(0)
  • 2020-12-13 12:21

    Java 7 to the rescue!

    You can either pass the file or the file name and it will return the MIME type.

    String mimeType = MimetypesFileTypeMap
        .getDefaultFileTypeMap()
        .getContentType(attachment.getFileName());
    

    http://docs.oracle.com/javase/7/docs/api/javax/activation/MimetypesFileTypeMap.html

    0 讨论(0)
  • 2020-12-13 12:25

    From https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/MediaType.html :

    staticjava.lang.String APPLICATION_ATOM_XML             "application/atom+xml"
    staticMediaType        APPLICATION_ATOM_XML_TYPE        "application/atom+xml"
    staticjava.lang.String APPLICATION_FORM_URLENCODED      "application/x-www-form-urlencoded"
    staticMediaType        APPLICATION_FORM_URLENCODED_TYPE "application/x-www-form-urlencoded"
    staticjava.lang.String APPLICATION_JSON                 "application/json"
    staticMediaType        APPLICATION_JSON_TYPE            "application/json"
    staticjava.lang.String APPLICATION_OCTET_STREAM         "application/octet-stream"
    staticMediaType        APPLICATION_OCTET_STREAM_TYPE    "application/octet-stream"
    staticjava.lang.String APPLICATION_SVG_XML              "application/svg+xml"
    staticMediaType        APPLICATION_SVG_XML_TYPE         "application/svg+xml"
    staticjava.lang.String APPLICATION_XHTML_XML            "application/xhtml+xml"
    staticMediaType        APPLICATION_XHTML_XML_TYPE       "application/xhtml+xml"
    staticjava.lang.String APPLICATION_XML                  "application/xml"
    staticMediaType        APPLICATION_XML_TYPE             "application/xml"
    staticjava.lang.String MEDIA_TYPE_WILDCARD              The value of a type or subtype wildcard: "*"
    staticjava.lang.String MULTIPART_FORM_DATA              "multipart/form-data"
    staticMediaType        MULTIPART_FORM_DATA_TYPE         "multipart/form-data"
    staticjava.lang.String TEXT_HTML                        "text/html"
    staticMediaType        TEXT_HTML_TYPE                   "text/html"
    staticjava.lang.String TEXT_PLAIN                       "text/plain"
    staticMediaType        TEXT_PLAIN_TYPE                  "text/plain"
    staticjava.lang.String TEXT_XML                         "text/xml"
    staticMediaType        TEXT_XML_TYPE                    "text/xml"
    staticjava.lang.String WILDCARD                         "*/*"
    staticMediaType        WILDCARD_TYPE                    "*/*"
    
    0 讨论(0)
提交回复
热议问题