Class MimeTypeUtils

java.lang.Object
org.springframework.util.MimeTypeUtils

public abstract class MimeTypeUtils extends Object
Miscellaneous MimeType utility methods.
Since:
4.0
Author:
Arjen Poutsma, Rossen Stoyanchev, Dimitrios Liapis, Brian Clozel, Sam Brannen
  • Field Details

  • Constructor Details

    • MimeTypeUtils

      public MimeTypeUtils()
  • Method Details

    • parseMimeType

      public static MimeType parseMimeType(String mimeType)
      Parse the given String into a single MimeType. Recently parsed MimeType are cached for further retrieval.
      Parameters:
      mimeType - the string to parse
      Returns:
      the mime type
      Throws:
      InvalidMimeTypeException - if the string cannot be parsed
    • parseMimeTypes

      public static List<MimeType> parseMimeTypes(String mimeTypes)
      Parse the comma-separated string into a mutable list of MimeType objects.
      Parameters:
      mimeTypes - the string to parse
      Returns:
      the list of mime types
      Throws:
      InvalidMimeTypeException - if the string cannot be parsed
    • tokenize

      public static List<String> tokenize(String mimeTypes)
      Tokenize the given comma-separated string of MimeType objects into a List<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

      public static String toString(Collection<? extends MimeType> mimeTypes)
      Generate a string representation of the given collection of MimeType objects.
      Parameters:
      mimeTypes - the MimeType objects
      Returns:
      a string representation of the MimeType objects
    • sortBySpecificity

      public static <T extends MimeType> void sortBySpecificity(List<T> mimeTypes)
      Sort the given list of MimeType objects by specificity.

      Because of the computational cost, this method throws an exception if the given list contains too many elements.

      Parameters:
      mimeTypes - the list of mime types to be sorted
      Throws:
      InvalidMimeTypeException - if mimeTypes 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

      public static String generateMultipartBoundaryString()
      Generate a random MIME boundary as String, often used in multipart mime types.