Package de.xima.fc.form.common
Class ContentTypeUtils
- java.lang.Object
-
- de.xima.fc.form.common.ContentTypeUtils
-
public final class ContentTypeUtils extends Object
Performs content type detection by utilizing the Apache Tika framework.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
detectMimeType(InputStream contentInputStream)
Makes a best attempt to detect the MIME type of the provided input stream's content.static String
detectMimeType(String fileName)
Makes a best attempt to detect the MIME type for the given file name.
-
-
-
Method Detail
-
detectMimeType
public static String detectMimeType(InputStream contentInputStream) throws IOException
Makes a best attempt to detect the MIME type of the provided input stream's content.This method returns
application/octet-stream
when no more specific type could be detected.The given input stream will be closed by this method.
- Parameters:
contentInputStream
- the input stream to be used for content type detection.- Returns:
- the detected MIME type (e.g. "image/png" for a PNG image).
- Throws:
NullPointerException
- if the passed input stream is nullIOException
- When the input stream could not be read.
-
detectMimeType
public static String detectMimeType(String fileName)
Makes a best attempt to detect the MIME type for the given file name.This method returns
application/octet-stream
when no more specific type could be detected.- Parameters:
fileName
- Name of the file to detect the MIME type for.- Returns:
- The detected MIME type, e.g.
image/png
for a PNG image. If detection fails, this method returnsapplication/octet-stream
.
-
-