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
Fields Modifier and Type Field Description static String
DEFAULT_MIMETYPE
static String
PDF_EXTENSION
static String
PDF_MIMETYPE
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description List<String>
getExtensionsFromMimetypeName(String mimetypeName)
Returns the extension for given mime type.MimetypeEntry
getMimetypeEntryByMimeType(String mimetype)
Gets theMimetypeEntry
for a given mime type.MimetypeEntry
getMimetypeEntryByName(String name)
Gets a mime type entry by name.String
getMimetypeFromBlob(Blob blob)
Returns the mime type from a given stream.String
getMimetypeFromBlobWithDefault(Blob blob, String defaultMimetype)
Finds the mime type of a Blob content and returns provided default if not possible.String
getMimetypeFromExtension(String extension)
Returns the mime type from a given extension.String
getMimetypeFromFile(File file)
Returns the mime type from a given file.String
getMimetypeFromFilename(String filename)
Returns the mime type from a given filename.String
getMimetypeFromFilenameAndBlobWithDefault(String filename, Blob blob, String defaultMimetype)
Finds the mime type of some content according to its filename and / or binary content.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.Optional<String>
getNormalizedMimeType(String mimeType)
Retrieves the normalized mime type for the givenmimeType
.boolean
isMimeTypeNormalized(String mimeType)
Checks if the givenmimeType
is a normalized one.Blob
updateMimetype(Blob blob)
Updates the mime type field of a Blob based on the embedded filename with fallback to binary sniffing.Blob
updateMimetype(Blob blob, String filename)
Updates the mime type field of a Blob based on the provided filename with fallback to binary sniffing.Blob
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 Detail
-
DEFAULT_MIMETYPE
static final String DEFAULT_MIMETYPE
- See Also:
- Constant Field Values
-
PDF_MIMETYPE
static final String PDF_MIMETYPE
- See Also:
- Constant Field Values
-
PDF_EXTENSION
static final String PDF_EXTENSION
- See Also:
- Constant Field Values
-
-
Method Detail
-
getMimetypeFromBlob
String getMimetypeFromBlob(Blob blob)
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
String getMimetypeFromBlobWithDefault(Blob blob, String defaultMimetype)
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
String getMimetypeFromFilename(String filename)
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
String getMimetypeFromFile(File file)
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
List<String> getExtensionsFromMimetypeName(String mimetypeName)
Returns the extension for given mime type.- Parameters:
mimetypeName
- the mime type name.- Returns:
- a list of strings containing the possible extensions.
-
getMimetypeEntryByName
MimetypeEntry getMimetypeEntryByName(String name)
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
MimetypeEntry getMimetypeEntryByMimeType(String mimetype)
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
Blob updateMimetype(Blob blob, String filename, Boolean withBlobMimetypeFallback)
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
Blob updateMimetype(Blob blob, String filename)
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
Blob updateMimetype(Blob blob)
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
String getMimetypeFromExtension(String extension)
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
Optional<String> getNormalizedMimeType(String mimeType)
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
boolean isMimeTypeNormalized(String mimeType)
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
-
-