eu.medsea.mimeutil.detector
Class MimeDetector

java.lang.Object
  extended by eu.medsea.mimeutil.detector.MimeDetector
Direct Known Subclasses:
ExtensionMimeDetector, MagicMimeMimeDetector, OpendesktopMimeDetector

public abstract class MimeDetector
extends Object

ALL MimeDetector(s) must extend this class.

Author:
Steven McArdle

Constructor Summary
MimeDetector()
           
 
Method Summary
 void addMimeHandler(MimeHandler handler)
          Add a mime handler to this MimeDetector.
abstract  String getDescription()
          Abstract method to be implement by concrete MimeDetector(s).
 Set getMimeHandlers()
          Return the Set of MimeHandler(s).
 Collection getMimeTypes(byte[] data)
          This method is called by the MimeUtil getMimeTypes(byte []) method via the MimeUtil.MimeUtilMimeDetectorRegistry class.
 Collection getMimeTypes(File file)
          This method is called by the MimeUtil getMimeTypes(File) method via the MimeUtil.MimeUtilMimeDetectorRegistry class.
 Collection getMimeTypes(InputStream in)
          This method is called by the MimeUtil getMimeTypes(InputStream) method via the MimeUtil.MimeUtilMimeDetectorRegistry class.
 Collection getMimeTypes(String fileName)
          This method is called by the MimeUtil getMimeTypes(fileName) method via the MimeUtil.MimeUtilMimeDetectorRegistry class.
 Collection getMimeTypes(URLConnection url)
          This method is called by the MimeUtil getMimeTypes(URLConnection) method via the MimeUtil.MimeUtilMimeDetectorRegistry class.
abstract  Collection getMimeTypesByteArray(byte[] data)
          Abstract method that must be implemented by concrete MimeDetector(s).
abstract  Collection getMimeTypesFile(File file)
          Abstract method that must be implemented by concrete MimeDetector(s).
abstract  Collection getMimeTypesInputStream(InputStream in)
          Abstract method that must be implemented by concrete MimeDetector(s).
 String getName()
          Gets the name of this MimeDetector
 boolean removeMimeHandler(MimeHandler handler)
          remove a mime handler to this MimeDetector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MimeDetector

public MimeDetector()
Method Detail

getName

public final String getName()
Gets the name of this MimeDetector

Returns:
name of MimeDetector as a fully qualified class name

addMimeHandler

public final void addMimeHandler(MimeHandler handler)
Add a mime handler to this MimeDetector. The MimeHandler(s) are given a chance to influence the collection of MimeTypes before they are returned for collation by MimeUtil and then passed back to the client.

Parameters:
handler -

removeMimeHandler

public final boolean removeMimeHandler(MimeHandler handler)
remove a mime handler to this MimeDetector. The MimeHandler(s) are given a chance to influence the collection of MimeTypes before they are returned for collation by MimeUtil and then passed back to the client.

Parameters:
handler -
Returns:
true if the MimeHandler was removed else false.

getMimeHandlers

public final Set getMimeHandlers()
Return the Set of MimeHandler(s). A set is used as the MimeHandler(s) are order maintained.

Returns:
Set of currently registered MimeHandler(s)

getMimeTypes

public final Collection getMimeTypes(byte[] data)
This method is called by the MimeUtil getMimeTypes(byte []) method via the MimeUtil.MimeUtilMimeDetectorRegistry class.

Parameters:
data -
Returns:
collection of matched MimeType(s) from the specific MimeDetector getMimeTypesByteArray(...) abstract method.

getMimeTypes

public final Collection getMimeTypes(URLConnection url)
This method is called by the MimeUtil getMimeTypes(URLConnection) method via the MimeUtil.MimeUtilMimeDetectorRegistry class.

Parameters:
url -
Returns:
collection of matched MimeType(s) from the specific MimeDetector getMimeTypesInputStream(...) abstract method.

getMimeTypes

public final Collection getMimeTypes(File file)
                              throws MimeException
This method is called by the MimeUtil getMimeTypes(File) method via the MimeUtil.MimeUtilMimeDetectorRegistry class.

Parameters:
file -
Returns:
collection of matched MimeType(s) from the specific MimeDetector getMimeTypesFile(...) abstract method.
Throws:
MimeException

getMimeTypes

public final Collection getMimeTypes(String fileName)
                              throws MimeException
This method is called by the MimeUtil getMimeTypes(fileName) method via the MimeUtil.MimeUtilMimeDetectorRegistry class.

Parameters:
file -
Returns:
collection of matched MimeType(s) from the specific MimeDetector getMimeTypesFile(...) abstract method.
Throws:
MimeException

getMimeTypes

public final Collection getMimeTypes(InputStream in)
                              throws MimeException
This method is called by the MimeUtil getMimeTypes(InputStream) method via the MimeUtil.MimeUtilMimeDetectorRegistry class.

Parameters:
file -
Returns:
collection of matched MimeType(s) from the specific MimeDetector getMimeTypesInputStream(...) abstract method.
Throws:
MimeException

getDescription

public abstract String getDescription()
Abstract method to be implement by concrete MimeDetector(s).

Returns:
description of this MimeDetector

getMimeTypesFile

public abstract Collection getMimeTypesFile(File file)
                                     throws UnsupportedOperationException
Abstract method that must be implemented by concrete MimeDetector(s). This takes a File object and is called by the MimeUtil getMimeTypes(fileName) and getMimeTypes(file) methods. If your MimeDetector does not handle File objects then either throw an UnsupportedOperationException or return an empty collection.

Parameters:
file -
Returns:
collection of matched MimeType(s)
Throws:
UnsupportedOperationException

getMimeTypesInputStream

public abstract Collection getMimeTypesInputStream(InputStream in)
                                            throws UnsupportedOperationException
Abstract method that must be implemented by concrete MimeDetector(s). This takes an InputStream object and is called by the MimeUtil getMimeTypes(URLConnection) and getMimeTypes(InputStream) methods. If your MimeDetector does not handle InputStream objects then either throw an UnsupportedOperationException or return an empty collection.

Parameters:
in - InputStream. If the InputStream does not support the mark() and reset() methods it will throw an exception.
Returns:
collection of matched MimeType(s)
Throws:
UnsupportedOperationException

getMimeTypesByteArray

public abstract Collection getMimeTypesByteArray(byte[] data)
                                          throws 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:
UnsupportedOperationException


Copyright © 2007-2009 Medsea Business Solutions S.L.. All Rights Reserved.