public class MimeTypeUtil extends Object
Modifier and Type | Method and Description |
---|---|
static String |
detectMimeType(File pFile)
Detects the mime-type of a file base on magic bytes.
|
static String |
detectMimeType(InputStream pInputStream,
String pFileName)
Detects the mime-type of a file base on magic bytes in a stream.
|
static String |
getExtension(String pMimeType)
Returns the default file name extension for a mime-type.
|
static String |
guessMimeType(File pFile)
Guesses the mime-type of a file based on its extension.
|
static String |
guessMimeType(String pFileName)
Guesses the mime-type of a file name based on its extension.
|
public static String guessMimeType(File pFile)
pFile
- the file to guess the mime-type for; can not be null
.null
or empty.IllegalArgumentException
- if pFile is null
.public static String guessMimeType(String pFileName)
pFileName
- the name of file to guess the mime-type for; can not be null
or empty.null
or empty.IllegalArgumentException
- if pFileName is null
or empty.public static String detectMimeType(File pFile) throws IOException
pFile
- the file to detect the mime-type for; can not be null
.null
or empty.IOException
- if an I/O error occurs while detecting the mime-type.IllegalArgumentException
- if pFile is null
.public static String detectMimeType(InputStream pInputStream, String pFileName) throws IOException
pInputStream
- the input stream of the file to detect the mime-type for; can not be null
;
must support mark
.pFileName
- the name of the file to detect the mime-type for; can be null
or empty.null
or empty.IOException
- if an I/O error occurs while detecting the mime-type.IllegalArgumentException
- if pInputStream is null
or does not support
mark
.public static String getExtension(String pMimeType)
pMimeType
- the mime-type to get the file name extension for; can be null
or empty.null
if no known extension is found for the
mime-type.© 1998- 2021 Escenic AS