org.apache.http.message
Class BasicHeaderValueFormatterHC4

java.lang.Object
  extended by org.apache.http.message.BasicHeaderValueFormatterHC4
All Implemented Interfaces:
org.apache.http.message.HeaderValueFormatter

@Immutable
public class BasicHeaderValueFormatterHC4
extends java.lang.Object
implements org.apache.http.message.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
static BasicHeaderValueFormatterHC4 DEFAULT
          Deprecated. (4.3) use INSTANCE
static BasicHeaderValueFormatterHC4 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
BasicHeaderValueFormatterHC4()
           
 
Method Summary
protected  void doFormatValue(org.apache.http.util.CharArrayBuffer buffer, java.lang.String value, boolean quote)
          Actually formats the value of a name-value pair.
protected  int estimateElementsLen(org.apache.http.HeaderElement[] elems)
          Estimates the length of formatted header elements.
protected  int estimateHeaderElementLen(org.apache.http.HeaderElement elem)
          Estimates the length of a formatted header element.
protected  int estimateNameValuePairLen(org.apache.http.NameValuePair nvp)
          Estimates the length of a formatted name-value pair.
protected  int estimateParametersLen(org.apache.http.NameValuePair[] nvps)
          Estimates the length of formatted parameters.
 org.apache.http.util.CharArrayBuffer formatElements(org.apache.http.util.CharArrayBuffer charBuffer, org.apache.http.HeaderElement[] elems, boolean quote)
           
static java.lang.String formatElements(org.apache.http.HeaderElement[] elems, boolean quote, org.apache.http.message.HeaderValueFormatter formatter)
          Formats an array of header elements.
 org.apache.http.util.CharArrayBuffer formatHeaderElement(org.apache.http.util.CharArrayBuffer charBuffer, org.apache.http.HeaderElement elem, boolean quote)
           
static java.lang.String formatHeaderElement(org.apache.http.HeaderElement elem, boolean quote, org.apache.http.message.HeaderValueFormatter formatter)
          Formats a header element.
 org.apache.http.util.CharArrayBuffer formatNameValuePair(org.apache.http.util.CharArrayBuffer charBuffer, org.apache.http.NameValuePair nvp, boolean quote)
           
static java.lang.String formatNameValuePair(org.apache.http.NameValuePair nvp, boolean quote, org.apache.http.message.HeaderValueFormatter formatter)
          Formats a name-value pair.
 org.apache.http.util.CharArrayBuffer formatParameters(org.apache.http.util.CharArrayBuffer charBuffer, org.apache.http.NameValuePair[] nvps, boolean quote)
           
static java.lang.String formatParameters(org.apache.http.NameValuePair[] nvps, boolean quote, org.apache.http.message.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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

@Deprecated
public static final BasicHeaderValueFormatterHC4 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.


INSTANCE

public static final BasicHeaderValueFormatterHC4 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
Constructor Detail

BasicHeaderValueFormatterHC4

public BasicHeaderValueFormatterHC4()
Method Detail

formatElements

public static java.lang.String formatElements(org.apache.http.HeaderElement[] elems,
                                              boolean quote,
                                              org.apache.http.message.HeaderValueFormatter formatter)
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

formatElements

public org.apache.http.util.CharArrayBuffer formatElements(org.apache.http.util.CharArrayBuffer charBuffer,
                                                           org.apache.http.HeaderElement[] elems,
                                                           boolean quote)
Specified by:
formatElements in interface org.apache.http.message.HeaderValueFormatter

estimateElementsLen

protected int estimateElementsLen(org.apache.http.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

formatHeaderElement

public static java.lang.String formatHeaderElement(org.apache.http.HeaderElement elem,
                                                   boolean quote,
                                                   org.apache.http.message.HeaderValueFormatter formatter)
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

formatHeaderElement

public org.apache.http.util.CharArrayBuffer formatHeaderElement(org.apache.http.util.CharArrayBuffer charBuffer,
                                                                org.apache.http.HeaderElement elem,
                                                                boolean quote)
Specified by:
formatHeaderElement in interface org.apache.http.message.HeaderValueFormatter

estimateHeaderElementLen

protected int estimateHeaderElementLen(org.apache.http.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

formatParameters

public static java.lang.String formatParameters(org.apache.http.NameValuePair[] nvps,
                                                boolean quote,
                                                org.apache.http.message.HeaderValueFormatter formatter)
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
Returns:
the formatted parameters

formatParameters

public org.apache.http.util.CharArrayBuffer formatParameters(org.apache.http.util.CharArrayBuffer charBuffer,
                                                             org.apache.http.NameValuePair[] nvps,
                                                             boolean quote)
Specified by:
formatParameters in interface org.apache.http.message.HeaderValueFormatter

estimateParametersLen

protected int estimateParametersLen(org.apache.http.NameValuePair[] nvps)
Estimates the length of formatted parameters.

Parameters:
nvps - the parameters to format, or null
Returns:
a length estimate, in number of characters

formatNameValuePair

public static java.lang.String formatNameValuePair(org.apache.http.NameValuePair nvp,
                                                   boolean quote,
                                                   org.apache.http.message.HeaderValueFormatter formatter)
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

formatNameValuePair

public org.apache.http.util.CharArrayBuffer formatNameValuePair(org.apache.http.util.CharArrayBuffer charBuffer,
                                                                org.apache.http.NameValuePair nvp,
                                                                boolean quote)
Specified by:
formatNameValuePair in interface org.apache.http.message.HeaderValueFormatter

estimateNameValuePairLen

protected int estimateNameValuePairLen(org.apache.http.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

doFormatValue

protected void doFormatValue(org.apache.http.util.CharArrayBuffer buffer,
                             java.lang.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

isSeparator

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

isUnsafe

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