Quaqua 5.4.1 2009-07-14

ch.randelshofer.quaqua.datatransfer
Class MimeType

java.lang.Object
  extended by ch.randelshofer.quaqua.datatransfer.MimeType
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable

public class MimeType
extends java.lang.Object
implements java.io.Externalizable, java.lang.Cloneable

A Multipurpose Internet Mail Extension (MIME) type, as defined in RFC 2045 and 2046.

Implementation taken from java.awt.datatransfer.MimeType 1.20 01/12/03

Version:
$Id: MimeType.java 82 2009-06-11 08:57:33Z wrandelshofer $
Author:
Werner Randelshofer
See Also:
Serialized Form

Constructor Summary
MimeType()
          Constructor for externalization; this constructor should not be called directly by an application, since the result will be an uninitialized, immutable MimeType object.
MimeType(java.lang.String rawdata)
          Builds a MimeType from a String.
MimeType(java.lang.String primary, java.lang.String sub)
          Builds a MimeType with the given primary and sub type but has an empty parameter list.
MimeType(java.lang.String primary, java.lang.String sub, ch.randelshofer.quaqua.datatransfer.MimeTypeParameterList mtpl)
          Builds a MimeType with a pre-defined and valid (or empty) parameter list.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of this object.
 boolean equals(java.lang.Object thatObject)
          MimeTypes are equal if their primary types, subtypes, and parameters are all equal.
 java.lang.String getBaseType()
          Return a String representation of this object without the parameter list.
 java.lang.String getParameter(java.lang.String name)
          Retrieve the value associated with the given name, or null if there is no current association.
 ch.randelshofer.quaqua.datatransfer.MimeTypeParameterList getParameters()
          Retrieve a copy of this object's parameter list.
 java.lang.String getPrimaryType()
          Retrieve the primary type of this object.
 java.lang.String getSubType()
          Retrieve the sub type of this object.
 int hashCode()
           
 boolean match(MimeType type)
          Returns true if the primary type and the subtype of this object are the same as the specified type; otherwise returns false.
 boolean match(java.lang.String rawdata)
          Returns true if the primary type and the subtype of this object are the same as the content type described in rawdata; otherwise returns false.
 void readExternal(java.io.ObjectInput in)
          The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.
 void removeParameter(java.lang.String name)
          Remove any value associated with the given name.
 void setParameter(java.lang.String name, java.lang.String value)
          Set the value to be associated with the given name, replacing any previous association.
 java.lang.String toString()
          Return the String representation of this object.
 void writeExternal(java.io.ObjectOutput out)
          The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings and arrays.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MimeType

public MimeType()
Constructor for externalization; this constructor should not be called directly by an application, since the result will be an uninitialized, immutable MimeType object.


MimeType

public MimeType(java.lang.String rawdata)
         throws MimeTypeParseException
Builds a MimeType from a String.

Parameters:
rawdata - text used to initialize the MimeType
Throws:
MimeTypeParseException

MimeType

public MimeType(java.lang.String primary,
                java.lang.String sub)
         throws MimeTypeParseException
Builds a MimeType with the given primary and sub type but has an empty parameter list.

Parameters:
primary - the primary type of this MimeType
sub - the subtype of this MimeType
Throws:
MimeTypeParseException

MimeType

public MimeType(java.lang.String primary,
                java.lang.String sub,
                ch.randelshofer.quaqua.datatransfer.MimeTypeParameterList mtpl)
         throws MimeTypeParseException
Builds a MimeType with a pre-defined and valid (or empty) parameter list.

Parameters:
primary - the primary type of this MimeType
sub - the subtype of this MimeType
mtpl - the requested parameter list
Throws:
MimeTypeParseException
Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object thatObject)
MimeTypes are equal if their primary types, subtypes, and parameters are all equal. No default values are taken into account.

Overrides:
equals in class java.lang.Object
Parameters:
thatObject - the object to be evaluated as a MimeType
Returns:
true if thatObject is a MimeType; otherwise returns false

getPrimaryType

public java.lang.String getPrimaryType()
Retrieve the primary type of this object.


getSubType

public java.lang.String getSubType()
Retrieve the sub type of this object.


getParameters

public ch.randelshofer.quaqua.datatransfer.MimeTypeParameterList getParameters()
Retrieve a copy of this object's parameter list.


getParameter

public java.lang.String getParameter(java.lang.String name)
Retrieve the value associated with the given name, or null if there is no current association.


setParameter

public void setParameter(java.lang.String name,
                         java.lang.String value)
Set the value to be associated with the given name, replacing any previous association.

Throws:
java.lang.IllegalArgumentException - if parameter or value is illegal

removeParameter

public void removeParameter(java.lang.String name)
Remove any value associated with the given name.

Throws:
IllegalArgumentExcpetion - if parameter may not be deleted

toString

public java.lang.String toString()
Return the String representation of this object.

Overrides:
toString in class java.lang.Object

getBaseType

public java.lang.String getBaseType()
Return a String representation of this object without the parameter list.


match

public boolean match(MimeType type)
Returns true if the primary type and the subtype of this object are the same as the specified type; otherwise returns false.

Parameters:
type - the type to compare to this's type
Returns:
true if the primary type and the subtype of this object are the same as the specified type; otherwise returns false

match

public boolean match(java.lang.String rawdata)
              throws MimeTypeParseException
Returns true if the primary type and the subtype of this object are the same as the content type described in rawdata; otherwise returns false.

Parameters:
rawdata - the raw data to be examined
Returns:
true if the primary type and the subtype of this object are the same as the content type described in rawdata; otherwise returns false; if rawdata is null, returns false
Throws:
MimeTypeParseException

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings and arrays.

Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException - Includes any I/O exceptions that may occur

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.lang.ClassNotFoundException - If the class for an object being restored cannot be found.
java.io.IOException

clone

public java.lang.Object clone()
Returns a clone of this object.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this object

Copyright 2003-2007 (c) Werner Randelshofer.
All rights reserved.