@Immutable public class BasicHeaderValueFormatter extends java.lang.Object implements HeaderValueFormatter
Modifier and Type | Field and Description |
---|---|
static BasicHeaderValueFormatter |
DEFAULT
Deprecated.
(4.3) use
INSTANCE |
static BasicHeaderValueFormatter |
INSTANCE |
static java.lang.String |
SEPARATORS
Special characters that can be used as separators in HTTP parameters.
|
static java.lang.String |
UNSAFE_CHARS
Unsafe special characters that must be escaped using the backslash
character
|
Constructor and Description |
---|
BasicHeaderValueFormatter() |
Modifier and Type | Method and Description |
---|---|
protected void |
doFormatValue(CharArrayBuffer buffer,
java.lang.String value,
boolean quote)
Actually formats the value of a name-value pair.
|
protected int |
estimateElementsLen(HeaderElement[] elems)
Estimates the length of formatted header elements.
|
protected int |
estimateHeaderElementLen(HeaderElement elem)
Estimates the length of a formatted header element.
|
protected int |
estimateNameValuePairLen(NameValuePair nvp)
Estimates the length of a formatted name-value pair.
|
protected int |
estimateParametersLen(NameValuePair[] nvps)
Estimates the length of formatted parameters.
|
CharArrayBuffer |
formatElements(CharArrayBuffer charBuffer,
HeaderElement[] elems,
boolean quote)
Formats an array of header elements.
|
static java.lang.String |
formatElements(HeaderElement[] elems,
boolean quote,
HeaderValueFormatter formatter)
Formats an array of header elements.
|
CharArrayBuffer |
formatHeaderElement(CharArrayBuffer charBuffer,
HeaderElement elem,
boolean quote)
Formats one header element.
|
static java.lang.String |
formatHeaderElement(HeaderElement elem,
boolean quote,
HeaderValueFormatter formatter)
Formats a header element.
|
CharArrayBuffer |
formatNameValuePair(CharArrayBuffer charBuffer,
NameValuePair nvp,
boolean quote)
Formats one name-value pair, where the value is optional.
|
static java.lang.String |
formatNameValuePair(NameValuePair nvp,
boolean quote,
HeaderValueFormatter formatter)
Formats a name-value pair.
|
CharArrayBuffer |
formatParameters(CharArrayBuffer charBuffer,
NameValuePair[] nvps,
boolean quote)
Formats the parameters of a header element.
|
static java.lang.String |
formatParameters(NameValuePair[] nvps,
boolean quote,
HeaderValueFormatter formatter)
Formats a set of parameters.
|
protected boolean |
isSeparator(char ch)
Checks whether a character is a
separator . |
protected boolean |
isUnsafe(char ch)
Checks whether a character is
unsafe . |
@Deprecated public static final BasicHeaderValueFormatter DEFAULT
INSTANCE
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 BasicHeaderValueFormatter INSTANCE
public static final java.lang.String SEPARATORS
public static final java.lang.String UNSAFE_CHARS
public static java.lang.String formatElements(HeaderElement[] elems, boolean quote, HeaderValueFormatter formatter)
elems
- the header elements to formatquote
- true
to always format with quoted values,
false
to use quotes only when necessaryformatter
- the formatter to use, or null
for the default
public CharArrayBuffer formatElements(CharArrayBuffer charBuffer, HeaderElement[] elems, boolean quote)
HeaderValueFormatter
formatElements
in interface HeaderValueFormatter
charBuffer
- the buffer to append to, or
null
to create a new bufferelems
- the header elements to formatquote
- true
to always format with quoted values,
false
to use quotes only when necessarybuffer
argument was not null
,
that buffer will be used and returned.protected int estimateElementsLen(HeaderElement[] elems)
elems
- the header elements to format, or null
public static java.lang.String formatHeaderElement(HeaderElement elem, boolean quote, HeaderValueFormatter formatter)
elem
- the header element to formatquote
- true
to always format with quoted values,
false
to use quotes only when necessaryformatter
- the formatter to use, or null
for the default
public CharArrayBuffer formatHeaderElement(CharArrayBuffer charBuffer, HeaderElement elem, boolean quote)
HeaderValueFormatter
formatHeaderElement
in interface HeaderValueFormatter
charBuffer
- the buffer to append to, or
null
to create a new bufferelem
- the header element to formatquote
- true
to always format with quoted values,
false
to use quotes only when necessarybuffer
argument was not null
,
that buffer will be used and returned.protected int estimateHeaderElementLen(HeaderElement elem)
elem
- the header element to format, or null
public static java.lang.String formatParameters(NameValuePair[] nvps, boolean quote, HeaderValueFormatter formatter)
nvps
- the parameters to formatquote
- true
to always format with quoted values,
false
to use quotes only when necessaryformatter
- the formatter to use, or null
for the default
public CharArrayBuffer formatParameters(CharArrayBuffer charBuffer, NameValuePair[] nvps, boolean quote)
HeaderValueFormatter
formatParameters
in interface HeaderValueFormatter
charBuffer
- the buffer to append to, or
null
to create a new buffernvps
- the parameters (name-value pairs) to formatquote
- true
to always format with quoted values,
false
to use quotes only when necessarybuffer
argument was not null
,
that buffer will be used and returned.protected int estimateParametersLen(NameValuePair[] nvps)
nvps
- the parameters to format, or null
public static java.lang.String formatNameValuePair(NameValuePair nvp, boolean quote, HeaderValueFormatter formatter)
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, or null
for the default
public CharArrayBuffer formatNameValuePair(CharArrayBuffer charBuffer, NameValuePair nvp, boolean quote)
HeaderValueFormatter
formatNameValuePair
in interface HeaderValueFormatter
charBuffer
- the buffer to append to, or
null
to create a new buffernvp
- the name-value pair to formatquote
- true
to always format with a quoted value,
false
to use quotes only when necessarybuffer
argument was not null
,
that buffer will be used and returned.protected int estimateNameValuePairLen(NameValuePair nvp)
nvp
- the name-value pair to format, or null
protected void doFormatValue(CharArrayBuffer buffer, java.lang.String value, boolean quote)
formatNameValuePair
.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 necessaryprotected boolean isSeparator(char ch)
separator
.ch
- the character to checktrue
if the character is a separator,
false
otherwiseprotected boolean isUnsafe(char ch)
unsafe
.ch
- the character to checktrue
if the character is unsafe,
false
otherwise