org.mmbase.util.magicfile
Class MagicFile

java.lang.Object
  extended by org.mmbase.util.magicfile.MagicFile

public class MagicFile
extends Object

Tries to determine the mime-type of a byte array (or a file).

Version:
$Id: MagicFile.java 41717 2010-04-01 11:43:17Z michiel $
Author:
cjr@dds.nl, Michiel Meeuwissen

Field Summary
protected static int BUFSIZE
           
protected  DetectorProvider detectors
           
static String FAILED
           
 
Method Summary
 String extensionToMimeType(String extension)
           
 List<Detector> getDetectors()
          Returns a list of detectors used by this MagicFile instance
static MagicFile getInstance()
          Return the current instance of MagicFile.
 String getMimeType(byte[] input)
          Tests the byte[] array for the mime type.
 String getMimeType(byte[] data, String extension)
           
 String getMimeType(File file)
           
 String getMimeType(InputStream input)
           
static void main(String[] argv)
          e.g.: java -Dmmbase.config=/home/mmbase/mmbase-app/WEB-INF/config org.mmbase.util.MagicFile test.doc
 String mimeTypeToExtension(String mimeType)
          Given a mime-type string, this function tries to create a common extension for it.
protected  String test(String path)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFSIZE

protected static final int BUFSIZE
See Also:
Constant Field Values

FAILED

public static final String FAILED
See Also:
Constant Field Values

detectors

protected final DetectorProvider detectors
Method Detail

getInstance

public static MagicFile getInstance()
Return the current instance of MagicFile. If no instance exists, one is created.


getDetectors

public List<Detector> getDetectors()
Returns a list of detectors used by this MagicFile instance


test

protected String test(String path)

getMimeType

public String getMimeType(File file)
                   throws IOException
Parameters:
file - Location of file to be checked
Returns:
Type of the file as determined by the magic file
Throws:
IOException

getMimeType

public String getMimeType(byte[] input)
Tests the byte[] array for the mime type.

Returns:
The found mime-type or FAILED

getMimeType

public String getMimeType(InputStream input)
                   throws IOException
Throws:
IOException
Since:
MMBase-1.9.2

extensionToMimeType

public String extensionToMimeType(String extension)
Javadoc:

mimeTypeToExtension

public String mimeTypeToExtension(String mimeType)
Given a mime-type string, this function tries to create a common extension for it.

Returns:
An extension (without the dot), or an empty string if the mime-type is unknown, or '???' if no valid extension for it is found.
Since:
MMBase-1.7.1

getMimeType

public String getMimeType(byte[] data,
                          String extension)
Javadoc:

main

public static void main(String[] argv)
e.g.: java -Dmmbase.config=/home/mmbase/mmbase-app/WEB-INF/config org.mmbase.util.MagicFile test.doc

Javadoc:


MMBase 2.0-SNAPSHOT - null