Methods Summary |
---|
public java.lang.String | getBaseType()Return a String representation of this object
without the parameter list.
return primaryType + "/" + subType;
|
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.
return parameters.get(name);
|
public javax.activation.MimeTypeParameterList | getParameters()Retrieve this object's parameter list.
return parameters;
|
public java.lang.String | getPrimaryType()Retrieve the primary type of this object.
return primaryType;
|
public java.lang.String | getSubType()Retrieve the subtype of this object.
return subType;
|
private static boolean | isTokenChar(char c)Determine whether or not a given character belongs to a legal token.
return ((c > 040) && (c < 0177)) && (TSPECIALS.indexOf(c) < 0);
|
private boolean | isValidToken(java.lang.String s)Determine whether or not a given string is a legal token.
int len = s.length();
if (len > 0) {
for (int i = 0; i < len; ++i) {
char c = s.charAt(i);
if (!isTokenChar(c)) {
return false;
}
}
return true;
} else {
return false;
}
|
public boolean | match(javax.activation.MimeType type)Determine if the primary and sub type of this object is
the same as what is in the given type.
return primaryType.equals(type.getPrimaryType())
&& (subType.equals("*")
|| type.getSubType().equals("*")
|| (subType.equals(type.getSubType())));
|
public boolean | match(java.lang.String rawdata)Determine if the primary and sub type of this object is
the same as the content type described in rawdata.
return match(new MimeType(rawdata));
|
private void | parse(java.lang.String rawdata)A routine for parsing the MIME type out of a String.
int slashIndex = rawdata.indexOf('/");
int semIndex = rawdata.indexOf(';");
if ((slashIndex < 0) && (semIndex < 0)) {
// neither character is present, so treat it
// as an error
throw new MimeTypeParseException("Unable to find a sub type.");
} else if ((slashIndex < 0) && (semIndex >= 0)) {
// we have a ';' (and therefore a parameter list),
// but no '/' indicating a sub type is present
throw new MimeTypeParseException("Unable to find a sub type.");
} else if ((slashIndex >= 0) && (semIndex < 0)) {
// we have a primary and sub type but no parameter list
primaryType = rawdata.substring(0, slashIndex).trim().
toLowerCase(Locale.ENGLISH);
subType = rawdata.substring(slashIndex + 1).trim().
toLowerCase(Locale.ENGLISH);
parameters = new MimeTypeParameterList();
} else if (slashIndex < semIndex) {
// we have all three items in the proper sequence
primaryType = rawdata.substring(0, slashIndex).trim().
toLowerCase(Locale.ENGLISH);
subType = rawdata.substring(slashIndex + 1, semIndex).trim().
toLowerCase(Locale.ENGLISH);
parameters = new MimeTypeParameterList(rawdata.substring(semIndex));
} else {
// we have a ';' lexically before a '/' which means we
// have a primary type and a parameter list but no sub type
throw new MimeTypeParseException("Unable to find a sub type.");
}
// now validate the primary and sub types
// check to see if primary is valid
if (!isValidToken(primaryType))
throw new MimeTypeParseException("Primary type is invalid.");
// check to see if sub is valid
if (!isValidToken(subType))
throw new MimeTypeParseException("Sub type is invalid.");
|
public 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. The
readExternal method must read the values in the same sequence
and with the same types as were written by writeExternal.
try {
parse(in.readUTF());
} catch (MimeTypeParseException e) {
throw new IOException(e.toString());
}
|
public void | removeParameter(java.lang.String name)Remove any value associated with the given name.
parameters.remove(name);
|
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.
parameters.set(name, value);
|
public void | setPrimaryType(java.lang.String primary)Set the primary type for this object to the given String.
// check to see if primary is valid
if (!isValidToken(primaryType))
throw new MimeTypeParseException("Primary type is invalid.");
primaryType = primary.toLowerCase(Locale.ENGLISH);
|
public void | setSubType(java.lang.String sub)Set the subtype for this object to the given String.
// check to see if sub is valid
if (!isValidToken(subType))
throw new MimeTypeParseException("Sub type is invalid.");
subType = sub.toLowerCase(Locale.ENGLISH);
|
public java.lang.String | toString()Return the String representation of this object.
return getBaseType() + parameters.toString();
|
public 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.
out.writeUTF(toString());
out.flush();
|