org.apache.cocoon.util
Class MIMEUtils

java.lang.Object
  extended by org.apache.cocoon.util.MIMEUtils

public class MIMEUtils
extends Object

A collection of File, URL and filename utility methods.

Version:
CVS $Id: MIMEUtils.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Stefano Mazzocchi, Torsten Knodt, Jeff Turner

Constructor Summary
MIMEUtils()
           
 
Method Summary
static String getDefaultExtension(String type)
          Return the default filename extension for a given MIME type.
static String getMIMEType(File file)
          Return the MIME type for a given file.
static String getMIMEType(String ext)
          Return the MIME type for a given filename extension.
static void loadMimeTypes(Reader in, Map extMap, Map mimeMap)
          Parses a mime.types file, and generates mappings between MIME types and extensions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MIMEUtils

public MIMEUtils()
Method Detail

getMIMEType

public static String getMIMEType(File file)
                          throws FileNotFoundException,
                                 IOException
Return the MIME type for a given file.

Parameters:
file - File.
Returns:
MIME type.
Throws:
FileNotFoundException
IOException

getMIMEType

public static String getMIMEType(String ext)
Return the MIME type for a given filename extension.

Parameters:
ext - Filename extension.
Returns:
MIME type.

getDefaultExtension

public static String getDefaultExtension(String type)
Return the default filename extension for a given MIME type.

Parameters:
type - MIME type.
Returns:
Filename extension.

loadMimeTypes

public static void loadMimeTypes(Reader in,
                                 Map extMap,
                                 Map mimeMap)
                          throws IOException
Parses a mime.types file, and generates mappings between MIME types and extensions. For example, if a line contains:
text/html   html htm
Then 'html' will be the default extension for text/html, and both 'html' and 'htm' will have MIME type 'text/html'. Lines starting with '#' are treated as comments and ignored. If an extension is listed for two MIME types, the first will be chosen.

Parameters:
in - Reader of bytes from mime.types file content
extMap - Empty map of default extensions, keyed by MIME type. Will be filled in by this method.
mimeMap - Empty map of MIME types, keyed by extension. Will be filled in by this method.
Throws:
IOException


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.