edu.northwestern.at.utils.net.mime

## Class MimeTypeMapper

- java.lang.Object
- - edu.northwestern.at.utils.net.mime.MimeTypeMapper

- All Implemented Interfaces:
    java.net.FileNameMap

      public class MimeTypeMapper
      extends java.lang.Object
      implements java.net.FileNameMap

  Maps file extensions to mime types.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static java.lang.String[][]` | `mimeDefs` Array of mappings between mime types and file extensions.
    `protected static java.util.Map<java.lang.String,java.lang.String>` | `mimeTypes` Map between mime types and file extensions.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MimeTypeMapper()` Null args constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `getContentTypeFor(java.lang.String fileName)` Returns MIME type for a filename.
    `static java.lang.String[]` | `getMatchingExtensions(java.lang.String mainMimeType)` Returns list of extensions matching main MIME type.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### mimeDefs

          protected static final java.lang.String[][] mimeDefs

      Array of mappings between mime types and file extensions.

      The first entry is the mime type, the second is the corresponding extension. Some mime types are associated with more then one extension.

    - #### mimeTypes

          protected static java.util.Map<java.lang.String,java.lang.String> mimeTypes

      Map between mime types and file extensions.

  - ### Constructor Detail

    - #### MimeTypeMapper

          public MimeTypeMapper()

      Null args constructor.

  - ### Method Detail

    - #### getContentTypeFor

          public java.lang.String getContentTypeFor(java.lang.String fileName)

      Returns MIME type for a filename.
      Specified by:
        `getContentTypeFor` in interface `java.net.FileNameMap`
      Parameters:
        `fileName` - Name of file for which mime type is desired.
      Returns:
        The mime type, e.g., "text/plain".

        When the file name's extension is not found in the mime types hash table, a mime type of "application/octet-stream" is returned.

    - #### getMatchingExtensions

          public static java.lang.String[] getMatchingExtensions(java.lang.String mainMimeType)

      Returns list of extensions matching main MIME type.
      Parameters:
        `mainMimeType` - The main mime type, e.g., "audio".
      Returns:
        The list of matching file extensions.