Package org.apache.http.message
Class BasicHeaderValueFormatter
- java.lang.Object
-
- org.apache.http.message.BasicHeaderValueFormatter
-
- All Implemented Interfaces:
HeaderValueFormatter
@Contract(threading=IMMUTABLE) public class BasicHeaderValueFormatter extends java.lang.Object implements HeaderValueFormatter
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 BasicHeaderValueFormatter
DEFAULT
Deprecated.(4.3) useINSTANCE
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 Summary
Constructors Constructor Description BasicHeaderValueFormatter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
formatElements(HeaderElement[] elems, boolean quote, HeaderValueFormatter formatter)
Formats an array of header elements.CharArrayBuffer
formatElements(CharArrayBuffer charBuffer, HeaderElement[] elems, boolean quote)
Formats an array of header elements.static java.lang.String
formatHeaderElement(HeaderElement elem, boolean quote, HeaderValueFormatter formatter)
Formats a header element.CharArrayBuffer
formatHeaderElement(CharArrayBuffer charBuffer, HeaderElement elem, boolean quote)
Formats one header element.static java.lang.String
formatNameValuePair(NameValuePair nvp, boolean quote, HeaderValueFormatter formatter)
Formats a name-value pair.CharArrayBuffer
formatNameValuePair(CharArrayBuffer charBuffer, NameValuePair nvp, boolean quote)
Formats one name-value pair, where the value is optional.static java.lang.String
formatParameters(NameValuePair[] nvps, boolean quote, HeaderValueFormatter formatter)
Formats a set of parameters.CharArrayBuffer
formatParameters(CharArrayBuffer charBuffer, NameValuePair[] nvps, boolean quote)
Formats the parameters of a header element.
-
-
-
Field Detail
-
DEFAULT
@Deprecated public static final BasicHeaderValueFormatter DEFAULT
Deprecated.(4.3) useINSTANCE
A default instance of this class, for use as default or fallback. Note thatBasicHeaderValueFormatter
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.
-
INSTANCE
public static final BasicHeaderValueFormatter INSTANCE
-
SEPARATORS
public static final java.lang.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 java.lang.String UNSAFE_CHARS
Unsafe special characters that must be escaped using the backslash character- See Also:
- Constant Field Values
-
-
Method Detail
-
formatElements
public static java.lang.String formatElements(HeaderElement[] elems, boolean quote, HeaderValueFormatter formatter)
Formats an array of header elements.- Parameters:
elems
- the header elements 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 header elements
-
formatElements
public CharArrayBuffer formatElements(CharArrayBuffer charBuffer, HeaderElement[] elems, boolean quote)
Description copied from interface:HeaderValueFormatter
Formats an array of header elements.- Specified by:
formatElements
in interfaceHeaderValueFormatter
- Parameters:
charBuffer
- the buffer to append to, ornull
to create a new bufferelems
- the header elements to formatquote
-true
to always format with quoted values,false
to use quotes only when necessary- Returns:
- a buffer with the formatted header elements.
If the
buffer
argument was notnull
, that buffer will be used and returned.
-
formatHeaderElement
public static java.lang.String formatHeaderElement(HeaderElement elem, boolean quote, HeaderValueFormatter formatter)
Formats a header element.- Parameters:
elem
- the header element 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 header element
-
formatHeaderElement
public CharArrayBuffer formatHeaderElement(CharArrayBuffer charBuffer, HeaderElement elem, boolean quote)
Description copied from interface:HeaderValueFormatter
Formats one header element.- Specified by:
formatHeaderElement
in interfaceHeaderValueFormatter
- Parameters:
charBuffer
- the buffer to append to, ornull
to create a new bufferelem
- the header element to formatquote
-true
to always format with quoted values,false
to use quotes only when necessary- Returns:
- a buffer with the formatted header element.
If the
buffer
argument was notnull
, that buffer will be used and returned.
-
formatParameters
public static java.lang.String formatParameters(NameValuePair[] 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, NameValuePair[] nvps, boolean quote)
Description copied from interface:HeaderValueFormatter
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.- Specified by:
formatParameters
in interfaceHeaderValueFormatter
- Parameters:
charBuffer
- the buffer to append to, ornull
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 necessary- Returns:
- a buffer with the formatted parameters.
If the
buffer
argument was notnull
, that buffer will be used and returned.
-
formatNameValuePair
public static java.lang.String formatNameValuePair(NameValuePair 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, NameValuePair nvp, boolean quote)
Description copied from interface:HeaderValueFormatter
Formats one name-value pair, where the value is optional.- Specified by:
formatNameValuePair
in interfaceHeaderValueFormatter
- Parameters:
charBuffer
- the buffer to append to, ornull
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 necessary- Returns:
- a buffer with the formatted name-value pair.
If the
buffer
argument was notnull
, that buffer will be used and returned.
-
-