Interface MimetypeRegistry
- All Known Implementing Classes:
MimetypeRegistryService
public interface MimetypeRegistry
Allows the management of the mime type entry registry.
Flexible registry of mime types.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetExtensionsFromMimetypeName
(String mimetypeName) Returns the extension for given mime type.getMimetypeEntryByMimeType
(String mimetype) Gets theMimetypeEntry
for a given mime type.getMimetypeEntryByName
(String name) Gets a mime type entry by name.getMimetypeFromBlob
(Blob blob) Returns the mime type from a given stream.getMimetypeFromBlobWithDefault
(Blob blob, String defaultMimetype) Finds the mime type of a Blob content and returns provided default if not possible.getMimetypeFromExtension
(String extension) Returns the mime type from a given extension.getMimetypeFromFile
(File file) Returns the mime type from a given file.getMimetypeFromFilename
(String filename) Returns the mime type from a given filename.getMimetypeFromFilenameAndBlobWithDefault
(String filename, Blob blob, String defaultMimetype) Finds the mime type of some content according to its filename and / or binary content.getMimetypeFromFilenameWithBlobMimetypeFallback
(String filename, Blob blob, String defaultMimetype) Finds the mime type of some content according to its filename or binary mime type or binary content.getNormalizedMimeType
(String mimeType) Retrieves the normalized mime type for the givenmimeType
.boolean
isMimeTypeNormalized
(String mimeType) Checks if the givenmimeType
is a normalized one.updateMimetype
(Blob blob) Updates the mime type field of a Blob based on the embedded filename with fallback to binary sniffing.updateMimetype
(Blob blob, String filename) Updates the mime type field of a Blob based on the provided filename with fallback to binary sniffing.updateMimetype
(Blob blob, String filename, Boolean withBlobMimetypeFallback) Updates the mime type field of a Blob based on the provided filename with fallback to binary.
-
Field Details
-
DEFAULT_MIMETYPE
- See Also:
-
UNDEFINED_MIMETYPE
Undefined MIME type marker, can be returned by the jMimeMagic library.- Since:
- 2023.18
- See Also:
-
XML_MIMETYPE
- Since:
- 2021.9
- See Also:
-
PDF_MIMETYPE
- See Also:
-
PDF_EXTENSION
- See Also:
-
-
Method Details
-
getMimetypeFromBlob
Returns the mime type from a given stream.- Returns:
- String mime type name.
- Throws:
MimetypeNotFoundException
- if mime type sniffing failed to identify a registered mime typeMimetypeDetectionException
- if unexpected problem prevent the detection to work as expected
-
getMimetypeFromBlobWithDefault
Finds the mime type of a Blob content and returns provided default if not possible.- Parameters:
blob
- content to be analyzeddefaultMimetype
- defaultMimeType to be used if no found- Returns:
- the mime type for the given blob if it exists, otherwise it returns
defaultMimetype
- Throws:
MimetypeDetectionException
- if unexpected problem prevent the detection to work as expected
-
getMimetypeFromFilename
Returns the mime type from a given filename.- Parameters:
filename
- the file name for which we are looking for the mime type- Returns:
- the mime type that matches the
filename
- Throws:
MimetypeNotFoundException
- if mime type sniffing failed to identify a registered mime type
-
getMimetypeFromFile
Returns the mime type from a given file.- Returns:
- the mime type of the given file
- Throws:
MimetypeNotFoundException
- if mime type sniffing failed to identify a registered mime typeMimetypeDetectionException
- if unexpected problem prevent the detection to work as expected
-
getExtensionsFromMimetypeName
Returns the extension for given mime type.- Parameters:
mimetypeName
- the mime type name.- Returns:
- a list of strings containing the possible extensions.
-
getMimetypeEntryByName
Gets a mime type entry by name.- Parameters:
name
- the mime type name- Returns:
- the mime type entry that matches the mime type name if it exists,
null
otherwise
-
getMimetypeEntryByMimeType
Gets theMimetypeEntry
for a given mime type.- Parameters:
mimetype
- the mime type for which we are looking for the mime type entry- Returns:
- the mime type entry if it exists,
DEFAULT_MIMETYPE
otherwise
-
getMimetypeFromFilenameAndBlobWithDefault
String getMimetypeFromFilenameAndBlobWithDefault(String filename, Blob blob, String defaultMimetype) Finds the mime type of some content according to its filename and / or binary content.- Parameters:
filename
- extension to analyzeblob
- content to be analyzed if filename is ambiguousdefaultMimetype
- defaultMimeType to be used if no found- Returns:
- the mime type
- Throws:
MimetypeDetectionException
- if unexpected problem prevent the detection to work as expected
-
getMimetypeFromFilenameWithBlobMimetypeFallback
String getMimetypeFromFilenameWithBlobMimetypeFallback(String filename, Blob blob, String defaultMimetype) Finds the mime type of some content according to its filename or binary mime type or binary content.- Parameters:
filename
- extension to analyzeblob
- content to be analyzed if filename is ambiguousdefaultMimetype
- defaultMimeType to be used if no found- Returns:
- the mime type
- Throws:
MimetypeDetectionException
- if unexpected problem prevent the detection to work as expected- Since:
- 8.4
-
updateMimetype
Updates the mime type field of a Blob based on the provided filename with fallback to binary. If the embedded filename isnull
, the provided filename is embedded into the blob as well.- Parameters:
blob
- content to be analyzed if filename is ambiguousfilename
- with extension to analyzewithBlobMimetypeFallback
- to consider blob mime type as fallback or not- Returns:
- updated blob (persisted if necessary)
- Throws:
MimetypeDetectionException
- if unexpected problem prevent the detection to work as expected- Since:
- 8.4
-
updateMimetype
Updates the mime type field of a Blob based on the provided filename with fallback to binary sniffing. If the embedded filename isnull
, the provided filename is embedded into the blob as well.- Parameters:
blob
- content to be analyzed if filename is ambiguousfilename
- with extension to analyze- Returns:
- updated blob (persisted if necessary)
- Throws:
MimetypeDetectionException
- if unexpected problem prevent the detection to work as expected
-
updateMimetype
Updates the mime type field of a Blob based on the embedded filename with fallback to binary sniffing. This method should not be called if the embedded filename isnull
for performance reasons (+ the fact that binary sniffing is no very reliable).- Parameters:
blob
- content to be analyzed if filename is ambiguous- Returns:
- updated blob (persisted if necessary)
- Throws:
MimetypeDetectionException
- if unexpected problem prevent the detection to work as expected
-
getMimetypeFromExtension
Returns the mime type from a given extension.- Parameters:
extension
- the extension for which we are looking for the mime type- Returns:
- the mime type for the given extension if it exists
- Throws:
MimetypeNotFoundException
- if mime type sniffing failed to identify a registered mime type- Since:
- 7.3
-
getNormalizedMimeType
Retrieves the normalized mime type for the givenmimeType
.- Parameters:
mimeType
- the mime for which we are looking for the normalized one- Returns:
- an
Optional
with a present value if the normalized mime type can be found, otherwise an emptyOptional
- Since:
- 11.1
-
isMimeTypeNormalized
Checks if the givenmimeType
is a normalized one.- Parameters:
mimeType
- the mime type to check- Returns:
true
ifmimeType
is normalized,false
otherwise- Since:
- 11.1
-