Package eu.medsea.mimeutil
Class MimeType
- java.lang.Object
-
- eu.medsea.mimeutil.MimeType
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable
- Direct Known Subclasses:
TextMimeType
public class MimeType extends java.lang.Object implements java.lang.Comparable, java.io.Serializable
This class represents a simple MimeType object. A mime type is made up of two parts<media type>/<sub type>
. The media type can be something likeapplication
ortext
and the the sub type can be something likexml
orplain
. Both the media type and sub type can also be the wild card*
such as*/*
andtext/*
. Note, if the media type is the wild card then the sub type must also be a wild card.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(java.lang.Object arg0)
Allows us to use MimeType(s) in Sortable Set's such as the TreeSet.boolean
equals(java.lang.Object o)
Overrides the equals method ofjava.lang.Object
.java.lang.String
getMediaType()
Get the media type part of the mime type.int
getSpecificity()
This indicates how specific the mime types is i.e.java.lang.String
getSubType()
Get the sub type of the mime typeint
hashCode()
Get the hashCode of this MimeType.java.lang.String
toString()
Overrides the toString method ofjava.lang.Object
.
-
-
-
Constructor Detail
-
MimeType
public MimeType(MimeType mimeType)
Construct a MimeType from another MimeType instance- Parameters:
mimeType
-
-
MimeType
public MimeType(java.lang.String mimeType) throws MimeException
Construct a mime type from a String such astext/plain
. It tries to ensure that the mime type pattern passed in is correctly formatted.- Parameters:
mimeType
-- Throws:
MimeException
-
-
Method Detail
-
getMediaType
public java.lang.String getMediaType()
Get the media type part of the mime type.- Returns:
- media type
-
getSubType
public java.lang.String getSubType()
Get the sub type of the mime type- Returns:
- sub type
-
hashCode
public int hashCode()
Get the hashCode of this MimeType. The hashCode is calculate as (31 * mediaType.hashCode()) + subType.hashCode()- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- calculated hashCode
- See Also:
Object.hashCode()
-
equals
public boolean equals(java.lang.Object o)
Overrides the equals method ofjava.lang.Object
. This is able to compare against another MimeType instance or a string representation of a mime type.- Overrides:
equals
in classjava.lang.Object
- Returns:
- true if the types match else false.
- See Also:
Object.equals(Object o)
-
toString
public java.lang.String toString()
Overrides the toString method ofjava.lang.Object
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- String representation i.e.
<media type>/<sub type>.
- See Also:
Object.toString()
-
getSpecificity
public int getSpecificity()
This indicates how specific the mime types is i.e. how good a match the mime type is when returned from the getMimeTypes(...) calls.This is calculated by the number of times this MimeType would be returned if the Collection was not normalised. The higher the count the more MimeDetectors have matched this type. As this can be a false positive for types such as application/octect-stream and text/plain where they would be returned by multiple MimeDetector(s). These types are referred to as root mime types where ALL mime types derive from application/octet-stream and all text/* types derive from text/plan so in these cases we set the specificity to 0 no matter how many times they match. This ensures they are regarded as the least specific in the returned Collection.
- Returns:
- how specific this MimeType is according to the rest of the MimeTypes in a Collection.
-
compareTo
public int compareTo(java.lang.Object arg0)
Allows us to use MimeType(s) in Sortable Set's such as the TreeSet.- Specified by:
compareTo
in interfacejava.lang.Comparable
-
-