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>
@NotThreadSafe public class MimeType extends Object implements IMimeType, IComparable<MimeType>
Represents a single MIME type as the combination of the content type and the sub-type and parameters.- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description MimeType(EMimeContentType eContentType, String sContentSubType)Constructor without parameters.MimeType(EMimeContentType eContentType, String sContentSubType, Collection<? extends MimeTypeParameter> aParameters)Constructor without parameters.MimeType(IMimeType aOther)Kind of a copy constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MimeTypeaddParameter(MimeTypeParameter aParameter)Add a parameter.MimeTypeaddParameter(String sAttribute, String sValue)Add a parameter.intcompareTo(MimeType o)booleanequals(Object o)ICommonsList<MimeTypeParameter>getAllParameters()StringgetAsString(EMimeQuoting eQuotingAlgorithm)Get the MIME type including all parameters as a single string.StringgetAsStringWithoutParameters()MimeTypegetClone()StringgetContentSubType()EMimeContentTypegetContentType()MimeTypegetCopyWithoutParameters()MimeTypeParametergetParameterAtIndex(int nIndex)Get the parameter at the specified index.intgetParameterCount()StringgetParametersAsString(EMimeQuoting eQuotingAlgorithm)Get all MIME type parameters as a single string but without the leading content and sub type.StringgetParameterValueWithName(String sParamName)Get the value of the parameter with the specified name.MimeTypeParametergetParameterWithName(String sParamName)Get the parameter with the specified name.booleanhasAnyParameters()inthashCode()EChangeremoveAllParameters()Remove all existing parameters.EChangeremoveParameter(MimeTypeParameter aParameter)Remove the specified parameter from this MIME type.EChangeremoveParameterAtIndex(int nIndex)Remove the parameter at the specified index.EChangeremoveParameterWithName(String sParamName)Remove the parameter with the specified name.StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.compare.IComparable
isEQ, isGE, isGT, isLE, isLT, isNE
-
Methods inherited from interface com.helger.commons.mime.IMimeType
getAsString, hasParameterWithName
-
-
-
-
Constructor Detail
-
MimeType
public MimeType(@Nonnull IMimeType aOther)
Kind of a copy constructor- Parameters:
aOther- The other object to copy the data from
-
MimeType
public MimeType(@Nonnull EMimeContentType eContentType, @Nonnull @Nonempty String sContentSubType)
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 Detail
-
getContentType
@Nonnull public EMimeContentType getContentType()
- Specified by:
getContentTypein interfaceIMimeType- Returns:
- The content type. Never
null.
-
getContentSubType
@Nonnull @Nonempty public String getContentSubType()
- Specified by:
getContentSubTypein interfaceIMimeType- Returns:
- The content sub type. Never
null.
-
getAsString
@Nonnull @Nonempty public String getAsString(@Nonnull EMimeQuoting eQuotingAlgorithm)
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:
IMimeType.getAsStringWithoutParameters(),IMimeType.getParametersAsString(EMimeQuoting)
-
getAsStringWithoutParameters
@Nonnull public String getAsStringWithoutParameters()
- Specified by:
getAsStringWithoutParametersin interfaceIMimeType- Returns:
- The combined string to be used as text representation but without
the parameters:
contentType '/' subType - See Also:
IMimeType.getAsString()
-
getParametersAsString
@Nonnull public String getParametersAsString(@Nonnull EMimeQuoting eQuotingAlgorithm)
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:
IMimeType.getAsString(EMimeQuoting),IMimeType.getAsStringWithoutParameters()
-
addParameter
@Nonnull public MimeType addParameter(@Nonnull @Nonempty String sAttribute, @Nonnull String sValue)
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
@Nonnull public MimeType addParameter(@Nonnull MimeTypeParameter aParameter)
Add a parameter.- Parameters:
aParameter- The parameter to be added. May not benull.- Returns:
- this
-
removeParameter
@Nonnull public EChange removeParameter(@Nullable MimeTypeParameter aParameter)
Remove the specified parameter from this MIME type.- Parameters:
aParameter- The parameter to be removed. May benull.- Returns:
EChange.CHANGEDif removal was successful
-
removeParameterAtIndex
@Nonnull public EChange removeParameterAtIndex(int nIndex)
Remove the parameter at the specified index.- Parameters:
nIndex- The index to remove. Should be ≥ 0.- Returns:
EChange.CHANGEDif removal was successful
-
removeAllParameters
@Nonnull public EChange removeAllParameters()
Remove all existing parameters.- Returns:
EChange.CHANGEDif at least one parameter was present
-
removeParameterWithName
@Nonnull public EChange removeParameterWithName(@Nullable String sParamName)
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
@Nonnegative public int getParameterCount()
- Specified by:
getParameterCountin interfaceIMimeType- Returns:
- The number of parameters. Alway ≥ 0.
-
getAllParameters
@Nonnull @ReturnsMutableCopy public ICommonsList<MimeTypeParameter> getAllParameters()
- Specified by:
getAllParametersin interfaceIMimeType- Returns:
- All present parameters. May not be
nullbut empty.
-
getParameterAtIndex
@Nullable public MimeTypeParameter getParameterAtIndex(@Nonnegative int nIndex)
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
@Nullable public MimeTypeParameter getParameterWithName(@Nullable String sParamName)
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
@Nullable public String getParameterValueWithName(@Nullable String sParamName)
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
@Nonnull public MimeType getClone()
- Specified by:
getClonein interfaceICloneable<IMimeType>- Returns:
- A 100% deep-copy of the implementing class.
-
getCopyWithoutParameters
@Nonnull public MimeType 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
public int compareTo(@Nonnull MimeType o)
- Specified by:
compareToin interfaceComparable<MimeType>
-
-