org.norther.tammi.acorn.mime
Class MimeTypeMapper

java.lang.Object
  extended by org.norther.tammi.acorn.mime.MimeTypeMapper

public class MimeTypeMapper
extends Object

MimeTypeMapper defines mappings between MIME types and the corresponding file name extensions. The mappings are defined as lines formed by a MIME type name followed by a list of extensions separated by a whitespace.

Version:
$Id: MimeTypeMapper.java,v 1.11 2010-03-15 15:49:08 cvsimp Exp $
Author:
Ilkka Priha

Constructor Summary
MimeTypeMapper()
          Constructs an empty MIME type mapper.
MimeTypeMapper(File file)
          Constructs a mapper reading from a file.
MimeTypeMapper(InputStream input)
          Constructs a mapper reading from a stream.
MimeTypeMapper(String path)
          Constructs a mapper reading from a file path.
 
Method Summary
 String getExtension(String type)
          Gets a file name extension corresponding to a specified MIME type.
protected  String[] getExtensions(String type)
          Gets all file name extensions corresponding to a specified MIME type.
 MimeType getMimeType(String ext)
          Gets a MIME type corresponding to a specified file name extension.
protected  MimeType[] getMimeTypes(String ext)
          Gets all MIME types corresponding to a specified file name extension.
protected  void parse(BufferedReader reader, boolean replace)
          Parses MIME type extensions.
protected  int parseMimeTypeExtension(String spec, Map<String,MimeType[]> mimeTypes, Map<String,String[]> extensions, boolean replace)
          Parses a MIME type extension.
 void setContentType(String spec)
          Sets a MIME content type mapping to extensions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MimeTypeMapper

public MimeTypeMapper()
Constructs an empty MIME type mapper.


MimeTypeMapper

public MimeTypeMapper(InputStream input)
               throws IOException
Constructs a mapper reading from a stream.

Parameters:
input - an input stream.
Throws:
IOException - for an incorrect stream.

MimeTypeMapper

public MimeTypeMapper(File file)
               throws IOException
Constructs a mapper reading from a file.

Parameters:
file - an input file.
Throws:
IOException - for an incorrect file.

MimeTypeMapper

public MimeTypeMapper(String path)
               throws IOException
Constructs a mapper reading from a file path.

Parameters:
path - an input file path.
Throws:
IOException - for an incorrect file.
Method Detail

getMimeType

public MimeType getMimeType(String ext)
Gets a MIME type corresponding to a specified file name extension.

Parameters:
ext - a file name extension.
Returns:
the corresponding MIME type or null.

getExtension

public String getExtension(String type)
Gets a file name extension corresponding to a specified MIME type.

Parameters:
type - the MIME type.
Returns:
the corresponding file name extension or null.

setContentType

public void setContentType(String spec)
Sets a MIME content type mapping to extensions.

Parameters:
spec - a MIME type extension specification to parse.

getMimeTypes

protected MimeType[] getMimeTypes(String ext)
Gets all MIME types corresponding to a specified file name extension.

Note that the internal array of the mapper is returned.

Parameters:
ext - a file name extension.
Returns:
the corresponding MIME type or null.

getExtensions

protected String[] getExtensions(String type)
Gets all file name extensions corresponding to a specified MIME type.

Note that the internal array of the mapper is returned.

Parameters:
type - a MIME type string.
Returns:
the corresponding file name extensions or null.

parse

protected void parse(BufferedReader reader,
                     boolean replace)
              throws IOException
Parses MIME type extensions.

Parameters:
reader - a reader to parse.
replace - a flag to replace.
Throws:
IOException - for an incorrect reader.

parseMimeTypeExtension

protected int parseMimeTypeExtension(String spec,
                                     Map<String,MimeType[]> mimeTypes,
                                     Map<String,String[]> extensions,
                                     boolean replace)
Parses a MIME type extension.

Parameters:
spec - an extension specification to parse.
mimeTypes - a map of MIME types.
extensions - a map of extensions.
replace - a flag to replace.
Returns:
the number of file name extensions parsed.


Copyright © 2004 The Norther Organization. All rights reserved.