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 "*/*"
If you are using Spring Framework then there is a MediaType class for common content types:
MediaType.TEXT_HTML
MediaType.TEXT_PLAIN
MediaType.TEXT_XML
MediaType.APPLICATION_JSON
MediaType.IMAGE_JPEG
...
We have a Guava class for this: com.google.common.net.MediaType.
It was released with Guava 12 as stated in the source code and in Issue 823. Sources are available, too.
There is now also the class org.apache.http.entity.ContentType from package org.apache.httpcomponents.httpcore, starting from 4.2 up.
javax.ws.rs.core.MediaType from JAX-RS
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
There's also a MediaType class in androidannotations in case you want to use with android! See here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With