Package com.foxinmy.weixin4j.http
Class HeaderValueFormatter
- java.lang.Object
-
- com.foxinmy.weixin4j.http.HeaderValueFormatter
-
public class HeaderValueFormatter extends Object
Basic implementation for formatting header value elements. Instances of this class are stateless and thread-safe. Derived classes are expected to maintain these properties.- Since:
- 4.0
-
-
Field Summary
Fields Modifier and Type Field Description static HeaderValueFormatter
INSTANCE
static String
SEPARATORS
Special characters that can be used as separators in HTTP parameters.static String
UNSAFE_CHARS
Unsafe special characters that must be escaped using the backslash character
-
Constructor Summary
Constructors Constructor Description HeaderValueFormatter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doFormatValue(CharArrayBuffer buffer, String value, boolean quote)
Actually formats the value of a name-value pair.protected int
estimateNameValuePairLen(NameValue nvp)
Estimates the length of a formatted name-value pair.protected int
estimateParametersLen(NameValue[] nvps)
Estimates the length of formatted parameters.CharArrayBuffer
formatNameValuePair(CharArrayBuffer charBuffer, NameValue nvp, boolean quote)
static String
formatNameValuePair(NameValue nvp, boolean quote, HeaderValueFormatter formatter)
Formats a name-value pair.CharArrayBuffer
formatParameters(CharArrayBuffer charBuffer, NameValue[] nvps, boolean quote)
static String
formatParameters(NameValue[] nvps, boolean quote, HeaderValueFormatter formatter)
Formats a set of parameters.protected boolean
isSeparator(char ch)
Checks whether a character is aseparator
.protected boolean
isUnsafe(char ch)
Checks whether a character isunsafe
.
-
-
-
Field Detail
-
INSTANCE
public static final HeaderValueFormatter INSTANCE
-
SEPARATORS
public static final String SEPARATORS
Special characters that can be used as separators in HTTP parameters. These special characters MUST be in a quoted string to be used within a parameter value .- See Also:
- Constant Field Values
-
UNSAFE_CHARS
public static final String UNSAFE_CHARS
Unsafe special characters that must be escaped using the backslash character- See Also:
- Constant Field Values
-
-
Method Detail
-
formatParameters
public static String formatParameters(NameValue[] nvps, boolean quote, HeaderValueFormatter formatter)
Formats a set of parameters.- Parameters:
nvps
- the parameters to formatquote
-true
to always format with quoted values,false
to use quotes only when necessaryformatter
- the formatter to use, ornull
for thedefault
- Returns:
- the formatted parameters
-
formatParameters
public CharArrayBuffer formatParameters(CharArrayBuffer charBuffer, NameValue[] nvps, boolean quote)
-
estimateParametersLen
protected int estimateParametersLen(NameValue[] nvps)
Estimates the length of formatted parameters.- Parameters:
nvps
- the parameters to format, ornull
- Returns:
- a length estimate, in number of characters
-
formatNameValuePair
public static String formatNameValuePair(NameValue nvp, boolean quote, HeaderValueFormatter formatter)
Formats a name-value pair.- Parameters:
nvp
- the name-value pair to formatquote
-true
to always format with a quoted value,false
to use quotes only when necessaryformatter
- the formatter to use, ornull
for thedefault
- Returns:
- the formatted name-value pair
-
formatNameValuePair
public CharArrayBuffer formatNameValuePair(CharArrayBuffer charBuffer, NameValue nvp, boolean quote)
-
estimateNameValuePairLen
protected int estimateNameValuePairLen(NameValue nvp)
Estimates the length of a formatted name-value pair.- Parameters:
nvp
- the name-value pair to format, ornull
- Returns:
- a length estimate, in number of characters
-
doFormatValue
protected void doFormatValue(CharArrayBuffer buffer, String value, boolean quote)
Actually formats the value of a name-value pair. This does not include a leading = character. Called fromformatNameValuePair
.- Parameters:
buffer
- the buffer to append to, nevernull
value
- the value to append, nevernull
quote
-true
to always format with quotes,false
to use quotes only when necessary
-
isSeparator
protected boolean isSeparator(char ch)
Checks whether a character is aseparator
.- Parameters:
ch
- the character to check- Returns:
true
if the character is a separator,false
otherwise
-
isUnsafe
protected boolean isUnsafe(char ch)
Checks whether a character isunsafe
.- Parameters:
ch
- the character to check- Returns:
true
if the character is unsafe,false
otherwise
-
-