Package org.apache.commons.fileupload
Class RFC2231Utility
java.lang.Object
org.apache.commons.fileupload.RFC2231Utility
Utility class to decode/encode character set on HTTP Header fields based on RFC 2231. This implementation adheres to RFC 5987 in particular, which was
defined for HTTP headers.
RFC 5987 builds on RFC 2231, but has lesser scope like mandatory charset definition and no parameter continuation
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]The Hexadecimal decode value.private static final char[]The Hexadecimal values char array.private static final byteThe Hexadecimal representation of 127.private static final intThe Hexadecimal representation of 128.private static final charPercent character ''%''. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor so that no instances can be created. -
Method Summary
Modifier and TypeMethodDescription(package private) static StringdecodeText(String encodedText) Decodes a string of text obtained from a HTTP header as per RFC 2231private static byte[]Convertstextto their corresponding Hex value.private static StringgetJavaCharset(String mimeCharset) (package private) static booleanhasEncodedValue(String paramName) Checks if Asterisk (*) at the end of parameter name to indicate, if it has charset and language information to decode the value.(package private) static StringstripDelimiter(String paramName) IfparamNamehas Asterisk (*) at the end, it will be stripped off, else the passed value will be returned.
-
Field Details
-
PERCENT
private static final char PERCENTPercent character ''%''.- See Also:
-
HEX_DIGITS
private static final char[] HEX_DIGITSThe Hexadecimal values char array. -
MASK
private static final byte MASKThe Hexadecimal representation of 127.- See Also:
-
MASK_128
private static final int MASK_128The Hexadecimal representation of 128.- See Also:
-
HEX_DECODE
private static final byte[] HEX_DECODEThe Hexadecimal decode value.
-
-
Constructor Details
-
RFC2231Utility
private RFC2231Utility()Private constructor so that no instances can be created. This class contains only static utility methods.
-
-
Method Details
-
decodeText
Decodes a string of text obtained from a HTTP header as per RFC 2231Eg 1.
us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2Awill be decoded toThis is ***fun***Eg 2.
iso-8859-1'en'%A3%20ratewill be decoded to£ rateEg 3.
UTF-8''%c2%a3%20and%20%e2%82%ac%20rateswill be decoded to£ and € rates- Parameters:
encodedText- Text to be decoded has a format of<charset>'<language>'<encoded_value>and ASCII only- Returns:
- Decoded text based on charset encoding
- Throws:
UnsupportedEncodingException- The requested character set wasn't found.
-
fromHex
Convertstextto their corresponding Hex value.- Parameters:
text- ASCII text input- Returns:
- Byte array of characters decoded from ASCII table
-
getJavaCharset
-
hasEncodedValue
Checks if Asterisk (*) at the end of parameter name to indicate, if it has charset and language information to decode the value.- Parameters:
paramName- The parameter, which is being checked.- Returns:
true, if encoded as per RFC 2231,falseotherwise
-
stripDelimiter
IfparamNamehas Asterisk (*) at the end, it will be stripped off, else the passed value will be returned.- Parameters:
paramName- The parameter, which is being inspected.- Returns:
- stripped
paramNameof Asterisk (*), if RFC2231 encoded
-