Package org.springframework.util
Class MimeTypeUtils
java.lang.Object
org.springframework.util.MimeTypeUtils
Miscellaneous
MimeType
utility methods.- Since:
- 4.0
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Dimitrios Liapis, Brian Clozel, Sam Brannen
-
Field Summary
Modifier and TypeFieldDescriptionstatic final MimeType
Public constant mime type that includes all media ranges (i.e.static final String
A String equivalent ofALL
.static final MimeType
Public constant mime type forapplication/graphql+json
.static final String
A String equivalent ofAPPLICATION_GRAPHQL
.static final MimeType
Public constant mime type forapplication/json
.static final String
A String equivalent ofAPPLICATION_JSON
.static final MimeType
Public constant mime type forapplication/octet-stream
.static final String
A String equivalent ofAPPLICATION_OCTET_STREAM
.static final MimeType
Public constant mime type forapplication/xml
.static final String
A String equivalent ofAPPLICATION_XML
.static final MimeType
Public constant mime type forimage/gif
.static final String
A String equivalent ofIMAGE_GIF
.static final MimeType
Public constant mime type forimage/jpeg
.static final String
A String equivalent ofIMAGE_JPEG
.static final MimeType
Public constant mime type forimage/png
.static final String
A String equivalent ofIMAGE_PNG
.static final Comparator<MimeType>
Deprecated, for removal: This API element is subject to removal in a future version.As of 6.0, with no direct replacementstatic final MimeType
Public constant mime type fortext/html
.static final String
A String equivalent ofTEXT_HTML
.static final MimeType
Public constant mime type fortext/plain
.static final String
A String equivalent ofTEXT_PLAIN
.static final MimeType
Public constant mime type fortext/xml
.static final String
A String equivalent ofTEXT_XML
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
Generate a random MIME boundary as bytes, often used in multipart mime types.static String
Generate a random MIME boundary as String, often used in multipart mime types.static MimeType
parseMimeType
(String mimeType) Parse the given String into a singleMimeType
.parseMimeTypes
(String mimeTypes) Parse the comma-separated string into a mutable list ofMimeType
objects.static <T extends MimeType>
voidsortBySpecificity
(List<T> mimeTypes) Sorts the given list ofMimeType
objects by specificity.Tokenize the given comma-separated string ofMimeType
objects into aList<String>
.static String
toString
(Collection<? extends MimeType> mimeTypes) Return a string representation of the given list ofMimeType
objects.
-
Field Details
-
SPECIFICITY_COMPARATOR
@Deprecated(since="6.0", forRemoval=true) public static final Comparator<MimeType> SPECIFICITY_COMPARATORDeprecated, for removal: This API element is subject to removal in a future version.As of 6.0, with no direct replacementComparator formally used bysortBySpecificity(List)
. -
ALL
Public constant mime type that includes all media ranges (i.e. "*/*"). -
ALL_VALUE
A String equivalent ofALL
.- See Also:
-
APPLICATION_GRAPHQL
Public constant mime type forapplication/graphql+json
.- Since:
- 5.3.19
- See Also:
-
APPLICATION_GRAPHQL_VALUE
A String equivalent ofAPPLICATION_GRAPHQL
.- Since:
- 5.3.19
- See Also:
-
APPLICATION_JSON
Public constant mime type forapplication/json
. -
APPLICATION_JSON_VALUE
A String equivalent ofAPPLICATION_JSON
.- See Also:
-
APPLICATION_OCTET_STREAM
Public constant mime type forapplication/octet-stream
. -
APPLICATION_OCTET_STREAM_VALUE
A String equivalent ofAPPLICATION_OCTET_STREAM
.- See Also:
-
APPLICATION_XML
Public constant mime type forapplication/xml
. -
APPLICATION_XML_VALUE
A String equivalent ofAPPLICATION_XML
.- See Also:
-
IMAGE_GIF
Public constant mime type forimage/gif
. -
IMAGE_GIF_VALUE
A String equivalent ofIMAGE_GIF
.- See Also:
-
IMAGE_JPEG
Public constant mime type forimage/jpeg
. -
IMAGE_JPEG_VALUE
A String equivalent ofIMAGE_JPEG
.- See Also:
-
IMAGE_PNG
Public constant mime type forimage/png
. -
IMAGE_PNG_VALUE
A String equivalent ofIMAGE_PNG
.- See Also:
-
TEXT_HTML
Public constant mime type fortext/html
. -
TEXT_HTML_VALUE
A String equivalent ofTEXT_HTML
.- See Also:
-
TEXT_PLAIN
Public constant mime type fortext/plain
. -
TEXT_PLAIN_VALUE
A String equivalent ofTEXT_PLAIN
.- See Also:
-
TEXT_XML
Public constant mime type fortext/xml
. -
TEXT_XML_VALUE
A String equivalent ofTEXT_XML
.- See Also:
-
-
Constructor Details
-
MimeTypeUtils
public MimeTypeUtils()
-
-
Method Details
-
parseMimeType
Parse the given String into a singleMimeType
. Recently parsedMimeType
are cached for further retrieval.- Parameters:
mimeType
- the string to parse- Returns:
- the mime type
- Throws:
InvalidMimeTypeException
- if the string cannot be parsed
-
parseMimeTypes
Parse the comma-separated string into a mutable list ofMimeType
objects.- Parameters:
mimeTypes
- the string to parse- Returns:
- the list of mime types
- Throws:
InvalidMimeTypeException
- if the string cannot be parsed
-
tokenize
Tokenize the given comma-separated string ofMimeType
objects into aList<String>
. Unlike simple tokenization by ",", this method takes into account quoted parameters.- Parameters:
mimeTypes
- the string to tokenize- Returns:
- the list of tokens
- Since:
- 5.1.3
-
toString
Return a string representation of the given list ofMimeType
objects.- Parameters:
mimeTypes
- the string to parse- Returns:
- the list of mime types
- Throws:
IllegalArgumentException
- if the String cannot be parsed
-
sortBySpecificity
Sorts the given list ofMimeType
objects by specificity.Because of the computational cost, this method throws an exception when the given list contains too many elements.
- Parameters:
mimeTypes
- the list of mime types to be sorted- Throws:
IllegalArgumentException
- ifmimeTypes
contains more than 50 elements- See Also:
-
generateMultipartBoundary
public static byte[] generateMultipartBoundary()Generate a random MIME boundary as bytes, often used in multipart mime types. -
generateMultipartBoundaryString
Generate a random MIME boundary as String, often used in multipart mime types.
-