Package ratpack.http
Interface MediaType
-
public interface MediaTypeA structured value for a Content-Type header value.Can also represent a non existent (i.e. empty) value.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringAPPLICATION_FORM"application/x-www-form-urlencoded".static java.lang.StringAPPLICATION_JSON"application/json".static java.lang.StringJSON_SUFFIX"+json".static java.lang.StringPLAIN_TEXT_UTF8"text/plain;charset=utf-8".static java.lang.StringTEXT_HTML"text/html".
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.StringgetCharset()The value of the "charset" parameter.java.lang.StringgetCharset(java.lang.String defaultValue)The value of the "charset" parameter, or the given default value of no charset was specified.com.google.common.collect.ImmutableListMultimap<java.lang.String,java.lang.String>getParams()The multimap containing parameters of the mime type.java.lang.StringgetType()The type without parameters.booleanisEmpty()True if this represents the absence of a value (i.e.booleanisForm()True if this type equals "application/x-www-form-urlencoded".booleanisHtml()True if this type equals "text/html".booleanisJson()True if this type equals "application/json", or ends with "+json".booleanisText()True if this type starts with "text/".
-
-
-
Field Detail
-
PLAIN_TEXT_UTF8
static final java.lang.String PLAIN_TEXT_UTF8
"text/plain;charset=utf-8".- See Also:
- Constant Field Values
-
APPLICATION_JSON
static final java.lang.String APPLICATION_JSON
"application/json".- See Also:
- Constant Field Values
-
JSON_SUFFIX
static final java.lang.String JSON_SUFFIX
"+json".- See Also:
- Constant Field Values
-
APPLICATION_FORM
static final java.lang.String APPLICATION_FORM
"application/x-www-form-urlencoded".- See Also:
- Constant Field Values
-
TEXT_HTML
static final java.lang.String TEXT_HTML
"text/html".- See Also:
- Constant Field Values
-
-
Method Detail
-
getType
@Nullable java.lang.String getType()
The type without parameters.Given a mime type of "text/plain;charset=utf-8", returns "text/plain".
May be null to represent no content type.
- Returns:
- The mime type without parameters, or null if this represents the absence of a value.
-
getParams
com.google.common.collect.ImmutableListMultimap<java.lang.String,java.lang.String> getParams()
The multimap containing parameters of the mime type.Given a mime type of "application/json;charset=utf-8", the
get("charset")returns["utf-8"]". May be empty, never null.All param names have been lower cased. The
charsetparameter values has been lower cased too.- Returns:
- the immutable multimap of the media type params.
-
getCharset
@Nullable java.lang.String getCharset()
The value of the "charset" parameter.- Returns:
- the value of the charset parameter, or
nullif the no charset parameter was specified
-
getCharset
java.lang.String getCharset(java.lang.String defaultValue)
The value of the "charset" parameter, or the given default value of no charset was specified.- Parameters:
defaultValue- the value if this type has no charset- Returns:
- the value of the charset parameter, or the given default
-
isText
boolean isText()
True if this type starts with "text/".- Returns:
- True if this type starts with "
text/".
-
isJson
boolean isJson()
True if this type equals "application/json", or ends with "+json".- Returns:
- if this represents a JSON like type
-
isForm
boolean isForm()
True if this type equals "application/x-www-form-urlencoded".- Returns:
- True if this type equals "application/x-www-form-urlencoded".
-
isHtml
boolean isHtml()
True if this type equals "text/html".- Returns:
- True if this type equals "text/html".
-
isEmpty
boolean isEmpty()
True if this represents the absence of a value (i.e. no Content-Type header)- Returns:
- True if this represents the absence of a value (i.e. no Content-Type header)
-
-