Top Description Fields Constructors Methods
org.apache.http.message

public Class BasicHeaderValueFormatter

extends Object
implements HeaderValueFormatter
Class Inheritance
All Implemented Interfaces
org.apache.http.message.HeaderValueFormatter
Annotations
@Contract
threading:IMMUTABLE
Imports
org.apache.http.HeaderElement, .NameValuePair, org.apache.http.annotation.ThreadingBehavior, .Contract, org.apache.http.util.Args, .CharArrayBuffer

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

Modifier and TypeField and Description
public static final BasicHeaderValueFormatter
DEFAULT

A default instance of this class, for use as default or fallback.

public static final BasicHeaderValueFormatter
public static final String
SEPARATORS

Special characters that can be used as separators in HTTP parameters.

public static final String
UNSAFE_CHARS

Unsafe special characters that must be escaped using the backslash character

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
doFormatValue(final CharArrayBuffer
the buffer to append to, never null
buffer
,
final String
the value to append, never null
value
,
final boolean
true to always format with quotes, false to use quotes only when necessary
quote
)

Actually formats the value of a name-value pair.

protected int

Returns:

a length estimate, in number of characters
estimateElementsLen
(final HeaderElement[]
the header elements to format, or null
elems
)

Estimates the length of formatted header elements.

protected int

Returns:

a length estimate, in number of characters
estimateHeaderElementLen
(final HeaderElement
the header element to format, or null
elem
)

Estimates the length of a formatted header element.

protected int

Returns:

a length estimate, in number of characters
estimateNameValuePairLen
(final NameValuePair
the name-value pair to format, or null
nvp
)

Estimates the length of a formatted name-value pair.

protected int

Returns:

a length estimate, in number of characters
estimateParametersLen
(final NameValuePair[]
the parameters to format, or null
nvps
)

Estimates the length of formatted parameters.

public static String

Returns:

the formatted header elements
formatElements
(final HeaderElement[]
the header elements to format
elems
,
final boolean
true to always format with quoted values, false to use quotes only when necessary
quote
,
final HeaderValueFormatter
the formatter to use, or null for the default
formatter
)

Formats an array of header elements.

public CharArrayBuffer
formatElements(final CharArrayBuffer
the buffer to append to, or null to create a new buffer
charBuffer
,
final HeaderElement[]
the header elements to format
elems
,
final boolean
true to always format with quoted values, false to use quotes only when necessary
quote
)

Implements org.apache.http.message.HeaderValueFormatter.formatElements.

Formats an array of header elements.
public static String

Returns:

the formatted header element
formatHeaderElement
(final HeaderElement
the header element to format
elem
,
final boolean
true to always format with quoted values, false to use quotes only when necessary
quote
,
final HeaderValueFormatter
the formatter to use, or null for the default
formatter
)

Formats a header element.

public CharArrayBuffer
formatHeaderElement(final CharArrayBuffer
the buffer to append to, or null to create a new buffer
charBuffer
,
final HeaderElement
the header element to format
elem
,
final boolean
true to always format with quoted values, false to use quotes only when necessary
quote
)

Implements org.apache.http.message.HeaderValueFormatter.formatHeaderElement.

Formats one header element.
public static String

Returns:

the formatted name-value pair
formatNameValuePair
(final NameValuePair
the name-value pair to format
nvp
,
final boolean
true to always format with a quoted value, false to use quotes only when necessary
quote
,
final HeaderValueFormatter
the formatter to use, or null for the default
formatter
)

Formats a name-value pair.

public CharArrayBuffer
formatNameValuePair(final CharArrayBuffer
the buffer to append to, or null to create a new buffer
charBuffer
,
final NameValuePair
the name-value pair to format
nvp
,
final boolean
true to always format with a quoted value, false to use quotes only when necessary
quote
)

Implements org.apache.http.message.HeaderValueFormatter.formatNameValuePair.

Formats one name-value pair, where the value is optional.
public static String

Returns:

