Top Description Fields Constructors Methods
org.apache.tomcat.util.http.fileupload.util.mime

public final Class RFC2231Utility

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .UnsupportedEncodingException

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
RFC 2231, RFC 5987

Field Summary

Modifier and TypeField and Description
private static final byte[]
HEX_DECODE

The Hexadecimal decode value.

private static final char[]
HEX_DIGITS

The Hexadecimal values char array.

private static final byte
MASK

The Hexadecimal representation of 127.

private static final int
MASK_128

The Hexadecimal representation of 128.

Constructor Summary

AccessConstructor and Description
private
RFC2231Utility()

Private constructor so that no instances can be created.

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

Decoded text based on charset encoding
decodeText
(final String
- Text to be decoded has a format of <charset>'<language>'<encoded_value> and ASCII only
encodedText
)

Decode a string of text obtained from a HTTP header as per RFC 2231

Eg 1.

private static byte[]

Returns:

Byte array of characters decoded from ASCII table
fromHex
(final String
- ASCII text input
text
)

Convert text to their corresponding Hex value.

private static String
getJavaCharset(final String mimeCharset)

public static boolean

Returns:

true, if encoded as per RFC 2231, false otherwise
hasEncodedValue
(final String
The parameter, which is being checked.
paramName
)

Checks if Asterisk (*) at the end of parameter name to indicate, if it has charset and language information to decode the value.

public static String

Returns:

stripped paramName of Asterisk (*), if RFC2231 encoded
stripDelimiter
(final String
The parameter, which is being inspected.
paramName
)

If paramName has Asterisk (*) at the end, it will be stripped off, else the passed value will be returned.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HEX_DECODEback to summary
private static final byte[] HEX_DECODE

The Hexadecimal decode value.

HEX_DIGITSback to summary
private static final char[] HEX_DIGITS

The Hexadecimal values char array.

MASKback to summary
private static final byte MASK

The Hexadecimal representation of 127.

MASK_128back to summary
private static final int MASK_128

The Hexadecimal representation of 128.

Constructor Detail

RFC2231Utilityback to summary
private RFC2231Utility()

Private constructor so that no instances can be created. This class contains only static utility methods.

Method Detail

decodeTextback to summary
public static String decodeText(final String encodedText) throws UnsupportedEncodingException

Decode a string of text obtained from a HTTP header as per RFC 2231

Eg 1. us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A will be decoded to This is ***fun***

Eg 2. iso-8859-1'en'%A3%20rate will be decoded to £ rate

Eg 3. UTF-8''%c2%a3%20and%20%e2%82%ac%20rates will be decoded to £ and € rates

Parameters
encodedText:String

- Text to be decoded has a format of <charset>'<language>'<encoded_value> and ASCII only

Returns:String

Decoded text based on charset encoding

Exceptions
UnsupportedEncodingException:
The requested character set wasn't found.
fromHexback to summary
private static byte[] fromHex(final String text)

Convert text to their corresponding Hex value.

Parameters
text:String

- ASCII text input

Returns:byte[]

Byte array of characters decoded from ASCII table

getJavaCharsetback to summary
private static String getJavaCharset(final String mimeCharset)
hasEncodedValueback to summary
public static boolean hasEncodedValue(final String paramName)

Checks if Asterisk (*) at the end of parameter name to indicate, if it has charset and language information to decode the value.

Parameters
paramName:String

The parameter, which is being checked.

Returns:boolean

true, if encoded as per RFC 2231, false otherwise

stripDelimiterback to summary
public static String stripDelimiter(final String paramName)

If paramName has Asterisk (*) at the end, it will be stripped off, else the passed value will be returned.

Parameters
paramName:String

The parameter, which is being inspected.

Returns:String

stripped paramName of Asterisk (*), if RFC2231 encoded