org.apache.nutch.util.mime
Class MimeTypes

java.lang.Object
  extended by org.apache.nutch.util.mime.MimeTypes

public final class MimeTypes
extends Object

This class is a MimeType repository. It gathers a set of MimeTypes and enables to retrieves a content-type from a specified file extension, or from a magic character sequence (or both).

Author:
Jerome Charron - http://frutch.free.fr/

Field Summary
static String DEFAULT
          The default application/octet-stream MimeType
 
Method Summary
 MimeType forName(String name)
          Return a MimeType from its name.
static MimeTypes get(String filepath, Configuration conf)
          Return a MimeTypes instance.
static MimeTypes get(String filepath, org.apache.commons.logging.Log logger, Configuration conf)
          Return a MimeTypes instance.
 MimeType getMimeType(byte[] data)
          Find the Mime Content Type of a stream from its content.
 MimeType getMimeType(File file)
          Find the Mime Content Type of a file.
 MimeType getMimeType(String name)
          Find the Mime Content Type of a document from its name.
 MimeType getMimeType(String name, byte[] data)
          Find the Mime Content Type of a document from its name and its content.
 MimeType getMimeType(URL url)
          Find the Mime Content Type of a document from its URL.
 int getMinLength()
          Return the minimum length of data to provide to analyzing methods based on the document's content in order to check all the known MimeTypes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final String DEFAULT
The default application/octet-stream MimeType

See Also:
Constant Field Values
Method Detail

get

public static MimeTypes get(String filepath,
                            Configuration conf)
Return a MimeTypes instance.

Parameters:
filepath - is the mime-types definitions xml file.
Returns:
A MimeTypes instance for the specified filepath xml file.

get

public static MimeTypes get(String filepath,
                            org.apache.commons.logging.Log logger,
                            Configuration conf)
Return a MimeTypes instance.

Parameters:
filepath - is the mime-types definitions xml file.
logger - is it Logger to uses for ouput messages.
Returns:
A MimeTypes instance for the specified filepath xml file.

getMimeType

public MimeType getMimeType(File file)
Find the Mime Content Type of a file.

Parameters:
file - to analyze.
Returns:
the Mime Content Type of the specified file, or null if none is found.

getMimeType

public MimeType getMimeType(URL url)
Find the Mime Content Type of a document from its URL.

Parameters:
url - of the document to analyze.
Returns:
the Mime Content Type of the specified document URL, or null if none is found.

getMimeType

public MimeType getMimeType(String name)
Find the Mime Content Type of a document from its name.

Parameters:
name - of the document to analyze.
Returns:
the Mime Content Type of the specified document name, or null if none is found.

getMimeType

public MimeType getMimeType(byte[] data)
Find the Mime Content Type of a stream from its content.

Parameters:
data - are the first bytes of data of the content to analyze. Depending on the length of provided data, all known MimeTypes are checked. If the length of provided data is greater or egals to the value returned by getMinLength(), then all known MimeTypes are checked, otherwise only the MimeTypes that could be analyzed with the length of provided data are analyzed.
Returns:
The Mime Content Type found for the specified data, or null if none is found.
See Also:
getMinLength()

getMimeType

public MimeType getMimeType(String name,
                            byte[] data)
Find the Mime Content Type of a document from its name and its content.

Parameters:
name - of the document to analyze.
data - are the first bytes of the document's content.
Returns:
the Mime Content Type of the specified document, or null if none is found.
See Also:
getMinLength()

forName

public MimeType forName(String name)
Return a MimeType from its name.


getMinLength

public int getMinLength()
Return the minimum length of data to provide to analyzing methods based on the document's content in order to check all the known MimeTypes.

Returns:
the minimum length of data to provide.
See Also:
getMimeType(byte[]), getMimeType(String, byte[])


Copyright © 2007, 2012, Oracle and/or its affiliates. All rights reserved.