Package com.helger.commons.mime
Class MimeTypeDeterminator
- java.lang.Object
-
- com.helger.commons.mime.MimeTypeDeterminator
-
@ThreadSafe @Singleton public final class MimeTypeDeterminator extends Object
Contains a basic set of MimeType determination method.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static IMimeTypeDEFAULT_MIME_TYPE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ICommonsCollection<MimeTypeContent>getAllMimeTypeContents()static MimeTypeDeterminatorgetInstance()IMimeTypegetMimeTypeFromBytes(byte[] b)Try to determine the MIME type from the given byte array.IMimeTypegetMimeTypeFromBytes(byte[] aBytes, IMimeType aDefault)Try to determine the MIME type from the given byte array.IMimeTypegetMimeTypeFromString(String s, Charset aCharset)Try to find the MIME type that matches the passed content string.IMimeTypegetMimeTypeFromString(String s, Charset aCharset, IMimeType aDefault)Try to find the MIME type that matches the passed content string.static booleanisInstantiated()EChangeregisterMimeTypeContent(MimeTypeContent aMimeTypeContent)Register a new MIME content type.voidreinitialize()Reset the MimeTypeContent cache to the initial state.EChangeunregisterMimeTypeContent(MimeTypeContent aMimeTypeContent)Unregister an existing MIME content type.
-
-
-
Field Detail
-
DEFAULT_MIME_TYPE
public static final IMimeType DEFAULT_MIME_TYPE
-
-
Method Detail
-
isInstantiated
public static boolean isInstantiated()
-
getInstance
@Nonnull public static MimeTypeDeterminator getInstance()
-
registerMimeTypeContent
@Nonnull public EChange registerMimeTypeContent(@Nonnull MimeTypeContent aMimeTypeContent)
Register a new MIME content type.- Parameters:
aMimeTypeContent- The content type to register. May not benull.- Returns:
EChange.CHANGEDif the object was successfully registered.
-
unregisterMimeTypeContent
@Nonnull public EChange unregisterMimeTypeContent(@Nullable MimeTypeContent aMimeTypeContent)
Unregister an existing MIME content type.- Parameters:
aMimeTypeContent- The content type to unregister. May not benull.- Returns:
EChange.CHANGEDif the object was successfully unregistered.
-
getMimeTypeFromString
@Nonnull public IMimeType getMimeTypeFromString(@Nullable String s, @Nonnull Charset aCharset)
Try to find the MIME type that matches the passed content string.- Parameters:
s- The content string to check. May benull.aCharset- The charset used to convert the string to a byte array. May not benull.- Returns:
DEFAULT_MIME_TYPEif no matching MIME type was found. Nevernull.
-
getMimeTypeFromString
@Nullable public IMimeType getMimeTypeFromString(@Nullable String s, @Nonnull Charset aCharset, @Nullable IMimeType aDefault)
Try to find the MIME type that matches the passed content string.- Parameters:
s- The content string to check. May benull.aCharset- The charset used to convert the string to a byte array. May not benull.aDefault- The default MIME type to be returned, if no MIME type could be found. May benull.- Returns:
aDefaultif no matching MIME type was found. May benull.
-
getMimeTypeFromBytes
@Nonnull public IMimeType getMimeTypeFromBytes(@Nullable byte[] b)
Try to determine the MIME type from the given byte array.- Parameters:
b- The byte array to parse. May benullor empty.- Returns:
DEFAULT_MIME_TYPEif no specific MIME type was found. Nevernull.
-
getMimeTypeFromBytes
@Nullable public IMimeType getMimeTypeFromBytes(@Nullable byte[] aBytes, @Nullable IMimeType aDefault)
Try to determine the MIME type from the given byte array.- Parameters:
aBytes- The byte array to parse. May benullor empty.aDefault- The default MIME type to be returned, if no matching MIME type was found. May benull.- Returns:
- The supplied default value, if no matching MIME type was found. May
be
null.
-
getAllMimeTypeContents
@Nonnull @ReturnsMutableCopy public ICommonsCollection<MimeTypeContent> getAllMimeTypeContents()
- Returns:
- A copy of all registered
MimeTypeContentobjects. Nevernullbut maybe empty.
-
reinitialize
public void reinitialize()
Reset the MimeTypeContent cache to the initial state.
-
-