public final class MimeType extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
MimeType.Trait |
| Modifier and Type | Method and Description |
|---|---|
static Collection<MimeType> |
allMimeTypes()
Returns a collection of all managed mime types.
|
MimeType |
createAlias(String name)
Create an new MimeType with traits and type of this MimeType instance and associate it with an new name.
|
String |
fileExtension()
Deprecated.
|
static List<MimeType> |
filterByTrait(MimeType.Trait trait)
Get a list of
MimeType with each item contains the trait specified. |
static MimeType |
findByContentType(String contentType)
Find MimeType by content type.
|
static MimeType |
findByFileExtension(String fileExtension)
Deprecated.
|
static MimeType |
findByName(String name)
Return a MimeType by name.
|
boolean |
hasTrait(MimeType.Trait trait)
Check if this
MimeType has the trait specified. |
boolean |
isAlias(MimeType mimeType)
Check if the mime type specified is an alias of this mime type.
|
boolean |
isSameTypeWith(MimeType mimeType)
Check if the mime type specified has the same
type of this mime type. |
boolean |
isSameTypeWithAny(MimeType... types)
Check if this mime type is same type of any one specified in the var arg list.
|
boolean |
matches(String s)
Check if this
MimeType matches a string specified. |
String |
name()
Return name of this MimeType.
|
static void |
registerMimeType(String name,
String contentType,
MimeType.Trait... traits)
Register an new MimeType with name, contentType and traits.
|
boolean |
test(MimeType.Trait trait)
Deprecated.
|
boolean |
test(String s)
This method is deprecated.
|
String |
toString() |
String |
type() |
static String |
typeOfName(String name)
Return a content type string corresponding to a given name.
|
static String |
typeOfSuffix(String fileExtension)
Deprecated.
|
@Deprecated public String fileExtension()
Return file extension of this MimeType.
Note this method is obsolete, please use instead
public String name()
Return name of this MimeType.
public String type()
public boolean isSameTypeWith(MimeType mimeType)
Check if the mime type specified has the same type of this mime type.
mimeType - the mime type to be testtrue if the mime type has the same type with this mime type.public boolean isSameTypeWithAny(MimeType... types)
Check if this mime type is same type of any one specified in the var arg list.
types - a var arg list of mime types.true if this mime type is same type of any one specified in the list.public boolean isAlias(MimeType mimeType)
Check if the mime type specified is an alias of this mime type. Calling this method has the same effect with calling #isSameType(MimeType).
mimeType - the mime type to be tested.true if the mime type has the same type with this mime type.public MimeType createAlias(String name)
Create an new MimeType with traits and type of this MimeType instance and associate it with an new name.
If the name specified is already registered, then an IllegalArgumentException will be thrown out.
name - the name to be associated with the new MimeType instance@Deprecated public boolean test(MimeType.Trait trait)
This method is deprecated. Please use hasTrait(Trait) instead.
Check if this MimeType has the trait specified.
trait - the trait to test this mime type.true if this mime type has the trait specified.public boolean hasTrait(MimeType.Trait trait)
Check if this MimeType has the trait specified.
trait - the trait to test this mime type.true if this mime type has the trait specified.public boolean test(String s)
This method is deprecated. Please use matches(String) instead
Check if this MimeType matches a string specified.
This method will
s - the string to be tested.true if the s matches as per logic specified above.public boolean matches(String s)
Check if this MimeType matches a string specified.
This method will
s - the string to be tested.true if the s matches as per logic specified above.@Deprecated public static MimeType findByFileExtension(String fileExtension)
This method is deprecated. Please use findByName(String) instead.
fileExtension - the file extension.public static MimeType findByName(String name)
Return a MimeType by name.
name - the name to locate the MimeType.public static MimeType findByContentType(String contentType)
Find MimeType by content type.
contentType - the content type.public static List<MimeType> filterByTrait(MimeType.Trait trait)
Get a list of MimeType with each item contains the trait specified.
trait - the trait to filter MimeType listMimeType matches the trait.public static Collection<MimeType> allMimeTypes()
Returns a collection of all managed mime types.
@Deprecated public static String typeOfSuffix(String fileExtension)
This method is deprecated. Please use typeOfName(String) instead.
Return a content type string corresponding to a given file extension suffix.
If there is no MimeType corresponding to the file extension, then returns the file extension string directly.
fileExtension - file extension suffixpublic static String typeOfName(String name)
Return a content type string corresponding to a given name.
If there is no MimeType corresponding to the name, then returns the name string directly.
name - the namepublic static void registerMimeType(String name, String contentType, MimeType.Trait... traits)
Register an new MimeType with name, contentType and traits.
Note if there are existing MimeType associated with the name, the existing one will be replaced.
name - the name of the new mime typecontentType - the content type of the new mime typetraits - the traits of the new mimetypeCopyright © 2014–2021 OSGL (Open Source General Library). All rights reserved.