Package org.apache.juneau
Class MediaType
java.lang.Object
org.apache.juneau.MediaType
- All Implemented Interfaces:
- Comparable<MediaType>
- Direct Known Subclasses:
- MediaRange
Describes a single media type used in content negotiation between an HTTP client and server, as described in
 Section 14.1 and 14.7 of RFC2616 (the HTTP/1.1 specification).
 
See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final MediaTypeReusable predefined media typestatic final MediaTypeRepresents an empty media type object.static final MediaTypeReusable predefined media typestatic final MediaTypeReusable predefined media typestatic final MediaTypeReusable predefined media typestatic final MediaTypeReusable predefined media typestatic final MediaTypeReusable predefined media typestatic final MediaTypeReusable predefined media typestatic final MediaTypeReusable predefined media typestatic final MediaTypeReusable predefined media typestatic final MediaTypeReusable predefined media typestatic final MediaTypeReusable predefined media typestatic final MediaTypeReusable predefined media typestatic final MediaTypeReusable predefined media typestatic final MediaTypeReusable predefined media type
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor.MediaType(String mt, NameValuePair[] parameters) Constructor.Constructor.MediaType(HeaderElement e, NameValuePair[] parameters) Constructor.
- 
Method SummaryModifier and TypeMethodDescriptionfinal intbooleanforEachParameter(Consumer<NameValuePair> action) Performs an action on the additional parameters on this media type.final MediaTypeforEachSubType(Consumer<String> action) Performs an action on the subtypes broken down by fragments delimited by"'" .getParameter(String name) Returns the additional parameter on this media type.Returns the additional parameters on this media type.final StringReturns the'subType' fragment of the'type/subType' string.Returns the subtypes broken down by fragments delimited by"'" .final StringgetType()Returns the'type' fragment of the'type/subType' string.inthashCode()final booleanhasSubType(String st) Returnstrue if the subtype contains the specified'+' delimited subtype value.final booleanReturnstrue if this media type subtype contains the'*' meta character.intGiven a list of media types, returns the best match for thisContent-Type header.final intReturns a match metric against the specified media type where a larger number represents a better match.static MediaTypeReturns the media type for the specified string.static MediaTypeof(String value, NameValuePair... parameters) Same asof(String)but allows you to specify the parameters.static MediaType[]Same asof(String)but allows you to construct an array ofMediaTypes from an array of strings.toString()
- 
Field Details- 
EMPTYRepresents an empty media type object.
- 
CSVReusable predefined media type
- 
HTMLReusable predefined media type
- 
JSONReusable predefined media type
- 
MSGPACKReusable predefined media type
- 
PLAINReusable predefined media type
- 
UONReusable predefined media type
- 
URLENCODINGReusable predefined media type
- 
XMLReusable predefined media type
- 
XMLSOAPReusable predefined media type
- 
RDFReusable predefined media type
- 
RDFABBREVReusable predefined media type
- 
NTRIPLEReusable predefined media type
- 
TURTLEReusable predefined media type
- 
N3Reusable predefined media type
 
- 
- 
Constructor Details- 
MediaTypeConstructor.- Parameters:
- mt- The media type string.
 
- 
MediaTypeConstructor.- Parameters:
- mt- The media type string.
- parameters- The media type parameters. If- null , they're pulled from the media type string.
 
- 
MediaTypeConstructor.- Parameters:
- e- The parsed media type string.
 
- 
MediaTypeConstructor.- Parameters:
- e- The parsed media type string.
- parameters- Optional parameters.
 
 
- 
- 
Method Details- 
ofReturns the media type for the specified string. The same media type strings always return the same objects so that these objects can be compared for equality using '=='.Notes:- 
      Spaces are replaced with '+' characters. This gets around the issue where passing media type strings with'+' as HTTP GET parameters get replaced with spaces by your browser. Since spaces aren't supported by the spec, this is doesn't break anything.
- 
      Anything including and following the ';' character is ignored (e.g.";charset=X" ).
 - Parameters:
- value- The media type string. Will be lowercased. Returns- null if input is null or empty.
- Returns:
- A cached media type object.
 
- 
      Spaces are replaced with 
