Package com.okta.commons.http
Class MimeTypeUtils
- java.lang.Object
-
- com.okta.commons.http.MimeTypeUtils
-
public final class MimeTypeUtils extends java.lang.ObjectMiscellaneousMimeTypeutility methods.- Since:
- 4.0
- Author:
- Arjen Poutsma, Rossen Stoyanchev
-
-
Field Summary
Fields Modifier and Type Field Description static MimeTypeALLPublic constant mime type that includes all media ranges (i.e.static java.lang.StringALL_VALUEA String equivalent ofALL.static MimeTypeAPPLICATION_JSONPublic constant mime type forapplication/json.static java.lang.StringAPPLICATION_JSON_VALUEA String equivalent ofAPPLICATION_JSON.static MimeTypeAPPLICATION_OCTET_STREAMPublic constant mime type forapplication/octet-stream.static java.lang.StringAPPLICATION_OCTET_STREAM_VALUEA String equivalent ofAPPLICATION_OCTET_STREAM.static MimeTypeAPPLICATION_XMLPublic constant mime type forapplication/xml.static java.lang.StringAPPLICATION_XML_VALUEA String equivalent ofAPPLICATION_XML.static MimeTypeIMAGE_GIFPublic constant mime type forimage/gif.static java.lang.StringIMAGE_GIF_VALUEA String equivalent ofIMAGE_GIF.static MimeTypeIMAGE_JPEGPublic constant mime type forimage/jpeg.static java.lang.StringIMAGE_JPEG_VALUEA String equivalent ofIMAGE_JPEG.static MimeTypeIMAGE_PNGPublic constant mime type forimage/png.static java.lang.StringIMAGE_PNG_VALUEA String equivalent ofIMAGE_PNG.static java.util.Comparator<MimeType>SPECIFICITY_COMPARATORComparator used bysortBySpecificity(List).static MimeTypeTEXT_HTMLPublic constant mime type fortext/html.static java.lang.StringTEXT_HTML_VALUEA String equivalent ofTEXT_HTML.static MimeTypeTEXT_PLAINPublic constant mime type fortext/plain.static java.lang.StringTEXT_PLAIN_VALUEA String equivalent ofTEXT_PLAIN.static MimeTypeTEXT_XMLPublic constant mime type fortext/xml.static java.lang.StringTEXT_XML_VALUEA String equivalent ofTEXT_XML.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]generateMultipartBoundary()Generate a random MIME boundary as bytes, often used in multipart mime types.static java.lang.StringgenerateMultipartBoundaryString()Generate a random MIME boundary as String, often used in multipart mime types.static MimeTypeparseMimeType(java.lang.String mimeType)Parse the given String into a singleMimeType.static java.util.List<MimeType>parseMimeTypes(java.lang.String mimeTypes)Parse the given, comma-separated string into a list ofMimeTypeobjects.static voidsortBySpecificity(java.util.List<MimeType> mimeTypes)Sorts the given list ofMimeTypeobjects by specificity.static java.lang.StringtoString(java.util.Collection<? extends MimeType> mimeTypes)Return a string representation of the given list ofMimeTypeobjects.
-
-
-
Field Detail
-
SPECIFICITY_COMPARATOR
public static final java.util.Comparator<MimeType> SPECIFICITY_COMPARATOR
Comparator used bysortBySpecificity(List).
-
ALL
public static final MimeType ALL
Public constant mime type that includes all media ranges (i.e. "*/*").
-
ALL_VALUE
public static final java.lang.String ALL_VALUE
A String equivalent ofALL.- See Also:
- Constant Field Values
-
APPLICATION_JSON
public static final MimeType APPLICATION_JSON
Public constant mime type forapplication/json.
-
APPLICATION_JSON_VALUE
public static final java.lang.String APPLICATION_JSON_VALUE
A String equivalent ofAPPLICATION_JSON.- See Also:
- Constant Field Values
-
APPLICATION_OCTET_STREAM
public static final MimeType APPLICATION_OCTET_STREAM
Public constant mime type forapplication/octet-stream.
-
APPLICATION_OCTET_STREAM_VALUE
public static final java.lang.String APPLICATION_OCTET_STREAM_VALUE
A String equivalent ofAPPLICATION_OCTET_STREAM.- See Also:
- Constant Field Values
-
APPLICATION_XML
public static final MimeType APPLICATION_XML
Public constant mime type forapplication/xml.
-
APPLICATION_XML_VALUE
public static final java.lang.String APPLICATION_XML_VALUE
A String equivalent ofAPPLICATION_XML.- See Also:
- Constant Field Values
-
IMAGE_GIF
public static final MimeType IMAGE_GIF
Public constant mime type forimage/gif.
-
IMAGE_GIF_VALUE
public static final java.lang.String IMAGE_GIF_VALUE
A String equivalent ofIMAGE_GIF.- See Also:
- Constant Field Values
-
IMAGE_JPEG
public static final MimeType IMAGE_JPEG
Public constant mime type forimage/jpeg.
-
IMAGE_JPEG_VALUE
public static final java.lang.String IMAGE_JPEG_VALUE
A String equivalent ofIMAGE_JPEG.- See Also:
- Constant Field Values
-
IMAGE_PNG
public static final MimeType IMAGE_PNG
Public constant mime type forimage/png.
-
IMAGE_PNG_VALUE
public static final java.lang.String IMAGE_PNG_VALUE
A String equivalent ofIMAGE_PNG.- See Also:
- Constant Field Values
-
TEXT_HTML
public static final MimeType TEXT_HTML
Public constant mime type fortext/html.
-
TEXT_HTML_VALUE
public static final java.lang.String TEXT_HTML_VALUE
A String equivalent ofTEXT_HTML.- See Also:
- Constant Field Values
-
TEXT_PLAIN
public static final MimeType TEXT_PLAIN
Public constant mime type fortext/plain.
-
TEXT_PLAIN_VALUE
public static final java.lang.String TEXT_PLAIN_VALUE
A String equivalent ofTEXT_PLAIN.- See Also:
- Constant Field Values
-
TEXT_XML
public static final MimeType TEXT_XML
Public constant mime type fortext/xml.
-
TEXT_XML_VALUE
public static final java.lang.String TEXT_XML_VALUE
A String equivalent ofTEXT_XML.- See Also:
- Constant Field Values
-
-
Method Detail
-
parseMimeType
public static MimeType parseMimeType(java.lang.String mimeType)
Parse the given String into a singleMimeType.- Parameters:
mimeType- the string to parse- Returns:
- the mime type
- Throws:
InvalidMimeTypeException- if the string cannot be parsed
-
parseMimeTypes
public static java.util.List<MimeType> parseMimeTypes(java.lang.String mimeTypes)
Parse the given, comma-separated string into a list ofMimeTypeobjects.- Parameters:
mimeTypes- the string to parse- Returns:
- the list of mime types
- Throws:
java.lang.IllegalArgumentException- if the string cannot be parsed
-
toString
public static java.lang.String toString(java.util.Collection<? extends MimeType> mimeTypes)
Return a string representation of the given list ofMimeTypeobjects.- Parameters:
mimeTypes- the string to parse- Returns:
- the list of mime types
- Throws:
java.lang.IllegalArgumentException- if the String cannot be parsed
-
sortBySpecificity
public static void sortBySpecificity(java.util.List<MimeType> mimeTypes)
Sorts the given list ofMimeTypeobjects by specificity.Given two mime types:
- if either mime type has a wildcard type, then the mime type without the wildcard is ordered before the other.
- if the two mime types have different types, then they are considered equal and remain their current order.
- if either mime type has a wildcard subtype , then the mime type without the wildcard is sorted before the other.
- if the two mime types have different subtypes, then they are considered equal and remain their current order.
- if the two mime types have a different amount of parameters, then the mime type with the most parameters is ordered before the other.
For example:
audio/basic < audio/* < */*
audio/basic;level=1 < audio/basic
audio/basic == text/html
audio/basic == audio/wave
- Parameters:
mimeTypes- the list of mime types to be sorted- See Also:
- HTTP 1.1: Semantics and Content, section 5.3.2
-
generateMultipartBoundary
public static byte[] generateMultipartBoundary()
Generate a random MIME boundary as bytes, often used in multipart mime types.- Returns:
- a multipart boundary byte array
-
generateMultipartBoundaryString
public static java.lang.String generateMultipartBoundaryString()
Generate a random MIME boundary as String, often used in multipart mime types.- Returns:
- a multipart boundary string
-
-