|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.net.MimeType
public class MimeType
Representation of a MIME content type.
This object contains information to a particular MIME
type. These objects are often combined into a MimeTypes collection so one can look up the proper mime type for a
file with a certain extension (or vice versa).
NOTE: The current implementation is case insensitive for a preference for lower case (I should probably verify this is a reasonable thing).
MimeTypes| Field Summary | |
|---|---|
static MimeType |
UNKNOWN
Constant for the "unknown/unknown" mime type (when we don't know the mime type). |
| Constructor Summary | |
|---|---|
MimeType(String type,
String subtype,
String[] fileExt)
Constructs a MimeType object with a type,
subtype and optional set of file extensions typically associated
with a mime type. |
|
| Method Summary | |
|---|---|
boolean |
equals(Object o)
Determine if this type matches another type. |
static MimeType |
fromMimeTypesString(String s)
Creates a MimeType object from a ASCII line of
text one might find in a /etc/mime.types files on a Unix System. |
String[] |
getFileExt()
Get the typical file extension(s) associated with the mime type. |
String |
getSubType()
Get the secondary Mime type (for example: "html" for "text/html"). |
String |
getType()
Get the primary Mime type (for example: "text" for "text/html"). |
int |
hashCode()
Generate a hash code such that two objects which are equal produce the same hash code. |
boolean |
isApplicationType()
Is mime-type one of the "application/*" types. |
boolean |
isExtSupported(String s)
Determine if the file extension in the string passed is associated with this mime type. |
boolean |
isImageType()
Is mime-type one of the "image/*" types. |
boolean |
isTextType()
Is mime-type one of the "text/*" types. |
boolean |
isVideoType()
Is mime-type one of the "video/*" types. |
String |
toMimeTypesString()
Return the mime type in a string form as one might find in "/etc/mime.types". |
String |
toString()
Returns the standard "mime" looking string of the mime type (like: "text/html"). |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static MimeType UNKNOWN
| Constructor Detail |
|---|
public MimeType(String type,
String subtype,
String[] fileExt)
MimeType object with a type,
subtype and optional set of file extensions typically associated
with a mime type.
type - The primary type (like "text" in "text/html") - must not be null.subtype - The secondary type (like "html" in "text/html") - must not be null.fileExt - The array of file extensions associated with the mime type
(like { "html", "htm" } for the "text/html" type). This may be
null if you don't need to associate any file extension types,
HOWEVER, if you don't pass null - then each entry must NOT be
null.| Method Detail |
|---|
public boolean equals(Object o)
equals in class Objecto - Object (or null) to compare to this type.
public int hashCode()
hashCode in class Objectpublic String getType()
public String getSubType()
public String[] getFileExt()
If the mime type has a set of typical file extensions for files containg this type of content, this method will return the extensions (as an array of strings).
For example, for the "text/html" mime type, this method would return an array with two entries: { "html", "htm" }.
If there isn't an associated type, then a zero length array is returned (we never return null).
You are free to modify the contents of the returned array (we give you a clone of our current copy so you can't muck up our immutable status).
public String toString()
toString in class Objectpublic String toMimeTypesString()
On Unix systems, mime types are often store in a configuration file (like "/etc/mime.types" on a RedHat 7.1 system). Each entry on the line has the form:
TYPE/SUBTYPE\t[\t[\t]][EXT0 [EXT1 ...]
For example, the "image/tiff" entry looks like:
image/tiff tiff tif
This method formats the mime type in the above form.
fromMimeTypesString(java.lang.String)public static MimeType fromMimeTypesString(String s)
MimeType object from a ASCII line of
text one might find in a /etc/mime.types files on a Unix System.
The /etc/mime.types file on Unix systems typically has a form similar to:
TYPE/SUBTYPE [EXT0[ EXT1[...]]]
The following shows example of a couple of these lines:
video/vnd.vivo text/html html htm
This static method takes one of these types of lines as input
and returns a corresponding MimeType object.
line - Line of text to parse (must not be null).
MimeType object which represents the parsed
line.
NullPointerException - If you pass null.
IllegalArgumentException - If string passed is not in the form "TYPE/SUBTYPE [EXT0 [EXT1 [...]"toMimeTypesString()public final boolean isApplicationType()
public final boolean isTextType()
public final boolean isImageType()
public final boolean isVideoType()
public boolean isExtSupported(String s)
This method is used to determine whether or not the file extension in the string passed is associated with this mime type or not.
s - The string to look for the file extension in (or just the file
extension). We only look at the characters following the last
period in the string (or the entire string if no period is
present). The compare is case insensitive. If you pass null,
we return false.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||