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
FieldsModifier and TypeFieldDescriptionstatic final MimeTypePublic constant mime type that includes all media ranges (i.e.static final StringA String equivalent ofALL.static final MimeTypePublic constant mime type forapplication/json.static final StringA String equivalent ofAPPLICATION_JSON.static final MimeTypePublic constant mime type forapplication/octet-stream.static final StringA String equivalent ofAPPLICATION_OCTET_STREAM.static final MimeTypePublic constant mime type forapplication/xml.static final StringA String equivalent ofAPPLICATION_XML.static final MimeTypePublic constant mime type forimage/gif.static final StringA String equivalent ofIMAGE_GIF.static final MimeTypePublic constant mime type forimage/jpeg.static final StringA String equivalent ofIMAGE_JPEG.static final MimeTypePublic constant mime type forimage/png.static final StringA String equivalent ofIMAGE_PNG.static final Comparator<MimeType>Deprecated.As of 6.0, with no direct replacementstatic final MimeTypePublic constant mime type fortext/html.static final StringA String equivalent ofTEXT_HTML.static final MimeTypePublic constant mime type fortext/plain.static final StringA String equivalent ofTEXT_PLAIN.static final MimeTypePublic constant mime type fortext/xml.static final StringA String equivalent ofTEXT_XML. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]Generate a random MIME boundary as bytes, often used in multipart mime types.static StringGenerate a random MIME boundary as String, often used in multipart mime types.static MimeTypeparseMimeType(String mimeType) Parse the given String into a singleMimeType.parseMimeTypes(String mimeTypes) Parse the comma-separated string into a list ofMimeTypeobjects.static <T extends MimeType>
voidsortBySpecificity(List<T> mimeTypes) Sorts the given list ofMimeTypeobjects by specificity.Tokenize the given comma-separated string ofMimeTypeobjects into aList<String>.static StringtoString(Collection<? extends MimeType> mimeTypes) Return a string representation of the given list ofMimeTypeobjects.
-
Field Details
-
SPECIFICITY_COMPARATOR
Deprecated.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_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 parsedMimeTypeare 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 list ofMimeTypeobjects.- 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 ofMimeTypeobjects 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 ofMimeTypeobjects.- 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 ofMimeTypeobjects 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- ifmimeTypescontains 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.
-