java.awt.datatransfer
Class MimeType

java.lang.Object
  |
  +--java.awt.datatransfer.MimeType
All Implemented Interfaces:
Cloneable, Externalizable, Serializable

class MimeType
extends Object
implements Externalizable, Cloneable

A Multipurpose Internet Mail Extension (MIME) type, as defined in RFC 2045 and 2046. THIS IS *NOT* - REPEAT *NOT* - A PUBLIC CLASS! DataFlavor IS THE PUBLIC INTERFACE, AND THIS IS PROVIDED AS A ***PRIVATE*** (THAT IS AS IN *NOT* PUBLIC) HELPER CLASS!


Field Summary
private  MimeTypeParameterList parameters
           
private  String primaryType
           
(package private) static long serialVersionUID
           
private  String subType
           
private static String TSPECIALS
          A string that holds all the special chars.
 
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(String rawdata)
          Builds a MimeType from a String.
MimeType(String primary, String sub)
          Builds a MimeType with the given primary and sub type but has an empty parameter list.
MimeType(String primary, String sub, MimeTypeParameterList mtpl)
          Builds a MimeType with a pre-defined and valid (or empty) parameter list.
 
Method Summary
 Object clone()
          Returns a clone of this object.
 boolean equals(Object thatObject)
          MimeTypes are equal if their primary types, subtypes, and parameters are all equal.
 String getBaseType()
          Return a String representation of this object without the parameter list.
 String getParameter(String name)
          Retrieve the value associated with the given name, or null if there is no current association.
 MimeTypeParameterList getParameters()
          Retrieve a copy of this object's parameter list.
 String getPrimaryType()
          Retrieve the primary type of this object.
 String getSubType()
          Retrieve the sub type of this object.
 int hashCode()
          Suppressed: Returns a hash code value for the object.
private static boolean isTokenChar(char c)
          Determines whether or not a given character belongs to a legal token.
private  boolean isValidToken(String s)
          Determines whether or not a given string is a legal token.
 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(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.
private  void parse(String rawdata)
          A routine for parsing the MIME type out of a String.
 void readExternal(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(String name)
          Remove any value associated with the given name.
 void setParameter(String name, String value)
          Set the value to be associated with the given name, replacing any previous association.
 String toString()
          Return the String representation of this object.
 void writeExternal(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
 

Field Detail

serialVersionUID

static final long serialVersionUID

primaryType

private String primaryType

subType

private String subType

parameters

private MimeTypeParameterList parameters

TSPECIALS

private static final String TSPECIALS
A string that holds all the special chars.

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(String rawdata)
         throws MimeTypeParseException
Builds a MimeType from a String.

Parameters:
rawdata - text used to initialize the MimeType

MimeType

public MimeType(String primary,
                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

MimeType

public MimeType(String primary,
                String sub,
                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
Method Detail

hashCode

public int hashCode()
Description copied from class: Object
Suppressed: Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

The general contract of hashCode is:

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

Overrides:
hashCode in class Object
Returns:
a hash code value for this object.
See Also:
java.lang.Object#equals(java.lang.Object), java.util.Hashtable

equals

public boolean equals(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 Object
Parameters:
thatObject - the object to be evaluated as a MimeType
Returns:
true if thatObject is a MimeType; otherwise returns false
See Also:
Object.hashCode(), java.util.Hashtable

parse

private void parse(String rawdata)
            throws MimeTypeParseException
A routine for parsing the MIME type out of a String.

MimeTypeParseException

getPrimaryType

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


getSubType

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


getParameters

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


getParameter

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


setParameter

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


removeParameter

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


toString

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

Overrides:
toString in class Object
Returns:
a string representation of the object.

getBaseType

public 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(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
MimeTypeParseException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws 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 Externalizable
Parameters:
out - the stream to write the object to
IOException

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         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 Externalizable
Parameters:
in - the stream to read data from in order to restore the object
IOException
ClassNotFoundException

clone

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

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

isTokenChar

private static boolean isTokenChar(char c)
Determines whether or not a given character belongs to a legal token.


isValidToken

private boolean isValidToken(String s)
Determines whether or not a given string is a legal token.



comments?