public final class MediaType extends Object implements Comparable<MediaType>
Modifier and Type | Field and Description |
---|---|
static MediaType |
all
ALL.
|
static String |
ALL
ALL.
|
static MediaType |
css
TEXT_CSS.
|
static String |
CSS
TEXT_CSS.
|
static MediaType |
form
FORM_URLENCODED.
|
static String |
FORM_URLENCODED
FORM_URLENCODED.
|
static MediaType |
html
TEXT_HTML.
|
static String |
HTML
TEXT_HTML.
|
static MediaType |
js
APPLICATION_JSON.
|
static String |
JS
APPLICATION_JAVASCRIPT.
|
static MediaType |
json
APPLICATION_JSON.
|
static String |
JSON
APPLICATION_JSON.
|
static BinaryOperator<MediaType> |
MOST_SPECIFIC
Computes and returns the most specific media type of both.
|
static MediaType |
multipart
MULTIPART_FORM_DATA.
|
static String |
MULTIPART_FORMDATA
MULTIPART_FORM_DATA.
|
static String |
OCTET_STREAM
APPLICATION_OCTET_STREAM.
|
static MediaType |
octetStream
APPLICATION_OCTET_STREAM.
|
static MediaType |
text
TEXT_PLAIN.
|
static String |
TEXT
TEXT_PLAIN.
|
static MediaType |
xml
APPLICATION_XML.
|
static String |
XML
APPLICATION_XML.
|
static MediaType |
yaml
YAML.
|
static String |
YAML
YAML.
|
Modifier and Type | Method and Description |
---|---|
static MediaType |
byFile(File file)
Mediatype by file extension.
|
static MediaType |
byFile(Path file)
Mediatype by file extension.
|
static MediaType |
byFile(String filename)
Mediatype by file extension.
|
static MediaType |
byFileExtension(String ext)
Mediatype by file extension.
|
int |
compareTo(MediaType other) |
boolean |
equals(Object obj) |
Charset |
getCharset()
Charset or
null . |
String |
getParameter(String name)
Get a parameter that matches the given name or
null . |
float |
getQuality()
Value of
q parameter. |
String |
getSubtype()
Subtype segment of mediatype (trailing type).
|
String |
getType()
Type segment of mediatype (leading type).
|
String |
getValue()
Media type value without parameters.
|
int |
hashCode() |
boolean |
isJson()
Indicates whenever this is a json mediatype.
|
boolean |
isTextual()
Indicates whenever this is a textual mediatype.
|
boolean |
matches(MediaType type)
True if this mediatype is compatible with the given content type.
|
boolean |
matches(String mediaType)
True if this mediatype is compatible with the given content type.
|
static List<MediaType> |
parse(String value)
Parse one or more mediatype values.
|
String |
toContentTypeHeader(Charset charset)
Render a content type header and add the charset parameter (when present).
|
String |
toString() |
static MediaType |
valueOf(String value)
Parse a string value into a media-type.
|
public static final BinaryOperator<MediaType> MOST_SPECIFIC
public static final String JSON
public static final String XML
public static final String TEXT
public static final String HTML
public static final String JS
public static final String CSS
public static final String OCTET_STREAM
public static final String FORM_URLENCODED
public static final String MULTIPART_FORMDATA
public static final String YAML
public static final String ALL
public static final MediaType json
public static final MediaType yaml
public static final MediaType xml
public static final MediaType text
public static final MediaType html
public static final MediaType js
public static final MediaType css
public static final MediaType octetStream
public static final MediaType form
public static final MediaType multipart
public static final MediaType all
@Nullable public String getParameter(@Nonnull String name)
null
.name
- Parameter name.null
.@Nonnull public String getValue()
@Nonnull public String toContentTypeHeader(@Nullable Charset charset)
charset
- Charset.@Nonnull public float getQuality()
q
parameter.q
parameter.public int compareTo(MediaType other)
compareTo
in interface Comparable<MediaType>
public boolean isTextual()
public boolean isJson()
@Nonnull public String getType()
@Nonnull public String getSubtype()
public boolean matches(@Nonnull String mediaType)
mediaType
- Media type to test.public boolean matches(@Nonnull MediaType type)
type
- Media type to test.@Nonnull public static MediaType valueOf(@Nonnull String value)
value
- String media-type.@Nonnull public static List<MediaType> parse(@Nullable String value)
,
.value
- Mediatype comma separated value.@Nonnull public static MediaType byFile(@Nonnull File file)
file
- File.@Nonnull public static MediaType byFile(@Nonnull Path file)
file
- File.@Nonnull public static MediaType byFile(@Nonnull String filename)
filename
- File.@Nonnull public static MediaType byFileExtension(@Nonnull String ext)
ext
- File extension.Copyright © 2023. All rights reserved.