Package com.norconex.commons.lang.file

# Class ContentType

java.lang.Object
com.norconex.commons.lang.file.ContentType

All Implemented Interfaces:
  `Serializable`

public final class ContentType extends Object implements Serializable
Represents a file Content-Type (also called MIME-Type or Media Type).
To detect the content type of a file, consider using an open-source library such as Apache Tika.
To provide your own extension mappings or display names, copy the appropriate `.properties` file to your classpath root, with the word "custom" inserted: `ContentType-custom-[...]`. The actual custom names and classpath location are:

Original vs custom mapping files.
Original | Custom
--- | ---
com.norconex.commmons.lang.file.ContentType-extensions.properties | ContentType-custom-extensions.properties
com.norconex.commmons.lang.file.ContentType-name[_locale].properties | ContentType-custom-name[_locale].propertiess

Since:
  1.4.0
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final ContentType`
  `BMP`
  `static final ContentType`
  `CSV`
  `static final ContentType`
  `GIF`
  `static final ContentType`
  `HTML`
  `static final ContentType`
  `JPEG`
  `static final ContentType`
  `PDF`
  `static final ContentType`
  `PNG`
  `static final ContentType`
  `TEXT`
  `static final ContentType`
  `TSV`
  `static final ContentType`
  `XML`
  `static final ContentType`
  `ZIP`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object o)`
  `ContentFamily`
  `getContentFamily()`
  `String`
  `getDisplayName()`
  Gets a name for the content type suitable for display to a user.
  `String`
  `getDisplayName(Locale locale)`
  Gets a name for the content type suitable for display to a user.
  `String`
  `getExtension()`
  Gets the file extension usually associated with this content type.
  `String[]`
  `getExtensions()`
  Gets the file extensions usually associated with this content type.
  `int`
  `hashCode()`
  `boolean`
  `matches(String contentType)`
  Whether the given string matches this content type.
  `ContentType`
  `toBaseType()`
  Returns a content-type without any parameters (removes ";" and any values afterwards).
  `String`
  `toBaseTypeString()`
  Returns the raw content-type representation without any parameters (removes ";" and any values afterwards).
  `String`
  `toString()`
  Returns the raw content-type representation.
  `static ContentType`
  `valueOf(String contentType)`
  Creates a new content type.
  `static ContentType[]`
  `valuesOf(String... contentTypes)`
  Creates a null-safe array of content types.
  `static List<ContentType>`
  `valuesOf(List<String> contentTypes)`
  Creates a null-safe array of content types.

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

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### TEXT

    public static final ContentType TEXT

  - ### HTML

    public static final ContentType HTML

  - ### PDF

    public static final ContentType PDF

  - ### XML

    public static final ContentType XML

  - ### CSV

    public static final ContentType CSV

  - ### TSV

    public static final ContentType TSV

  - ### ZIP

    public static final ContentType ZIP
    Since:
      1.14.0

  - ### JPEG

    public static final ContentType JPEG

  - ### GIF

    public static final ContentType GIF

  - ### BMP

    public static final ContentType BMP

  - ### PNG

    public static final ContentType PNG

- ## Method Details

  - ### valueOf

    public static ContentType valueOf(String contentType)
    Creates a new content type. Returns an existing instance if the same content type is requested more than once.
    Parameters:
      `contentType` - the official media type name
    Returns:
      content type instance or `null` if content type string is `null` or blank.

  - ### valuesOf

    public static ContentType[] valuesOf(String... contentTypes)
    Creates a null-safe array of content types. The same number of elements as the supplied strings are returned. A `null` value will return an empty array. Each content types are individually obtained by invoking `valueOf(String)`.
    Parameters:
      `contentTypes` - the official media type names
    Returns:
      content type array.

  - ### valuesOf

    public static List<ContentType> valuesOf(List<String> contentTypes)
    Creates a null-safe array of content types. The same number of elements as the supplied strings are returned. A `null` value will return an empty array. Each content types are individually obtained by invoking `valueOf(String)`.
    Parameters:
      `contentTypes` - the official media type names
    Returns:
      content type array.
    Since:
      2.0.0

  - ### getDisplayName

    public String getDisplayName()
    Gets a name for the content type suitable for display to a user. The system locale is used to defined the language of the display name. If no name has been defined for a content type, the raw content type is returned (equivalent to `toString()`).
    Returns:
      display name

  - ### getDisplayName

    public String getDisplayName(Locale locale)
    Gets a name for the content type suitable for display to a user. If the locale is `null`, the system locale is used. If no name has been defined for a content type with the provided locale, the name defaults to English. If no name has been defined for any locale, the raw content type is returned (equivalent to `toString()`).
    Parameters:
      `locale` - the locale to use to get the display name
    Returns:
      display name

  - ### getContentFamily

    public ContentFamily getContentFamily()

  - ### getExtension

    public String getExtension()
    Gets the file extension usually associated with this content type. If the content type has more than one extension, the first one is returned.
    Returns:
      file extension or empty string if no extension is defined

  - ### getExtensions

    public String[] getExtensions()
    Gets the file extensions usually associated with this content type. Most content types only have one commonly used extension.
    Returns:
      file extension or empty array if no extension is defined

  - ### matches

    public boolean matches(String contentType)
    Whether the given string matches this content type.
    Parameters:
      `contentType` - the content type
    Returns:
      `true` if the given string matches this content type

  - ### toString

    public String toString()
    Returns the raw content-type representation.
    Overrides:
      `toString` in class `Object`
    Returns:
      content type as string

  - ### toBaseTypeString

    public String toBaseTypeString()
    Returns the raw content-type representation without any parameters (removes ";" and any values afterwards).
    Returns:
      content type as string without parameters
    Since:
      1.14.0

  - ### toBaseType

    public ContentType toBaseType()
    Returns a content-type without any parameters (removes ";" and any values afterwards). Invoking a content type without parameters will return itself.
    Returns:
      content type without parameters
    Since:
      1.14.0

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`