org.springframework.http

Class MediaTypeFactory

  • java.lang.Object
    • org.springframework.http.MediaTypeFactory


  • public final class MediaTypeFactory
    extends java.lang.Object
    A factory delegate for resolving MediaType objects from Resource handles or filenames.
    Since:
    5.0
    Author:
    Juergen Hoeller, Arjen Poutsma
    • Method Summary

      All Methods Static Methods Concrete Methods 
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getMediaType

        public static java.util.Optional<MediaType> getMediaType(@Nullable
                                                                 Resource resource)
        Determine a media type for the given resource, if possible.
        Parameters:
        resource - the resource to introspect
        Returns:
        the corresponding media type, or null if none found
      • getMediaType

        public static java.util.Optional<MediaType> getMediaType(@Nullable
                                                                 java.lang.String filename)
        Determine a media type for the given file name, if possible.
        Parameters:
        filename - the file name plus extension
        Returns:
        the corresponding media type, or null if none found
      • getMediaTypes

        public static java.util.List<MediaType> getMediaTypes(@Nullable
                                                              java.lang.String filename)
        Determine the media types for the given file name, if possible.
        Parameters:
        filename - the file name plus extension
        Returns:
        the corresponding media types, or an empty list if none found