Constructor: |
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. |
public MimeType(String rawdata) throws MimeTypeParseException {
parse(rawdata);
}
Builds a MimeType from a String . Parameters:
rawdata - text used to initialize the MimeType
Throws:
NullPointerException - if rawdata is null
|
public MimeType(String primary,
String sub) throws MimeTypeParseException {
this(primary, sub, new MimeTypeParameterList());
}
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:
NullPointerException - if either primary or
sub is null
|
public MimeType(String primary,
String sub,
MimeTypeParameterList mtpl) throws MimeTypeParseException {
// check to see if primary is valid
if(isValidToken(primary)) {
primaryType = primary.toLowerCase();
} else {
throw new MimeTypeParseException("Primary type is invalid.");
}
// check to see if sub is valid
if(isValidToken(sub)) {
subType = sub.toLowerCase();
} else {
throw new MimeTypeParseException("Sub type is invalid.");
}
parameters = (MimeTypeParameterList)mtpl.clone();
}
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:
NullPointerException - if either primary ,
sub or mtpl is null
|
Method from java.awt.datatransfer.MimeType Detail: |
public Object clone() {
MimeType newObj = null;
try {
newObj = (MimeType)super.clone();
} catch (CloneNotSupportedException cannotHappen) {
}
newObj.parameters = (MimeTypeParameterList)parameters.clone();
return newObj;
}
Returns a clone of this object. |
public boolean equals(Object thatObject) {
if (!(thatObject instanceof MimeType)) {
return false;
}
MimeType that = (MimeType)thatObject;
boolean isIt =
((this.primaryType.equals(that.primaryType)) &&
(this.subType.equals(that.subType)) &&
(this.parameters.equals(that.parameters)));
return isIt;
}
MimeType s are equal if their primary types,
subtypes, and parameters are all equal. No default values
are taken into account.
|
public String getBaseType() {
return primaryType + "/" + subType;
}
Return a String representation of this object
without the parameter list. |
public String getParameter(String name) {
return parameters.get(name);
}
Retrieve the value associated with the given name, or null if there
is no current association. |
public MimeTypeParameterList getParameters() {
return (MimeTypeParameterList)parameters.clone();
}
Retrieve a copy of this object's parameter list. |
public String getPrimaryType() {
return primaryType;
}
Retrieve the primary type of this object. |
public String getSubType() {
return subType;
}
Retrieve the sub type of this object. |
public int hashCode() {
// We sum up the hash codes for all of the strings. This
// way, the order of the strings is irrelevant
int code = 0;
code += primaryType.hashCode();
code += subType.hashCode();
code += parameters.hashCode();
return code;
}
|
public boolean match(MimeType type) {
if (type == null)
return false;
return primaryType.equals(type.getPrimaryType())
&& (subType.equals("*")
|| type.getSubType().equals("*")
|| (subType.equals(type.getSubType())));
}
Returns true if the primary type and the
subtype of this object are the same as the specified
type ; otherwise returns false . |
public boolean match(String rawdata) throws MimeTypeParseException {
if (rawdata == null)
return false;
return match(new MimeType(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 . |
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
String s = in.readUTF();
if (s == null || s.length() == 0) { // long mime type
byte[] ba = new byte[in.readInt()];
in.readFully(ba);
s = new String(ba);
}
try {
parse(s);
} catch(MimeTypeParseException e) {
throw new IOException(e.toString());
}
}
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. |
public void removeParameter(String name) {
parameters.remove(name);
}
Remove any value associated with the given name. |
public void setParameter(String name,
String value) {
parameters.set(name, value);
}
Set the value to be associated with the given name, replacing
any previous association. |
public String toString() {
return getBaseType() + parameters.toString();
}
Return the String representation of this object. |
public void writeExternal(ObjectOutput out) throws IOException {
String s = toString(); // contains ASCII chars only
// one-to-one correspondence between ASCII char and byte in UTF string
if (s.length() < = 65535) { // 65535 is max length of UTF string
out.writeUTF(s);
} else {
out.writeByte(0);
out.writeByte(0);
out.writeInt(s.length());
out.write(s.getBytes());
}
}
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. |