com.mirrorworlds.lifestreams.mail.tnef
Class DefaultContentTypeImpl

java.lang.Object
  |
  +--com.mirrorworlds.lifestreams.mail.tnef.DefaultContentTypeImpl

public class DefaultContentTypeImpl
extends java.lang.Object
implements TnefContentTypes

Default implementation for the tnef content-type map. Note that the methods in this class are not synchronized i.e. not thread safe.

To save the 72 preconfigured entries to a file from the command line:

  java com.mirrorworlds.lifestreams.mail.tnef.DefaultContentTypeImpl mimetypes.txt 
 

Version:
Feb 20, 2000 Lifestreams 1.5

Constructor Summary
DefaultContentTypeImpl()
          Creates and initialize a list of file extensions and associated mime content-types.
 
Method Summary
 void addType(java.lang.String ext, java.lang.String contentType)
          Lets subclasses add extension and content-types.
 java.util.Enumeration contentTypes()
          Returns an Enumeration to the current mime types.
 java.util.Enumeration extensions()
          Returns an Enumeration to the current file extensions.
 java.lang.String getContentTypeFromExtension(java.lang.String ext)
          Returns the MIME content type given a file extension.
 java.lang.String getContentTypeFromFilename(java.lang.String filename)
          Returns the MIME content type given a file name.
 int getSize()
           
 void load(java.io.InputStream i, boolean clear)
          Loads the extension|content-type from an (text)inputstream.
static void main(java.lang.String[] args)
           
 void removeContentType(java.lang.String contentType)
          Lets subclasses remove content-type and its associated file extensions.
 void removeExtension(java.lang.String ext)
          Lets subclasses remove extension and its associated content-type.
 void writeTo(java.io.OutputStream o)
          Writes the current list of mime type to the output stream using the format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultContentTypeImpl

public DefaultContentTypeImpl()
Creates and initialize a list of file extensions and associated mime content-types. This implementation is configured with 72 entries.
Method Detail

getSize

public int getSize()
Returns:
number of extension/mime-type entries in this registry.

extensions

public java.util.Enumeration extensions()
Returns an Enumeration to the current file extensions. Useful for subclasses to see the current extentsions.

contentTypes

public java.util.Enumeration contentTypes()
Returns an Enumeration to the current mime types. Useful for subclasses to see the current content-types.

addType

public void addType(java.lang.String ext,
                    java.lang.String contentType)
Lets subclasses add extension and content-types.
Parameters:
ext - file extension
contentType - MIME type associated with the file extension.

removeExtension

public void removeExtension(java.lang.String ext)
Lets subclasses remove extension and its associated content-type.
Parameters:
ext - file extension

removeContentType

public void removeContentType(java.lang.String contentType)
Lets subclasses remove content-type and its associated file extensions.
Parameters:
contentType - MIME content-type.

writeTo

public void writeTo(java.io.OutputStream o)
             throws java.io.IOException
Writes the current list of mime type to the output stream using the format
extension [space] mime-type

For example:
       try {
           DefaultContentTypeImpl ct = new DefaultContentTypeImpl();
           FileOutputStream fos = new FileOutputStream("types.txt");
           ct.writeTo(fos);
           fos.close();
       }catch(Exception e) {
       }      
 
Parameters:
o - outputstream to where the contents are written to.

load

public void load(java.io.InputStream i,
                 boolean clear)
          throws java.io.IOException
Loads the extension|content-type from an (text)inputstream. This method expects the inputstream to contain entries in the following (one entry per line) format:
extension [space] mime-type

If the clear flag is set to true then the current contents of the registry are cleared prior to loading. Otherwise, the content are replaced (over written). For example:
       try {
           DefaultContentTypeImpl ct = new DefaultContentTypeImpl();
           FileInputStream fis = new FileInputStream("my-types.txt");
           ct.load(fos,false);
           fis.close();
       }catch(Exception e) {
       }      
 
Any line begining with the pound (#) sign is assumed to be a comment and is ignored.
Parameters:
i - inputstream of ext/mime-type contents
clear - if true,clears the current contents prior to loading.

getContentTypeFromExtension

public java.lang.String getContentTypeFromExtension(java.lang.String ext)
Returns the MIME content type given a file extension. Eg: .txt or .gif The default value is application/octet-stream
Specified by:
getContentTypeFromExtension in interface TnefContentTypes
Parameters:
ext - file extentsion.

getContentTypeFromFilename

public java.lang.String getContentTypeFromFilename(java.lang.String filename)
Returns the MIME content type given a file name. Eg: hello.txt or image.gif The default value is application/octet-stream
Specified by:
getContentTypeFromFilename in interface TnefContentTypes
Parameters:
name - file name with extentsion.

main

public static void main(java.lang.String[] args)