the formatted parameters
formatParameters
(final NameValuePair[]
the parameters to format
nvps
,
final boolean
true to always format with quoted values, false to use quotes only when necessary
quote
,
final HeaderValueFormatter
the formatter to use, or null for the default
formatter
)

Formats a set of parameters.

public CharArrayBuffer
formatParameters(final CharArrayBuffer
the buffer to append to, or null to create a new buffer
charBuffer
,
final NameValuePair[]
the parameters (name-value pairs) to format
nvps
,
final boolean
true to always format with quoted values, false to use quotes only when necessary
quote
)

Implements org.apache.http.message.HeaderValueFormatter.formatParameters.

Formats the parameters of a header element.
protected boolean

Returns:

true if the character is a separator, false otherwise
isSeparator
(final char
the character to check
ch
)

Checks whether a character is a separator.

protected boolean

Returns:

true if the character is unsafe, false otherwise
isUnsafe
(final char
the character to check
ch
)

Checks whether a character is unsafe.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULTback to summary
public static final BasicHeaderValueFormatter DEFAULT

Deprecated

(4.3) use INSTANCE

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.

Annotations
@Deprecated
INSTANCEback to summary
public static final BasicHeaderValueFormatter INSTANCE
SEPARATORSback to summary
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 .

UNSAFE_CHARSback to summary
public static final String UNSAFE_CHARS

Unsafe special characters that must be escaped using the backslash character

Constructor Detail

BasicHeaderValueFormatterback to summary
public BasicHeaderValueFormatter()

Method Detail

doFormatValueback to summary
protected void doFormatValue(final CharArrayBuffer buffer, final String value, final boolean quote)

Actually formats the value of a name-value pair. This does not include a leading = character. Called from formatNameValuePair.

Parameters
buffer:CharArrayBuffer

the buffer to append to, never null

value:String

the value to append, never null

quote:boolean

true to always format with quotes, false to use quotes only when necessary

estimateElementsLenback to summary
protected int estimateElementsLen(final HeaderElement[] elems)

Estimates the length of formatted header elements.

Parameters
elems:HeaderElement[]

the header elements to format, or null

Returns:int

a length estimate, in number of characters

estimateHeaderElementLenback to summary
protected int estimateHeaderElementLen(final HeaderElement elem)

Estimates the length of a formatted header element.

Parameters
elem:HeaderElement

the header element to format, or null

Returns:int

a length estimate, in number of characters

estimateNameValuePairLenback to summary
protected int estimateNameValuePairLen(final NameValuePair nvp)

Estimates the length of a formatted name-value pair.

Parameters
nvp:NameValuePair

the name-value pair to format, or null

Returns:int

a length estimate, in number of characters

estimateParametersLenback to summary
protected int estimateParametersLen(final NameValuePair[] nvps)

Estimates the length of formatted parameters.

Parameters
nvps:NameValuePair[]

the parameters to format, or null

Returns:int

a length estimate, in number of characters

formatElementsback to summary
public static String formatElements(final HeaderElement[] elems, final boolean quote, final HeaderValueFormatter formatter)

Formats an array of header elements.

Parameters
elems:HeaderElement[]

the header elements to format

quote:boolean

true to always format with quoted values, false to use quotes only when necessary

formatter:HeaderValueFormatter

the formatter to use, or null for the default

Returns:String

the formatted header elements

formatElementsback to summary
public CharArrayBuffer formatElements(final CharArrayBuffer charBuffer, final HeaderElement[] elems, final boolean quote)

Implements org.apache.http.message.HeaderValueFormatter.formatElements.

Doc from org.apache.http.message.HeaderValueFormatter.formatElements.

Formats an array of header elements.

Parameters
charBuffer:CharArrayBuffer

the buffer to append to, or null to create a new buffer

elems:HeaderElement[]

the header elements to format

quote:boolean

true to always format with quoted values, false to use quotes only when necessary

Returns:CharArrayBuffer

