Class Mime

java.lang.Object
org.rapidcontext.core.web.Mime

public final class Mime extends Object
A MIME type helper class.
Version:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String[]
    The MIME types commonly used for binary data.
    static javax.servlet.ServletContext
    The helper servlet context.
    static final String[]
    The MIME types commonly used for CSS.
    static final String[]
    The MIME types commonly used for GIF images.
    static final String[]
    The MIME types commonly used for HTML.
    static final String[]
    The MIME types commonly used for ICO images.
    static final String[]
    The MIME types commonly used for JPEG images.
    static final String[]
    The MIME types commonly used for JavaScript.
    static final String[]
    The MIME types commonly used for JSON.
    static final String[]
    The MIME types commonly used for Markdown.
    static final String[]
    The MIME types commonly used for PNG images.
    static final String[]
    The MIME types commonly used for Java Properties.
    static final String[]
    The MIME types commonly used for SVG images.
    static final String[]
    The MIME types commonly used for plain text.
    static final String[]
    The MIME types commonly used for web form data.
    static final String[]
    The MIME types commonly used for XML.
    static final String[]
    The MIME types commonly used for YAML.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isInputMatch(Request request, String[] mimes)
    Checks if the request input matches one of the specified MIME types.
    static boolean
    isMatch(String contentType, String[] mimes)
    Checks if a specified content type matches one of the specified MIME types.
    static boolean
    isOutputMatch(Request request, String[] mimes)
    Checks if the accepted request output matches one of the specified MIME types.
    static boolean
    isText(String contentType)
    Checks if a specified content type is a known MIME type for text content.
    static String
    type(File file)
    Attempts to guess the MIME type for a file, based on the file name (extension).
    static String
    type(String fileName)
    Attempts to guess the MIME type for a file name (extension).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TEXT

      public static final String[] TEXT
      The MIME types commonly used for plain text.
    • HTML

      public static final String[] HTML
      The MIME types commonly used for HTML.
    • CSS

      public static final String[] CSS
      The MIME types commonly used for CSS.
    • JS

      public static final String[] JS
      The MIME types commonly used for JavaScript.
    • JSON

      public static final String[] JSON
      The MIME types commonly used for JSON.
    • PROPERTIES

      public static final String[] PROPERTIES
      The MIME types commonly used for Java Properties.
    • XML

      public static final String[] XML
      The MIME types commonly used for XML.
    • YAML

      public static final String[] YAML
      The MIME types commonly used for YAML.
    • MARKDOWN

      public static final String[] MARKDOWN
      The MIME types commonly used for Markdown.
    • GIF

      public static final String[] GIF
      The MIME types commonly used for GIF images.
    • JPEG

      public static final String[] JPEG
      The MIME types commonly used for JPEG images.
    • PNG

      public static final String[] PNG
      The MIME types commonly used for PNG images.
    • SVG

      public static final String[] SVG
      The MIME types commonly used for SVG images.
    • ICO

      public static final String[] ICO
      The MIME types commonly used for ICO images.
    • BIN

      public static final String[] BIN
      The MIME types commonly used for binary data.
    • WWW_FORM

      public static final String[] WWW_FORM
      The MIME types commonly used for web form data.
    • context

      public static javax.servlet.ServletContext context
      The helper servlet context. This can be set by the application to access the servlet container MIME type configuration.
  • Method Details

    • type

      public static String type(File file)
      Attempts to guess the MIME type for a file, based on the file name (extension). This method will always return a valid MIME type, defaulting to the binary MIME type if unknown.
      Parameters:
      file - the file to check
      Returns:
      the file MIME type, or a binary MIME type if unknown
    • type

      public static String type(String fileName)
      Attempts to guess the MIME type for a file name (extension). This method will always return a valid MIME type, defaulting to the binary MIME type if unknown.
      Parameters:
      fileName - the file name to check
      Returns:
      the file MIME type, or a binary MIME type if unknown
    • isText

      public static boolean isText(String contentType)
      Checks if a specified content type is a known MIME type for text content.
      Parameters:
      contentType - the content type to analyze
      Returns:
      true if the MIME type is for text content, or false otherwise
    • isMatch

      public static boolean isMatch(String contentType, String[] mimes)
      Checks if a specified content type matches one of the specified MIME types. Note that this method checks for any match, without regard for any embedded quality or encoding value.
      Parameters:
      contentType - the content type to analyze
      mimes - the MIME types to check for
      Returns:
      true if one of the MIME types is accepted, or false otherwise
    • isInputMatch

      public static boolean isInputMatch(Request request, String[] mimes)
      Checks if the request input matches one of the specified MIME types. The input MIME type is read from the 'Content-Type' HTTP header, not from the data stream itself.
      Parameters:
      request - the request to analyze
      mimes - the MIME types to check for
      Returns:
      true if one of the MIME types match, or false otherwise
    • isOutputMatch

      public static boolean isOutputMatch(Request request, String[] mimes)
      Checks if the accepted request output matches one of the specified MIME types. The accepted output MIME type is read from the 'Accept' HTTP header. Note that this method accept matches without regard for quality values in the header.
      Parameters:
      request - the request to analyze
      mimes - the MIME types to check for
      Returns:
      true if one of the MIME types is accepted, or false otherwise