Package org.apache.tika.mime
Class MediaType
- java.lang.Object
-
- org.apache.tika.mime.MediaType
-
- All Implemented Interfaces:
Serializable,Comparable<MediaType>
public final class MediaType extends Object implements Comparable<MediaType>, Serializable
Internet media type.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static MediaTypeAPPLICATION_XMLstatic MediaTypeAPPLICATION_ZIPstatic MediaTypeEMPTYstatic MediaTypeOCTET_STREAMstatic MediaTypeTEXT_HTMLstatic MediaTypeTEXT_PLAIN
-
Constructor Summary
Constructors Constructor Description MediaType(String type, String subtype)MediaType(String type, String subtype, Map<String,String> parameters)MediaType(MediaType type, String name, String value)Creates a media type by adding a parameter to a base type.MediaType(MediaType type, Charset charset)Creates a media type by adding the "charset" parameter to a base type.MediaType(MediaType type, Map<String,String> parameters)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MediaTypeapplication(String type)static MediaTypeaudio(String type)intcompareTo(MediaType that)booleanequals(Object object)MediaTypegetBaseType()Returns the base form of the MediaType, excluding any parameters, such as "text/plain" for "text/plain; charset=utf-8"Map<String,String>getParameters()Returns an immutable sorted map of the parameters of this media type.StringgetSubtype()Return the Sub-Type of the MediaType, such as "plain" for "text/plain"StringgetType()Return the Type of the MediaType, such as "text" for "text/plain"inthashCode()booleanhasParameters()Checks whether this media type contains parameters.static MediaTypeimage(String type)static MediaTypeparse(String string)Parses the given string to a media type.static Set<MediaType>set(String... types)Convenience method that parses the given media type strings and returns an unmodifiable set that contains all the parsed types.static Set<MediaType>set(MediaType... types)Convenience method that returns an unmodifiable set that contains all the given media types.static MediaTypetext(String type)StringtoString()static MediaTypevideo(String type)
-
-
-
Field Detail
-
OCTET_STREAM
public static final MediaType OCTET_STREAM
-
EMPTY
public static final MediaType EMPTY
-
TEXT_PLAIN
public static final MediaType TEXT_PLAIN
-
TEXT_HTML
public static final MediaType TEXT_HTML
-
APPLICATION_XML
public static final MediaType APPLICATION_XML
-
APPLICATION_ZIP
public static final MediaType APPLICATION_ZIP
-
-
Method Detail
-
set
public static Set<MediaType> set(MediaType... types)
Convenience method that returns an unmodifiable set that contains all the given media types.- Parameters:
types- media types- Returns:
- unmodifiable set of the given types
- Since:
- Apache Tika 1.2
-
set
public static Set<MediaType> set(String... types)
Convenience method that parses the given media type strings and returns an unmodifiable set that contains all the parsed types.- Parameters:
types- media type strings- Returns:
- unmodifiable set of the parsed types
- Since:
- Apache Tika 1.2
-
parse
public static MediaType parse(String string)
Parses the given string to a media type. The string is expected to be of the form "type/subtype(; parameter=...)*" as defined in RFC 2045, though we also handle "charset=xxx; type/subtype" for broken web servers.- Parameters:
string- media type string to be parsed- Returns:
- parsed media type, or
nullif parsing fails
-
getBaseType
public MediaType getBaseType()
Returns the base form of the MediaType, excluding any parameters, such as "text/plain" for "text/plain; charset=utf-8"
-
getType
public String getType()
Return the Type of the MediaType, such as "text" for "text/plain"
-
getSubtype
public String getSubtype()
Return the Sub-Type of the MediaType, such as "plain" for "text/plain"
-
hasParameters
public boolean hasParameters()
Checks whether this media type contains parameters.- Returns:
trueif this type has one or more parameters,falseotherwise- Since:
- Apache Tika 0.8
-
getParameters
public Map<String,String> getParameters()
Returns an immutable sorted map of the parameters of this media type. The parameter names are guaranteed to be trimmed and in lower case.- Returns:
- sorted map of parameters
-
compareTo
public int compareTo(MediaType that)
- Specified by:
compareToin interfaceComparable<MediaType>
-
-