a buffer with the formatted header elements. If the buffer argument was not null, that buffer will be used and returned.

Annotations
@Override
formatHeaderElementback to summary
public static String formatHeaderElement(final HeaderElement elem, final boolean quote, final HeaderValueFormatter formatter)

Formats a header element.

Parameters
elem:HeaderElement

the header element to format

quote:boolean

true to always format with quoted values, false to use quotes only when necessary

formatter:HeaderValueFormatter

the formatter to use, or null for the default

Returns:String

the formatted header element

formatHeaderElementback to summary
public CharArrayBuffer formatHeaderElement(final CharArrayBuffer charBuffer, final HeaderElement elem, final boolean quote)

Implements org.apache.http.message.HeaderValueFormatter.formatHeaderElement.

Doc from org.apache.http.message.HeaderValueFormatter.formatHeaderElement.

Formats one header element.

Parameters
charBuffer:CharArrayBuffer

the buffer to append to, or null to create a new buffer

elem:HeaderElement

the header element to format

quote:boolean

true to always format with quoted values, false to use quotes only when necessary

Returns:CharArrayBuffer

a buffer with the formatted header element. If the buffer argument was not null, that buffer will be used and returned.

Annotations
@Override
formatNameValuePairback to summary
public static String formatNameValuePair(final NameValuePair nvp, final boolean quote, final HeaderValueFormatter formatter)

Formats a name-value pair.

Parameters
nvp:NameValuePair

the name-value pair to format

quote:boolean

true to always format with a quoted value, false to use quotes only when necessary

formatter:HeaderValueFormatter

the formatter to use, or null for the default

Returns:String

the formatted name-value pair

formatNameValuePairback to summary
public CharArrayBuffer formatNameValuePair(final CharArrayBuffer charBuffer, final NameValuePair nvp, final boolean quote)

Implements org.apache.http.message.HeaderValueFormatter.formatNameValuePair.

Doc from org.apache.http.message.HeaderValueFormatter.formatNameValuePair.

Formats one name-value pair, where the value is optional.

Parameters
charBuffer:CharArrayBuffer

the buffer to append to, or null to create a new buffer

nvp:NameValuePair

the name-value pair to format

quote:boolean

true to always format with a quoted value, false to use quotes only when necessary

Returns:CharArrayBuffer

a buffer with the formatted name-value pair. If the buffer argument was not null, that buffer will be used and returned.

Annotations
@Override
formatParametersback to summary
public static String formatParameters(final NameValuePair[] nvps, final boolean quote, final HeaderValueFormatter formatter)

Formats a set of parameters.

Parameters
nvps:NameValuePair[]

the parameters to format

quote:boolean

true to always format with quoted values, false to use quotes only when necessary

formatter:HeaderValueFormatter

the formatter to use, or null for the default

Returns:String

the formatted parameters

formatParametersback to summary
public CharArrayBuffer formatParameters(final CharArrayBuffer charBuffer, final NameValuePair[] nvps, final boolean quote)

Implements org.apache.http.message.HeaderValueFormatter.formatParameters.

Doc from org.apache.http.message.HeaderValueFormatter.formatParameters.

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.

Parameters
charBuffer:CharArrayBuffer

the buffer to append to, or null to create a new buffer

nvps:NameValuePair[]

the parameters (name-value pairs) to format

quote:boolean

true to always format with quoted values, false to use quotes only when necessary

Returns:CharArrayBuffer

a buffer with the formatted parameters. If the buffer argument was not null, that buffer will be used and returned.

Annotations
@Override
isSeparatorback to summary
protected boolean isSeparator(final char ch)

Checks whether a character is a separator.

Parameters
ch:char

the character to check

Returns:boolean

true if the character is a separator, false otherwise

isUnsafeback to summary
protected boolean isUnsafe(final char ch)

Checks whether a character is unsafe.

Parameters
ch:char

the character to check

Returns:boolean

true if the character is unsafe, false otherwise