Package com.helger.commons.mime
Class MimeType
java.lang.Object
com.helger.commons.mime.MimeType
- All Implemented Interfaces:
IComparable<MimeType>,ICloneable<IMimeType>,IMimeType,Comparable<MimeType>
Represents a single MIME type as the combination of the content type and the
sub-type and parameters.
- Author:
- Philip Helger
-
Constructor Summary
ConstructorsConstructorDescriptionMimeType(EMimeContentType eContentType, String sContentSubType) Constructor without parameters.MimeType(EMimeContentType eContentType, String sContentSubType, Collection<? extends MimeTypeParameter> aParameters) Constructor without parameters.Kind of a copy constructor -
Method Summary
Modifier and TypeMethodDescriptionaddParameter(MimeTypeParameter aParameter) Add a parameter.addParameter(String sAttribute, String sValue) Add a parameter.intbooleangetAsString(EMimeQuoting eQuotingAlgorithm) Get the MIME type including all parameters as a single string.getClone()getParameterAtIndex(int nIndex) Get the parameter at the specified index.intgetParametersAsString(EMimeQuoting eQuotingAlgorithm) Get all MIME type parameters as a single string but without the leading content and sub type.getParameterValueWithName(String sParamName) Get the value of the parameter with the specified name.getParameterWithName(String sParamName) Get the parameter with the specified name.booleaninthashCode()Remove all existing parameters.removeParameter(MimeTypeParameter aParameter) Remove the specified parameter from this MIME type.removeParameterAtIndex(int nIndex) Remove the parameter at the specified index.removeParameterWithName(String sParamName) Remove the parameter with the specified name.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.commons.compare.IComparable
isEQ, isGE, isGT, isLE, isLT, isNEMethods inherited from interface com.helger.commons.mime.IMimeType
getAsString, hasParameterWithName
-
Constructor Details
-
MimeType
Kind of a copy constructor- Parameters:
aOther- The other object to copy the data from
-
MimeType
Constructor without parameters. To construct the MIME type "text/xml" you need to passEMimeContentType.TEXTand the String "xml" to this constructor.- Parameters:
eContentType- MIME content type. May not benull.sContentSubType- MIME content sub type. May neither benullnor empty.
-
MimeType
public MimeType(@Nonnull EMimeContentType eContentType, @Nonnull @Nonempty String sContentSubType, @Nullable Collection<? extends MimeTypeParameter> aParameters) Constructor without parameters. To construct the MIME type "text/xml" you need to passEMimeContentType.TEXTand the String "xml" to this constructor.- Parameters:
eContentType- MIME content type. May not benull.sContentSubType- MIME content sub type. May neither benullnor empty.aParameters- MIME type parameters. May benullor empty.
-
-
Method Details
-
getContentType
- Specified by:
getContentTypein interfaceIMimeType- Returns:
- The content type. Never
null.
-
getContentSubType
- Specified by:
getContentSubTypein interfaceIMimeType- Returns:
- The content sub type. Never
null.
-
getAsString
Description copied from interface:IMimeTypeGet the MIME type including all parameters as a single string. The specified quoting algorithm is used to quote parameter values (if necessary).- Specified by:
getAsStringin interfaceIMimeType- Parameters:
eQuotingAlgorithm- Quoting algorithm to be used- Returns:
- The combined string to be used as text representation:
contentType '/' subType ( ';' parameterName '=' parameterValue )* - See Also:
-
getAsStringWithoutParameters
- Specified by:
getAsStringWithoutParametersin interfaceIMimeType- Returns:
- The combined string to be used as text representation but without
the parameters:
contentType '/' subType - See Also:
-
getParametersAsString
Description copied from interface:IMimeTypeGet all MIME type parameters as a single string but without the leading content and sub type. The specified quoting algorithm is used to quote parameter values.- Specified by:
getParametersAsStringin interfaceIMimeType- Parameters:
eQuotingAlgorithm- Quoting algorithm to be used- Returns:
- The combined string to be used as text representation:
(';' parameterName '=' parameterValue )*. If no parameters are present, an empty String is returned! - See Also:
-
addParameter
Add a parameter.- Parameters:
sAttribute- Parameter name. Must neither benullnor empty and must matchMimeTypeParser.isToken(String).sValue- The value to use. May not benull. Must not be a valid MIME token.- Returns:
- this
-
addParameter
Add a parameter.- Parameters:
aParameter- The parameter to be added. May not benull.- Returns:
- this
-
removeParameter
Remove the specified parameter from this MIME type.- Parameters:
aParameter- The parameter to be removed. May benull.- Returns:
EChange.CHANGEDif removal was successful
-
removeParameterAtIndex
Remove the parameter at the specified index.- Parameters:
nIndex- The index to remove. Should be ≥ 0.- Returns:
EChange.CHANGEDif removal was successful
-
removeAllParameters
Remove all existing parameters.- Returns:
EChange.CHANGEDif at least one parameter was present
-
removeParameterWithName
Remove the parameter with the specified name.- Parameters:
sParamName- The name of the parameter to remove. May benull.- Returns:
EChange.CHANGEDif the parameter was removed,EChange.UNCHANGEDotherwise.
-
hasAnyParameters
public boolean hasAnyParameters()- Specified by:
hasAnyParametersin interfaceIMimeType- Returns:
trueif at least one parameter is present,falseif no parameter is present.
-
getParameterCount
- Specified by:
getParameterCountin interfaceIMimeType- Returns:
- The number of parameters. Alway ≥ 0.
-
getAllParameters
- Specified by:
getAllParametersin interfaceIMimeType- Returns:
- All present parameters. May not be
nullbut empty.
-
getParameterAtIndex
Description copied from interface:IMimeTypeGet the parameter at the specified index.- Specified by:
getParameterAtIndexin interfaceIMimeType- Parameters:
nIndex- The index to use. Should be ≥ 0.- Returns:
nullif the provided index is illegal.
-
getParameterWithName
Description copied from interface:IMimeTypeGet the parameter with the specified name. The names are matched case sensitive!- Specified by:
getParameterWithNamein interfaceIMimeType- Parameters:
sParamName- The parameter name to search. May benull.- Returns:
nullif no such parameter exists.
-
getParameterValueWithName
Description copied from interface:IMimeTypeGet the value of the parameter with the specified name. The names are matched case sensitive!- Specified by:
getParameterValueWithNamein interfaceIMimeType- Parameters:
sParamName- The parameter name to search. May benull.- Returns:
nullif no such parameter exists.
-
getClone
- Specified by:
getClonein interfaceICloneable<IMimeType>- Returns:
- A 100% deep-copy of the implementing class.
-
getCopyWithoutParameters
- Specified by:
getCopyWithoutParametersin interfaceIMimeType- Returns:
- A copy of this MIME type but only the content type and the sub
type. This method must even deliver a copy if no parameter are
present! May not return
null.
-
compareTo
- Specified by:
compareToin interfaceComparable<MimeType>
-
equals
-
hashCode
public int hashCode() -
toString
-