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.

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 getContentType(String ext)
          Gets a MIME content type corresponding to a specified file name extension.
protected  String[] getContentTypes(String ext)
          Gets all MIME content types corresponding to a specified file name extension.
 String getExtension(String type)
          Gets a file name extension corresponding to a specified MIME content type.
protected  String[] getExtensions(String type)
          Gets all file name extensions corresponding to a specified MIME content type.
protected  void parse(BufferedReader reader, boolean replace)
          Parses MIME type extensions.
protected  int parseMimeTypeExtension(String spec, Map mimeTypes, Map 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

getContentType

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

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

getExtension

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

Parameters:
type - a MIME type string.
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.

getContentTypes

protected String[] getContentTypes(String ext)
Gets all MIME content 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 string or null.

getExtensions

protected String[] getExtensions(String type)
Gets all file name extensions corresponding to a specified MIME content 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 mimeTypes,
                                     Map 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.