Package com.norconex.commons.lang.file
Class ContentType
java.lang.Object
com.norconex.commons.lang.file.ContentType
- All Implemented Interfaces:
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
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 | 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentType -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets a name for the content type suitable for display to a user.getDisplayName(Locale locale) Gets a name for the content type suitable for display to a user.Gets the file extension usually associated with this content type.String[]Gets the file extensions usually associated with this content type.inthashCode()booleanWhether the given string matches this content type.Returns a content-type without any parameters (removes ";" and any values afterwards).Returns the raw content-type representation without any parameters (removes ";" and any values afterwards).toString()Returns the raw content-type representation.static ContentTypeCreates a new content type.static ContentType[]Creates a null-safe array of content types.static List<ContentType> Creates a null-safe array of content types.
-
Field Details
-
TEXT
-
HTML
-
PDF
-
XML
-
CSV
-
TSV
-
ZIP
- Since:
- 1.14.0
-
JPEG
-
GIF
-
BMP
-
PNG
-
-
Method Details
-
valueOf
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
nullif content type string isnullor blank.
-
valuesOf
Creates a null-safe array of content types. The same number of elements as the supplied strings are returned. Anullvalue will return an empty array. Each content types are individually obtained by invokingvalueOf(String).- Parameters:
contentTypes- the official media type names- Returns:
- content type array.
-
valuesOf
Creates a null-safe array of content types. The same number of elements as the supplied strings are returned. Anullvalue will return an empty array. Each content types are individually obtained by invokingvalueOf(String).- Parameters:
contentTypes- the official media type names- Returns:
- content type array.
- Since:
- 2.0.0
-
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 totoString()).- Returns:
- display name
-
getDisplayName
Gets a name for the content type suitable for display to a user. If the locale isnull, 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 totoString()).- Parameters:
locale- the locale to use to get the display name- Returns:
- display name
-
getContentFamily
-
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
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
Whether the given string matches this content type.- Parameters:
contentType- the content type- Returns:
trueif the given string matches this content type
-
toString
Returns the raw content-type representation. -
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
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
-
hashCode
public int hashCode()
-