- 
ofSame asof(String)but allows you to specify the parameters.- Parameters:
- value- The media type string. Will be lowercased. Returns- null if input is null or empty.
- parameters- The media type parameters. If- null , they're pulled from the media type string.
- Returns:
- A new media type object, cached if parameters were not specified.
 
- 
ofAllSame asof(String)but allows you to construct an array ofMediaTypes from an array of strings.- Parameters:
- values- The media type strings.
- Returns:
- An array of MediaType objects.
 Always the same length as the input string array.
 
- 
getTypeReturns the'type' fragment of the'type/subType' string.- Returns:
- The media type.
 
- 
getSubTypeReturns the'subType' fragment of the'type/subType' string.- Returns:
- The media subtype.
 
- 
hasSubTypeReturnstrue if the subtype contains the specified'+' delimited subtype value.- Parameters:
- st- The subtype string. Case is ignored.
- Returns:
- true if the subtype contains the specified subtype string.
 
- 
getSubTypesReturns the subtypes broken down by fragments delimited by"'" .For example, the media type "text/foo+bar" will return a list of['foo' ,'bar' ]- Returns:
- An unmodifiable list of subtype fragments.  Never null .
 
- 
forEachSubTypePerforms an action on the subtypes broken down by fragments delimited by"'" .- Parameters:
- action- The action to perform.
- Returns:
- This object.
 
- 
isMetaSubtypeReturnstrue if this media type subtype contains the'*' meta character.- Returns:
- true if this media type subtype contains the- '*' meta character.
 
- 
matchReturns a match metric against the specified media type where a larger number represents a better match.This media type can contain '*' metacharacters.
 The comparison media type must not.- Exact matches (e.g. "text/json" /"text/json") should match better than meta-character matches (e.g."text/*" /"text/json")
- The comparison media type can have additional subtype tokens (e.g. "text/json+foo" ) that will not prevent a match if theallowExtraSubTypes flag is set. The reverse is not true, e.g. the comparison media type must contain all subtype tokens found in the comparing media type.- We want the JsonSerializer("text/json" ) class to be able to handle requests for"text/json+foo" .
- We want to make sure Json5Serializer("text/json5" ) does not handle requests for"text/json" .
 
- We want the 
 type/subTypes :- An exact match is 100,000 .
- Add the following for type (assuming subtype match is <0):
   - 10,000 for an exact match (e.g.- "text" ==- "text" ).
- 5,000 for a meta match (e.g.- "*" ==- "text" ).
 
- Add the following for subtype (assuming type match is <0):
   - 7,500 for an exact match (e.g.- "json+foo" ==- "json+foo" or- "json+foo" ==- "foo+json" )
- 100 for every subtype entry match (e.g.- "json" /- "json+foo" )
 
 - Parameters:
- o- The media type to compare with.
- allowExtraSubTypes- If- true ,
- Returns:
- true if the media types match.
 
- Exact matches (e.g. 
- 
getParametersReturns the additional parameters on this media type.For example, given the media type string "text/html;level=1" , will return a map with the single entry{level:[.'1' ]}- Returns:
- The map of additional parameters, or an empty map if there are no parameters.
 
- 
forEachParameterPerforms an action on the additional parameters on this media type.- Parameters:
- action- The action to perform.
- Returns:
- This object.
 
- 
getParameterReturns the additional parameter on this media type.- Parameters:
- name- The additional parameter name.
- Returns:
- The parameter value, or null if not found.
 
- 
matchGiven a list of media types, returns the best match for thisContent-Type header.Note that fuzzy matching is allowed on the media types where the Content-Types header may contain additional subtype parts.
 For example, given aContent-Type value of"text/json+activity" , the media type"text/json" will match if"text/json+activity" or"text/activity+json" isn't found.
 The purpose for this is to allow parsers to match when artifacts such asid properties are present in the header.- Parameters:
- mediaTypes- The media types to match against.
- Returns:
- The index into the array of the best match, or -1 if no suitable matches could be found.
 
- 
toString
- 
hashCode
- 
equals
- 
compareTo- Specified by:
- compareToin interface- Comparable<MediaType>
 
 
-