Package com.helger.commons.mime
Class MimeTypeParser
java.lang.Object
com.helger.commons.mime.MimeTypeParser
This class handles the String parsing of MIME types.
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic char[]static booleanCheck if the passed string is a valid MIME token by checking that the length is at least 1 and all chars match theisTokenChar(char)condition.static booleanisTokenChar(char c) Check if the passed character is a valid token character.static booleanisTSpecialChar(char c) Check if the passed character is a special character according to RFC 2045 chapter 5.1static MimeTypeparseMimeType(String sMimeType) Try to convert the string representation of a MIME type to an object.static MimeTypeparseMimeType(String sMimeType, EMimeQuoting eQuotingAlgorithm) Try to convert the string representation of a MIME type to an object.static MimeTypesafeParseMimeType(String sMimeType) Try to convert the string representation of a MIME type to an object.static MimeTypesafeParseMimeType(String sMimeType, EMimeQuoting eQuotingAlgorithm) Try to convert the string representation of a MIME type to an object.
-
Method Details
-
getAllTSpecialChars
- Returns:
- A copy of the array with all TSpecial chars. Never
null.
-
isTSpecialChar
public static boolean isTSpecialChar(char c) Check if the passed character is a special character according to RFC 2045 chapter 5.1- Parameters:
c- The character to check- Returns:
trueif the character is a special character,falseotherwise.
-
isTokenChar
public static boolean isTokenChar(char c) Check if the passed character is a valid token character. According to RFC 2045 this can be any (US-ASCII) CHAR except SPACE, CTLs, or tspecials- Parameters:
c- The character to check.- Returns:
trueif the passed character is a valid token character,falseotherwise
-
isToken
Check if the passed string is a valid MIME token by checking that the length is at least 1 and all chars match theisTokenChar(char)condition.- Parameters:
sToken- The token to be checked. May benull.- Returns:
trueif the passed string is valid token,falseotherwise.
-
parseMimeType
@Nullable public static MimeType parseMimeType(@Nullable String sMimeType) throws MimeTypeParserException Try to convert the string representation of a MIME type to an object. The default quoting algorithmCMimeType.DEFAULT_QUOTINGis used to unquote strings.- Parameters:
sMimeType- The string representation to be converted. May benull.- Returns:
nullif the parsed string is empty.- Throws:
MimeTypeParserException- In case of an error
-
parseMimeType
@Nullable public static MimeType parseMimeType(@Nullable String sMimeType, @Nonnull EMimeQuoting eQuotingAlgorithm) throws MimeTypeParserException Try to convert the string representation of a MIME type to an object. The default quoting algorithmCMimeType.DEFAULT_QUOTINGis used to un-quote strings.- Parameters:
sMimeType- The string representation to be converted. May benull.eQuotingAlgorithm- The quoting algorithm to be used to un-quote parameter values. May not benull.- Returns:
nullif the parsed string is empty.- Throws:
MimeTypeParserException- In case of an error
-
safeParseMimeType
Try to convert the string representation of a MIME type to an object. The default quoting algorithmCMimeType.DEFAULT_QUOTINGis used to unquote strings. Compared toparseMimeType(String)this method swallows allMimeTypeParserExceptionand simply returnsnull. Additionally if the string is RFC 2616 encoded, it is decoded before parsing (since 9.4.6).- Parameters:
sMimeType- The string representation to be converted. May benull.- Returns:
nullif the parsed string is empty or not a valid mime type.
-
safeParseMimeType
@Nullable public static MimeType safeParseMimeType(@Nullable String sMimeType, @Nonnull EMimeQuoting eQuotingAlgorithm) Try to convert the string representation of a MIME type to an object. The default quoting algorithmCMimeType.DEFAULT_QUOTINGis used to unquote strings. Compared toparseMimeType(String, EMimeQuoting)this method swallows allMimeTypeParserExceptionand simply returnsnull. Additionally if the string is RFC 2616 encoded, it is decoded before parsing (since 9.4.6).- Parameters:
sMimeType- The string representation to be converted. May benull.eQuotingAlgorithm- The quoting algorithm to be used to un-quote parameter values. May not benull.- Returns:
nullif the parsed string is empty or not a valid mime type.- Since:
- 9.4.6
-