Package com.liferay.portal.kernel.util
Class MimeTypesUtil
Object
com.liferay.portal.kernel.util.MimeTypesUtil
- Author:
- Jorge Ferrer, Brian Wing Shun Chan, Alexander Chow
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getContentType
(File file) Returns the content type from the file.static String
getContentType
(File file, String fileName) Returns the content type from the file and file name.static String
getContentType
(InputStream inputStream, String fileName) Returns the content type from the input stream and file name.static String
getContentType
(String fileName) Returns the content type from the file name.static String
getExtensionContentType
(String extension) Returns the content type from the file extension.getExtensions
(String contentType) Returns the possible file extensions for the content type.static MimeTypes
-
Constructor Details
-
MimeTypesUtil
public MimeTypesUtil()
-
-
Method Details
-
getContentType
Returns the content type from the file.- Parameters:
file
- the file of the content- Returns:
- the content type if it is a supported format or "application/octet-stream" if it is an unsupported format
-
getContentType
Returns the content type from the file and file name.- Parameters:
file
- the file of the content (optionallynull
)fileName
- the full name or extension of the file (e.g., "Test.doc", ".doc")- Returns:
- the content type if it is a supported format or "application/octet-stream" if it is an unsupported format
-
getContentType
Returns the content type from the input stream and file name.The input stream is not reset upon return of this method. This needs to be handled by the caller if the input stream is to be reused. Alternatively, use the method
getContentType(File, String)
.- Parameters:
inputStream
- the input stream of the content (optionallynull
)fileName
- the full name or extension of the file (e.g., "Test.doc", ".doc")- Returns:
- the content type if it is a supported format or "application/octet-stream" if it is an unsupported format
-
getContentType
Returns the content type from the file name.- Parameters:
fileName
- the full name or extension of the file (e.g., "Test.doc", ".doc")- Returns:
- the content type if it is a supported format or "application/octet-stream" if it is an unsupported format
-
getExtensionContentType
Returns the content type from the file extension.- Parameters:
extension
- the extension of the file (e.g., "doc")- Returns:
- the content type if it is a supported format or "application/octet-stream" if it is an unsupported format
-
getExtensions
Returns the possible file extensions for the content type.- Parameters:
contentType
- the content type of the file (e.g., "image/jpeg")- Returns:
- the set of extensions if it is a known content type or an empty set if it is an unknown content type
-
getMimeTypes
-