|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.j256.simplemagic.ContentTypeUtil
public class ContentTypeUtil
Class which reads in the magic files and determines the ContentType
for files and byte arrays. You use the
default constructor ContentTypeUtil()
to use the internal rules file or load in a local file from the
file-system using ContentTypeUtil(String)
. Once the rules are loaded, you use findMatch(String)
or
other such methods to get the content-type of a file or bytes.
Nested Class Summary | |
---|---|
static interface |
ContentTypeUtil.ErrorCallBack
While we are parsing the magic configuration files, there are usually tons of badly formed lines and other errors. |
Constructor Summary | |
---|---|
ContentTypeUtil()
Construct a magic utility using the internal magic file built into the package. |
|
ContentTypeUtil(ContentTypeUtil.ErrorCallBack errorCallBack)
Construct a magic utility using the internal magic file built into the package. |
|
ContentTypeUtil(File fileOrDirectory)
Construct a magic utility using the magic files from a file or a directory of files. |
|
ContentTypeUtil(File fileOrDirectory,
ContentTypeUtil.ErrorCallBack errorCallBack)
Construct a magic utility using the magic files from a file or a directory of files. |
|
ContentTypeUtil(String fileOrDirectoryPath)
Construct a magic utility using the magic files from a file or a directory of files. |
|
ContentTypeUtil(String fileOrDirectoryPath,
ContentTypeUtil.ErrorCallBack errorCallBack)
Construct a magic utility using the magic files from a file or a directory of files. |
Method Summary | |
---|---|
ContentType |
findMatch(byte[] bytes)
Return the content type from the associated bytes or null if none of the magic entries matched. |
ContentType |
findMatch(File file)
Return the content type for the file or null if none of the magic entries matched. |
ContentType |
findMatch(InputStream inputStream)
Return the content type for the input-stream or null if none of the magic entries matched. |
ContentType |
findMatch(String filePath)
Return the content type for the file or null if none of the magic entries matched. |
void |
setErrorCallBack(ContentTypeUtil.ErrorCallBack errorCallBack)
Set our class which will get called whenever we get a configuration error. |
void |
setFileReadSize(int fileReadSize)
Set the default size that will be read if we are getting the content from a file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ContentTypeUtil()
IllegalStateException
- If there was a problem reading the magic entries from the internal magic file.public ContentTypeUtil(ContentTypeUtil.ErrorCallBack errorCallBack)
IllegalStateException
- If there was a problem reading the magic entries from the internal magic file.public ContentTypeUtil(String fileOrDirectoryPath) throws IOException
IOException
- If there was a problem reading the magic entries from the internal magic file.public ContentTypeUtil(String fileOrDirectoryPath, ContentTypeUtil.ErrorCallBack errorCallBack) throws IOException
IOException
- If there was a problem reading the magic entries from the internal magic file.public ContentTypeUtil(File fileOrDirectory) throws IOException
IOException
- If there was a problem reading the magic entries from the internal magic file.public ContentTypeUtil(File fileOrDirectory, ContentTypeUtil.ErrorCallBack errorCallBack) throws IOException
IOException
- If there was a problem reading the magic entries from the internal magic file.Method Detail |
---|
public ContentType findMatch(String filePath) throws IOException
IOException
- If there was a problem reading from the file.public ContentType findMatch(File file) throws IOException
IOException
- If there was a problem reading from the file.public ContentType findMatch(InputStream inputStream) throws IOException
NOTE: The caller is responsible for closing the input-stream.
IOException
- If there was a problem reading from the input-stream.public ContentType findMatch(byte[] bytes)
public void setFileReadSize(int fileReadSize)
public void setErrorCallBack(ContentTypeUtil.ErrorCallBack errorCallBack)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |