Class MimeDetector
- java.lang.Object
-
- eu.medsea.mimeutil.detector.MimeDetector
-
- Direct Known Subclasses:
ExtensionMimeDetector
,MagicMimeMimeDetector
,OpendesktopMimeDetector
,TextMimeDetector
,WindowsRegistryMimeDetector
public abstract class MimeDetector extends java.lang.Object
ALL MimeDetector(s) must extend this class.
-
-
Constructor Summary
Constructors Constructor Description MimeDetector()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static java.io.InputStream
closeStream(java.io.InputStream in)
void
delete()
You can override this method if for instance you allocated any resources in the init() method that need to be closed or deallocated specially.abstract java.lang.String
getDescription()
Abstract method to be implement by concrete MimeDetector(s).java.util.Collection
getMimeTypes(byte[] data)
Called by MimeUtil.MimeDetectorRegistry.getMimeTypes(byte [] data) {}java.util.Collection
getMimeTypes(java.io.File file)
Called by MimeUtil.MimeDetectorRegistry.getMimeTypes(File file) {}java.util.Collection
getMimeTypes(java.io.InputStream in)
Called by MimeUtil.MimeDetectorRegistry.getMimeTypes(InputStream in) {} The InputStream must support the mark() and reset() methods.java.util.Collection
getMimeTypes(java.lang.String fileName)
Called by MimeUtil.MimeDetectorRegistry.getMimeTypes(String fileName) {}java.util.Collection
getMimeTypes(java.net.URL url)
Called by MimeUtil.MimeDetectorRegistry.getMimeTypes(URL url) {}protected abstract java.util.Collection
getMimeTypesByteArray(byte[] data)
Abstract method that must be implemented by concrete MimeDetector(s).protected abstract java.util.Collection
getMimeTypesFile(java.io.File file)
Abstract method that must be implemented by concrete MimeDetector(s).protected abstract java.util.Collection
getMimeTypesFileName(java.lang.String fileName)
Abstract method that must be implemented by concrete MimeDetector(s).protected abstract java.util.Collection
getMimeTypesInputStream(java.io.InputStream in)
Abstract method that must be implemented by concrete MimeDetector(s).protected abstract java.util.Collection
getMimeTypesURL(java.net.URL url)
Abstract method that must be implemented by concrete MimeDetector(s).java.lang.String
getName()
Gets the name of this MimeDetectorvoid
init()
You can override this method if you have any special one off initialisation to perform such as allocating resources etc.
-
-
-
Method Detail
-
getName
public final java.lang.String getName()
Gets the name of this MimeDetector- Returns:
- name of MimeDetector as a fully qualified class name
-
getMimeTypes
public final java.util.Collection getMimeTypes(java.lang.String fileName) throws java.lang.UnsupportedOperationException
Called by MimeUtil.MimeDetectorRegistry.getMimeTypes(String fileName) {}- Parameters:
fileName
-- Returns:
- Throws:
java.lang.UnsupportedOperationException
-
getMimeTypes
public final java.util.Collection getMimeTypes(java.io.File file) throws java.lang.UnsupportedOperationException
Called by MimeUtil.MimeDetectorRegistry.getMimeTypes(File file) {}- Parameters:
fileName
-- Returns:
- Throws:
java.lang.UnsupportedOperationException
-
getMimeTypes
public final java.util.Collection getMimeTypes(java.net.URL url) throws java.lang.UnsupportedOperationException
Called by MimeUtil.MimeDetectorRegistry.getMimeTypes(URL url) {}- Parameters:
fileName
-- Returns:
- Throws:
java.lang.UnsupportedOperationException
-
getMimeTypes
public final java.util.Collection getMimeTypes(byte[] data) throws java.lang.UnsupportedOperationException
Called by MimeUtil.MimeDetectorRegistry.getMimeTypes(byte [] data) {}- Parameters:
fileName
-- Returns:
- Throws:
java.lang.UnsupportedOperationException
-
getMimeTypes
public final java.util.Collection getMimeTypes(java.io.InputStream in) throws java.lang.UnsupportedOperationException
Called by MimeUtil.MimeDetectorRegistry.getMimeTypes(InputStream in) {} The InputStream must support the mark() and reset() methods.- Parameters:
fileName
-- Returns:
- Throws:
java.lang.UnsupportedOperationException
-
init
public void init()
You can override this method if you have any special one off initialisation to perform such as allocating resources etc.
-
delete
public void delete()
You can override this method if for instance you allocated any resources in the init() method that need to be closed or deallocated specially.
-
getDescription
public abstract java.lang.String getDescription()
Abstract method to be implement by concrete MimeDetector(s).- Returns:
- description of this MimeDetector
-
getMimeTypesFileName
protected abstract java.util.Collection getMimeTypesFileName(java.lang.String fileName) throws java.lang.UnsupportedOperationException
Abstract method that must be implemented by concrete MimeDetector(s). This takes a file name and is called by the MimeUtil getMimeTypes(String fileName) getMimeTypes(File file) getMimeTypes(URL url) methods. If your MimeDetector does not handle file names then either throw an UnsupportedOperationException or return an empty collection.- Parameters:
fileName
-- Returns:
- Collection of matched MimeType(s)
- Throws:
java.lang.UnsupportedOperationException
-
getMimeTypesFile
protected abstract java.util.Collection getMimeTypesFile(java.io.File file) throws java.lang.UnsupportedOperationException
Abstract method that must be implemented by concrete MimeDetector(s). This takes a file object and is called by the MimeUtil getMimeTypes(File file) method. If your MimeDetector does not handle file names then either throw an UnsupportedOperationException or return an empty collection.- Parameters:
file
-- Returns:
- Collection of matched MimeType(s)
- Throws:
java.lang.UnsupportedOperationException
-
getMimeTypesURL
protected abstract java.util.Collection getMimeTypesURL(java.net.URL url) throws java.lang.UnsupportedOperationException
Abstract method that must be implemented by concrete MimeDetector(s). This takes a URL object and is called by the MimeUtil getMimeTypes(URL url) method. If your MimeDetector does not handle file names then either throw an UnsupportedOperationException or return an empty collection.- Parameters:
file
-- Returns:
- Collection of matched MimeType(s)
- Throws:
java.lang.UnsupportedOperationException
-
getMimeTypesInputStream
protected abstract java.util.Collection getMimeTypesInputStream(java.io.InputStream in) throws java.lang.UnsupportedOperationException
Abstract method that must be implemented by concrete MimeDetector(s). This takes an InputStream object and is called by the MimeUtil getMimeTypes(URL url), getMimeTypes(File file) and getMimeTypes(InputStream in) methods. If your MimeDetector does not handle InputStream objects then either throw an UnsupportedOperationException or return an empty collection.If the InputStream passed in does not support the mark() and reset() methods a MimeException will be thrown before reaching this point. The implementation is responsible for the actual use of the mark() and reset() methods as the amount of data to retrieve from the stream is implementation and even call by call dependent. If you do not use the mark() and reset() methods on the Stream then the position in the Stream will have moved on when this method returns and the next MimeDetector that handles the stream will either fail or be incorrect.
To allow the reuse of the Stream in other parts of your code and by further MimeDetector(s) in a way that it is unaware of any data read via this method i.e. the Stream position will be returned to where it was when this method was called, it is IMPORTANT to utilise the mark() and reset() methods within your implementing method.
- Parameters:
in
- InputStream.- Returns:
- Collection of matched MimeType(s)
- Throws:
java.lang.UnsupportedOperationException
-
getMimeTypesByteArray
protected abstract java.util.Collection getMimeTypesByteArray(byte[] data) throws java.lang.UnsupportedOperationException
Abstract method that must be implemented by concrete MimeDetector(s). This takes a byte [] object and is called by the MimeUtil getMimeTypes(byte []) method. If your MimeDetector does not handle byte [] objects then either throw an UnsupportedOperationException or return an empty collection.- Parameters:
data
- byte []. Is a byte array that you want to parse for matching mime types.- Returns:
- Collection of matched MimeType(s)
- Throws:
java.lang.UnsupportedOperationException
-
closeStream
protected static java.io.InputStream closeStream(java.io.InputStream in)
-
-