org.semanticdesktop.aperture.mime.identifier.magic
Class MagicMimeTypeIdentifier

java.lang.Object
  extended by org.semanticdesktop.aperture.mime.identifier.magic.MagicMimeTypeIdentifier
All Implemented Interfaces:
MimeTypeIdentifier

public class MagicMimeTypeIdentifier
extends Object
implements MimeTypeIdentifier

Determines the MIME type of a binary resource based on magic number-based heuristics.


Constructor Summary
MagicMimeTypeIdentifier()
           
MagicMimeTypeIdentifier(String definitionsResource)
           
 
Method Summary
 List getExtensionsFor(String mimeType)
          Utility method for listing all known file extensions of the specified MIME type.
protected  ArrayList getMimeTypeDescriptions()
           
 int getMinArrayLength()
          Returns the minimum length needed by the identify method for its array parameter.
 String identify(byte[] firstBytes, String fileName, URI uri)
          Identifies the MIME type of a binary resource based on the specified characteristics.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MagicMimeTypeIdentifier

public MagicMimeTypeIdentifier()

MagicMimeTypeIdentifier

public MagicMimeTypeIdentifier(String definitionsResource)
Method Detail

getMimeTypeDescriptions

protected ArrayList getMimeTypeDescriptions()

identify

public String identify(byte[] firstBytes,
                       String fileName,
                       URI uri)
Description copied from interface: MimeTypeIdentifier
Identifies the MIME type of a binary resource based on the specified characteristics. Any of the parameters may be null.

Specified by:
identify in interface MimeTypeIdentifier
Parameters:
firstBytes - The first bytes of the resource's binary contents. The getMinArrayLength method will return how big this array should minimally be for this MimeTypeIdentifier to do its job.
fileName - The resource's file name.
uri - the URI used to typically identify the resource.
Returns:
the detected MIME type of the resource, or null when the MIME type could not be determined.
See Also:
MimeTypeIdentifier.getMinArrayLength()

getMinArrayLength

public int getMinArrayLength()
Description copied from interface: MimeTypeIdentifier
Returns the minimum length needed by the identify method for its array parameter.

Specified by:
getMinArrayLength in interface MimeTypeIdentifier
See Also:
MimeTypeIdentifier.identify(byte[], String, URI)

getExtensionsFor

public List getExtensionsFor(String mimeType)
Utility method for listing all known file extensions of the specified MIME type.

Returns:
A List of file name extensions known to be used for the specified MIME type, or null when the MIME type was not recognized.


Copyright © 2010 Aperture Development Team. All Rights Reserved.