public abstract class MimeTypeUtils
extends java.lang.Object
MimeType
utility methods.Modifier and Type | Class and Description |
---|---|
private static class |
MimeTypeUtils.ConcurrentLruCache<K,V>
Simple Least Recently Used cache, bounded by the maximum size given
to the class constructor.
|
Modifier and Type | Field and Description |
---|---|
static MimeType |
ALL
Public constant mime type that includes all media ranges (i.e.
|
static java.lang.String |
ALL_VALUE
A String equivalent of
ALL . |
static MimeType |
APPLICATION_JSON
Public constant mime type for
application/json . |
static java.lang.String |
APPLICATION_JSON_VALUE
A String equivalent of
APPLICATION_JSON . |
static MimeType |
APPLICATION_OCTET_STREAM
Public constant mime type for
application/octet-stream . |
static java.lang.String |
APPLICATION_OCTET_STREAM_VALUE
A String equivalent of
APPLICATION_OCTET_STREAM . |
static MimeType |
APPLICATION_XML
Public constant mime type for
application/xml . |
static java.lang.String |
APPLICATION_XML_VALUE
A String equivalent of
APPLICATION_XML . |
private static byte[] |
BOUNDARY_CHARS |
private static MimeTypeUtils.ConcurrentLruCache<java.lang.String,MimeType> |
cachedMimeTypes |
static MimeType |
IMAGE_GIF
Public constant mime type for
image/gif . |
static java.lang.String |
IMAGE_GIF_VALUE
A String equivalent of
IMAGE_GIF . |
static MimeType |
IMAGE_JPEG
Public constant mime type for
image/jpeg . |
static java.lang.String |
IMAGE_JPEG_VALUE
A String equivalent of
IMAGE_JPEG . |
static MimeType |
IMAGE_PNG
Public constant mime type for
image/png . |
static java.lang.String |
IMAGE_PNG_VALUE
A String equivalent of
IMAGE_PNG . |
private static java.util.Random |
random |
static java.util.Comparator<MimeType> |
SPECIFICITY_COMPARATOR
Comparator used by
sortBySpecificity(List) . |
static MimeType |
TEXT_HTML
Public constant mime type for
text/html . |
static java.lang.String |
TEXT_HTML_VALUE
A String equivalent of
TEXT_HTML . |
static MimeType |
TEXT_PLAIN
Public constant mime type for
text/plain . |
static java.lang.String |
TEXT_PLAIN_VALUE
A String equivalent of
TEXT_PLAIN . |
static MimeType |
TEXT_XML
Public constant mime type for
text/xml . |
static java.lang.String |
TEXT_XML_VALUE
A String equivalent of
TEXT_XML . |
Constructor and Description |
---|
MimeTypeUtils() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
generateMultipartBoundary()
Generate a random MIME boundary as bytes, often used in multipart mime types.
|
static java.lang.String |
generateMultipartBoundaryString()
Generate a random MIME boundary as String, often used in multipart mime types.
|
private static java.util.Random |
initRandom()
Lazily initialize the
SecureRandom for generateMultipartBoundary() . |
static MimeType |
parseMimeType(java.lang.String mimeType)
Parse the given String into a single
MimeType . |
private static MimeType |
parseMimeTypeInternal(java.lang.String mimeType) |
static java.util.List<MimeType> |
parseMimeTypes(java.lang.String mimeTypes)
Parse the comma-separated string into a list of
MimeType objects. |
static void |
sortBySpecificity(java.util.List<MimeType> mimeTypes)
Sorts the given list of
MimeType objects by specificity. |
static java.util.List<java.lang.String> |
tokenize(java.lang.String mimeTypes)
Tokenize the given comma-separated string of
MimeType objects
into a List<String> . |
static java.lang.String |
toString(java.util.Collection<? extends MimeType> mimeTypes)
Return a string representation of the given list of
MimeType objects. |
private static final byte[] BOUNDARY_CHARS
public static final java.util.Comparator<MimeType> SPECIFICITY_COMPARATOR
sortBySpecificity(List)
.public static final MimeType ALL
public static final java.lang.String ALL_VALUE
ALL
.public static final MimeType APPLICATION_JSON
application/json
.public static final java.lang.String APPLICATION_JSON_VALUE
APPLICATION_JSON
.public static final MimeType APPLICATION_OCTET_STREAM
application/octet-stream
.public static final java.lang.String APPLICATION_OCTET_STREAM_VALUE
APPLICATION_OCTET_STREAM
.public static final MimeType APPLICATION_XML
application/xml
.public static final java.lang.String APPLICATION_XML_VALUE
APPLICATION_XML
.public static final MimeType IMAGE_GIF
image/gif
.public static final java.lang.String IMAGE_GIF_VALUE
IMAGE_GIF
.public static final MimeType IMAGE_JPEG
image/jpeg
.public static final java.lang.String IMAGE_JPEG_VALUE
IMAGE_JPEG
.public static final MimeType IMAGE_PNG
image/png
.public static final java.lang.String IMAGE_PNG_VALUE
IMAGE_PNG
.public static final MimeType TEXT_HTML
text/html
.public static final java.lang.String TEXT_HTML_VALUE
TEXT_HTML
.public static final MimeType TEXT_PLAIN
text/plain
.public static final java.lang.String TEXT_PLAIN_VALUE
TEXT_PLAIN
.public static final MimeType TEXT_XML
text/xml
.public static final java.lang.String TEXT_XML_VALUE
TEXT_XML
.private static final MimeTypeUtils.ConcurrentLruCache<java.lang.String,MimeType> cachedMimeTypes
@Nullable private static volatile java.util.Random random
public static MimeType parseMimeType(java.lang.String mimeType)
MimeType
.
Recently parsed MimeType
are cached for further retrieval.mimeType
- the string to parseInvalidMimeTypeException
- if the string cannot be parsedprivate static MimeType parseMimeTypeInternal(java.lang.String mimeType)
public static java.util.List<MimeType> parseMimeTypes(java.lang.String mimeTypes)
MimeType
objects.mimeTypes
- the string to parseInvalidMimeTypeException
- if the string cannot be parsedpublic static java.util.List<java.lang.String> tokenize(java.lang.String mimeTypes)
MimeType
objects
into a List<String>
. Unlike simple tokenization by ",", this
method takes into account quoted parameters.mimeTypes
- the string to tokenizepublic static java.lang.String toString(java.util.Collection<? extends MimeType> mimeTypes)
MimeType
objects.mimeTypes
- the string to parsejava.lang.IllegalArgumentException
- if the String cannot be parsedpublic static void sortBySpecificity(java.util.List<MimeType> mimeTypes)
MimeType
objects by specificity.
Given two mime types:
For example:
audio/basic < audio/* < */*
audio/basic;level=1 < audio/basic
audio/basic == text/html
audio/basic == audio/wave
mimeTypes
- the list of mime types to be sortedprivate static java.util.Random initRandom()
SecureRandom
for generateMultipartBoundary()
.public static byte[] generateMultipartBoundary()
public static java.lang.String generateMultipartBoundaryString()