public class MediaTypeFactory
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static MultiValueMap<java.lang.String,MediaType> |
fileExtensionToMediaTypes |
private static java.lang.String |
MIME_TYPES_FILE_NAME |
Constructor and Description |
---|
MediaTypeFactory() |
Modifier and Type | Method and Description |
---|---|
static java.util.Optional<MediaType> |
getMediaType(Resource resource)
Determine a media type for the given resource, if possible.
|
static java.util.Optional<MediaType> |
getMediaType(java.lang.String filename)
Determine a media type for the given file name, if possible.
|
static java.util.List<MediaType> |
getMediaTypes(java.lang.String filename)
Determine the media types for the given file name, if possible.
|
private static MultiValueMap<java.lang.String,MediaType> |
parseMimeTypes()
Parse the
mime.types file found in the resources. |
private static final java.lang.String MIME_TYPES_FILE_NAME
private static final MultiValueMap<java.lang.String,MediaType> fileExtensionToMediaTypes
private static MultiValueMap<java.lang.String,MediaType> parseMimeTypes()
mime.types
file found in the resources. Format is:
# comments begin with a '#'
# the format is <mime type> <space separated file extensions>
# for example:
text/plain txt text
# this would map file.txt and file.text to
# the mime type "text/plain"
public static java.util.Optional<MediaType> getMediaType(@Nullable Resource resource)
resource
- the resource to introspectnull
if none foundpublic static java.util.Optional<MediaType> getMediaType(@Nullable java.lang.String filename)
filename
- the file name plus extensionnull
if none found