Package com.nimbusds.common.contenttype
Class ContentType
- java.lang.Object
-
- com.nimbusds.common.contenttype.ContentType
-
public final class ContentType extends Object
Content (media) type.To create a new content type
application/jsonwithout character set parameter:ContentType ct = new ContentType("application", "json"); // Prints out "application/json" System.out.println(ct.toString());With a character set parameter
application/json; charset=UTF-8:ContentType ct = new ContentType("application", "json", new ContentType.Parameter("charset", "UTF-8")); // Prints out "application/json; charset=UTF-8" System.out.println(ct.toString());To parse a content type:
try { ContentType.parse("application/json; charset=UTF-8"); } catch (java.text.ParseException e) { System.err.println(e.getMessage()); }See RFC 2045, section 5.1.
See RFC 6838, section 4.2.8.
- Author:
- vd
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classContentType.ParameterOptional content type parameter, for examplecharset=UTF-8.
-
Field Summary
Fields Modifier and Type Field Description static ContentTypeAPPLICATION_JOSEContent typeapplication/jose; charset=UTF-8.static ContentTypeAPPLICATION_JSONContent typeapplication/json; charset=UTF-8.static ContentTypeAPPLICATION_JWTContent typeapplication/jwt; charset=UTF-8.static ContentTypeAPPLICATION_PDFContent typeapplication/pdf.static ContentTypeAPPLICATION_URLENCODEDContent typeapplication/x-www-form-urlencoded; charset=UTF-8.static ContentTypeIMAGE_APNGContent typeimage/apng.static ContentTypeIMAGE_AVIFContent typeimage/avif.static ContentTypeIMAGE_GIFContent typeimage/gif.static ContentTypeIMAGE_JPEGContent typeimage/jpeg.static ContentTypeIMAGE_PNGContent typeimage/png.static ContentTypeIMAGE_SVG_XMLContent typeimage/svg+xml.static ContentTypeIMAGE_WEBPContent typeimage/webp.static ContentTypeTEXT_PLAINContent typetext/plain; charset=UTF-8.
-
Constructor Summary
Constructors Constructor Description ContentType(String baseType, String subType, ContentType.Parameter... param)Creates a new content type.ContentType(String baseType, String subType, Charset charset)Creates a new content type with the specified character set.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)StringgetBaseSubType()Returns the base sub type.StringgetBaseType()Returns the base type.List<ContentType.Parameter>getParameters()Returns the optional parameters.StringgetSubType()Returns the subtype.StringgetSubTypeSuffix()Returns the sub type suffix.StringgetType()Returns the type.inthashCode()booleanhasSubTypeSuffix(String suffix)Returnstrueif this content type has the specified sub type suffix.booleanmatches(ContentType other)Returnstrueif the types and subtypes match.static ContentTypeparse(String s)Parses a content type from the specified string.StringtoString()
-
-
-
Field Detail
-
APPLICATION_JSON
public static final ContentType APPLICATION_JSON
Content typeapplication/json; charset=UTF-8.
-
APPLICATION_JOSE
public static final ContentType APPLICATION_JOSE
Content typeapplication/jose; charset=UTF-8.
-
APPLICATION_JWT
public static final ContentType APPLICATION_JWT
Content typeapplication/jwt; charset=UTF-8.
-
APPLICATION_URLENCODED
public static final ContentType APPLICATION_URLENCODED
Content typeapplication/x-www-form-urlencoded; charset=UTF-8.
-
TEXT_PLAIN
public static final ContentType TEXT_PLAIN
Content typetext/plain; charset=UTF-8.
-
IMAGE_APNG
public static final ContentType IMAGE_APNG
Content typeimage/apng.
-
IMAGE_AVIF
public static final ContentType IMAGE_AVIF
Content typeimage/avif.
-
IMAGE_GIF
public static final ContentType IMAGE_GIF
Content typeimage/gif.
-
IMAGE_JPEG
public static final ContentType IMAGE_JPEG
Content typeimage/jpeg.
-
IMAGE_PNG
public static final ContentType IMAGE_PNG
Content typeimage/png.
-
IMAGE_SVG_XML
public static final ContentType IMAGE_SVG_XML
Content typeimage/svg+xml.
-
IMAGE_WEBP
public static final ContentType IMAGE_WEBP
Content typeimage/webp.
-
APPLICATION_PDF
public static final ContentType APPLICATION_PDF
Content typeapplication/pdf.
-
-
Constructor Detail
-
ContentType
public ContentType(String baseType, String subType, ContentType.Parameter... param)
Creates a new content type.- Parameters:
baseType- The type. E.g. "application" from "application/json".Must not benullor empty.subType- The subtype. E.g. "json" from "application/json". Must not benullor empty.param- Optional parameters.
-
ContentType
public ContentType(String baseType, String subType, Charset charset)
Creates a new content type with the specified character set.- Parameters:
baseType- The base type. E.g. "application" from "application/json".Must not benullor empty.subType- The subtype. E.g. "json" from "application/json". Must not benullor empty.charset- The character set to use for thecharsetparameter. Must not benull.
-
-
Method Detail
-
getBaseType
public String getBaseType()
Returns the base type. E.g. "application" from "application/json".- Returns:
- The base type.
-
getSubType
public String getSubType()
Returns the subtype. E.g. "json" from "application/json".- Returns:
- The subtype.
-
getBaseSubType
public String getBaseSubType()
Returns the base sub type. E.g. "entity-statement" from "application/entity-statement+jwt".- Returns:
- The base sub type or the sub type if a suffix is not present.
-
getSubTypeSuffix
public String getSubTypeSuffix()
Returns the sub type suffix. E.g. "jwt" from "application/entity-statement+jwt".- Returns:
- The sub type suffix,
nullnone.
-
hasSubTypeSuffix
public boolean hasSubTypeSuffix(String suffix)
Returnstrueif this content type has the specified sub type suffix.- Parameters:
suffix- The sub type suffix,nullif not specified.- Returns:
trueif the sub type has the specified suffix, elsefalse.
-
getType
public String getType()
Returns the type. E.g. "application/json".- Returns:
- The type, any optional parameters are omitted.
-
getParameters
public List<ContentType.Parameter> getParameters()
Returns the optional parameters.- Returns:
- The parameters, as unmodifiable list, empty list if none.
-
matches
public boolean matches(ContentType other)
Returnstrueif the types and subtypes match. The parameters, if any, are ignored.- Parameters:
other- The other content type,nullif not specified.- Returns:
trueif the types and subtypes match, elsefalse.
-
parse
public static ContentType parse(String s) throws ParseException
Parses a content type from the specified string.- Parameters:
s- The string to parse.- Returns:
- The content type.
- Throws:
ParseException- If parsing failed or the string isnullor empty.
-
-