org.mmbase.util.magicfile
Class MagicFile

java.lang.Object
  extended byorg.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,v 1.1 2005/10/25 12:12:29 pierre Exp $
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 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)
           
protected  String getMimeType(File file)
           
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

FAILED

public static final String FAILED
See Also:
Constant Field Values

BUFSIZE

protected static int BUFSIZE

detectors

protected 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 getDetectors()
Returns a list of detectors used by this MagicFile instance


test

protected String test(String path)

getMimeType

protected 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

extensionToMimeType

public String extensionToMimeType(String extension)
Warning: No Java Documentation Available.

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.
Since:
MMBase-1.7.1

getMimeType

public String getMimeType(byte[] data,
                          String extension)
Warning: No Java Documentation Available.

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

Warning: No Java Documentation Available.


MMBase build 1.8.1.20060716