org.apache.http.message.BasicHeaderValueFormatter
Basic implementation for formatting header value elements.
Instances of this class are stateless and thread-safe.
Derived classes are expected to maintain these properties.
Summary
Constants
Public Constructors
Public Methods
|
|
|
|
|
CharArrayBuffer |
formatElements(CharArrayBuffer buffer, HeaderElement[] elems, boolean quote) |
|
|
final |
static |
|
String |
formatElements(HeaderElement[] elems, boolean quote, HeaderValueFormatter formatter) |
|
|
|
|
|
CharArrayBuffer |
formatHeaderElement(CharArrayBuffer buffer, HeaderElement elem, boolean quote) |
|
|
final |
static |
|
String |
formatHeaderElement(HeaderElement elem, boolean quote, HeaderValueFormatter formatter) |
|
|
final |
static |
|
String |
formatNameValuePair(NameValuePair nvp, boolean quote, HeaderValueFormatter formatter) |
|
|
|
|
|
CharArrayBuffer |
formatNameValuePair(CharArrayBuffer buffer, NameValuePair nvp, boolean quote) |
|
|
|
|
|
CharArrayBuffer |
formatParameters(CharArrayBuffer buffer, NameValuePair[] nvps, boolean quote) |
|
|
final |
static |
|
String |
formatParameters(NameValuePair[] nvps, boolean quote, HeaderValueFormatter formatter) |
Protected Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Constants
A default instance of this class, for use as default or fallback.
Note that
BasicHeaderValueFormatter is not a singleton, there
can be many instances of the class itself and of derived classes.
The instance here provides non-customized, default behavior.
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 .
Constant Value:
" ;,:@()<>\"/[]?={} "
public
static
final
String
UNSAFE_CHARS
Unsafe special characters that must be escaped using the backslash
character
Constant Value:
""\"
Public Constructors
public
BasicHeaderValueFormatter()
Public Methods
Formats an array of header elements.
Formats an array of header elements.
Parameters
elems
| the header elements to format |
quote
| true to always format with quoted values,
false to use quotes only when necessary |
formatter
| the formatter to use, or null
for the default |
Returns
- the formatted header elements
Formats one header element.
Formats a header element.
Parameters
elem
| the header element to format |
quote
| true to always format with quoted values,
false to use quotes only when necessary |
formatter
| the formatter to use, or null
for the default |
Returns
- the formatted header element
Formats a name-value pair.
Parameters
nvp
| the name-value pair to format |
quote
| true to always format with a quoted value,
false to use quotes only when necessary |
formatter
| the formatter to use, or null
for the default |
Returns
- the formatted name-value pair
Formats one name-value pair, where the value is optional.
Formats the parameters of a header element.
That's a list of name-value pairs, to be separated by semicolons.
This method will not generate a leading semicolon.
Formats a set of parameters.
Parameters
nvps
| the parameters to format |
quote
| true to always format with quoted values,
false to use quotes only when necessary |
formatter
| the formatter to use, or null
for the default |
Protected Methods
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 from
formatNameValuePair.
Parameters
buffer
| the buffer to append to, never null |
value
| the value to append, never null |
quote
| true to always format with quotes,
false to use quotes only when necessary
|
protected
int
estimateElementsLen(HeaderElement[] elems)
Estimates the length of formatted header elements.
Parameters
elems
| the header elements to format, or null |
Returns
- a length estimate, in number of characters
protected
int
estimateHeaderElementLen(HeaderElement elem)
Estimates the length of a formatted header element.
Parameters
elem
| the header element to format, or null |
Returns
- a length estimate, in number of characters
protected
int
estimateNameValuePairLen(NameValuePair nvp)
Estimates the length of a formatted name-value pair.
Parameters
nvp
| the name-value pair to format, or null |
Returns
- a length estimate, in number of characters
protected
int
estimateParametersLen(NameValuePair[] nvps)
Estimates the length of formatted parameters.
Parameters
nvps
| the parameters to format, or null |
Returns
- a length estimate, in number of characters
protected
boolean
isSeparator(char ch)
Checks whether a character is a
separator.
Parameters
ch
| the character to check |
Returns
true
if the character is a separator,
false
otherwise
protected
boolean
isUnsafe(char ch)
Checks whether a character is
unsafe.
Parameters
ch
| the character to check |
Returns
true
if the character is unsafe,
false
otherwise