Package com.helger.commons.mime
Class MimeTypeDeterminator
java.lang.Object
com.helger.commons.mime.MimeTypeDeterminator
Contains a basic set of MimeType determination method.
- Author:
- Philip Helger
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic MimeTypeDeterminatorgetMimeTypeFromBytes(byte[] b) Try to determine the MIME type from the given byte array.getMimeTypeFromBytes(byte[] aBytes, IMimeType aDefault) Try to determine the MIME type from the given byte array.getMimeTypeFromString(String s, Charset aCharset) Try to find the MIME type that matches the passed content string.getMimeTypeFromString(String s, Charset aCharset, IMimeType aDefault) Try to find the MIME type that matches the passed content string.static booleanregisterMimeTypeContent(MimeTypeContent aMimeTypeContent) Register a new MIME content type.voidReset the MimeTypeContent cache to the initial state.unregisterMimeTypeContent(MimeTypeContent aMimeTypeContent) Unregister an existing MIME content type.
-
Field Details
-
DEFAULT_MIME_TYPE
-
-
Method Details
-
isInstantiated
public static boolean isInstantiated() -
getInstance
-
registerMimeTypeContent
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
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
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
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
- Returns:
- A copy of all registered
MimeTypeContentobjects. Nevernullbut maybe empty.
-
reinitialize
public void reinitialize()Reset the MimeTypeContent cache to the initial state.- See Also:
-