org.jets3t.service.utils
Class Mimetypes

java.lang.Object
  extended by org.jets3t.service.utils.Mimetypes

public class Mimetypes
extends Object

Utility class that maintains a listing of known Mimetypes, and determines the mimetype of files based on file extensions.

This class is obtained with the {#link getInstance() method that recognised loads mime types from the file mime.types if this file is available at the root of the classpath. The mime.types file format, and most of the content, is taken from the Apache HTTP server's mime.types file.

The format for mime type setting documents is: mimetype + extension (+ extension)*. Any blank lines in the file are ignored, as are lines starting with # which are considered comments. Lines that have a mimetype but no associated extensions are also ignored.

For more information about Mimetype settings please see: JetS3t Configuration

Author:
James Murty

Field Summary
static String MIMETYPE_GZIP
          The default gzip mimetype: application/x-gzip
static String MIMETYPE_HTML
          The default HTML mimetype: text/html
static String MIMETYPE_JETS3T_DIRECTORY
          A JetS3t-specific mimetype used to indicate that an S3 object actually represents a directory on the local file system.
static String MIMETYPE_OCTET_STREAM
          The default binary mimetype: application/octet-stream
static String MIMETYPE_XML
          The default XML mimetype: application/xml
 
Method Summary
static Mimetypes getInstance()
          Loads mime type settings from the file 'mime.types' in the classpath, if it's available.
 String getMimetype(File file)
          Determines the mimetype of a file by looking up the file's extension in an internal listing to find the corresponding mime type.
 String getMimetype(String fileName)
          Determines the mimetype of a file by looking up the file's extension in an internal listing to find the corresponding mime type.
 void loadAndReplaceMimetypes(InputStream is)
          Reads and stores the mime type setting corresponding to a file extension, by reading text from an InputStream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIMETYPE_XML

public static final String MIMETYPE_XML
The default XML mimetype: application/xml

See Also:
Constant Field Values

MIMETYPE_HTML

public static final String MIMETYPE_HTML
The default HTML mimetype: text/html

See Also:
Constant Field Values

MIMETYPE_OCTET_STREAM

public static final String MIMETYPE_OCTET_STREAM
The default binary mimetype: application/octet-stream

See Also:
Constant Field Values

MIMETYPE_GZIP

public static final String MIMETYPE_GZIP
The default gzip mimetype: application/x-gzip

See Also:
Constant Field Values

MIMETYPE_JETS3T_DIRECTORY

public static final String MIMETYPE_JETS3T_DIRECTORY
A JetS3t-specific mimetype used to indicate that an S3 object actually represents a directory on the local file system.

See Also:
Constant Field Values
Method Detail

getInstance

public static Mimetypes getInstance()
Loads mime type settings from the file 'mime.types' in the classpath, if it's available.


loadAndReplaceMimetypes

public void loadAndReplaceMimetypes(InputStream is)
                             throws IOException
Reads and stores the mime type setting corresponding to a file extension, by reading text from an InputStream. If a mime type setting already exists when this method is run, the mime type value is replaced with the newer one.

Parameters:
is -
Throws:
IOException

getMimetype

public String getMimetype(String fileName)
Determines the mimetype of a file by looking up the file's extension in an internal listing to find the corresponding mime type. If the file has no extension, or the extension is not available in the listing contained in this class, the default mimetype application/octet-stream is returned.

A file extension is one or more characters that occur after the last period (.) in the file's name. If a file has no extension, Guesses the mimetype of file data based on the file's extension.

Parameters:
fileName - the name of the file whose extension may match a known mimetype.
Returns:
the file's mimetype based on its extension, or a default value of application/octet-stream if a mime type value cannot be found.

getMimetype

public String getMimetype(File file)
Determines the mimetype of a file by looking up the file's extension in an internal listing to find the corresponding mime type. If the file has no extension, or the extension is not available in the listing contained in this class, the default mimetype application/octet-stream is returned.

A file extension is one or more characters that occur after the last period (.) in the file's name. If a file has no extension, Guesses the mimetype of file data based on the file's extension.

Parameters:
file - the file whose extension may match a known mimetype.
Returns:
the file's mimetype based on its extension, or a default value of application/octet-stream if a mime type value cannot be found.