Android APIs
public class

BasicHeaderValueFormatter

extends Object
implements HeaderValueFormatter
java.lang.Object
   ↳ org.apache.http.message.BasicHeaderValueFormatter

This class was deprecated in API level 22.
Please use openConnection() instead. Please visit this webpage for further details.

Class Overview

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
String SEPARATORS Special characters that can be used as separators in HTTP parameters.
String UNSAFE_CHARS Unsafe special characters that must be escaped using the backslash character
Fields
public static final BasicHeaderValueFormatter DEFAULT A default instance of this class, for use as default or fallback.
Public Constructors
BasicHeaderValueFormatter()
Public Methods
final static String formatElements(HeaderElement[] elems, boolean quote, HeaderValueFormatter formatter)
Formats an array of header elements.
CharArrayBuffer formatElements(CharArrayBuffer buffer, HeaderElement[] elems, boolean quote)
Formats an array of header elements.
final static String formatHeaderElement(HeaderElement elem, boolean quote, HeaderValueFormatter formatter)
Formats a header element.
CharArrayBuffer formatHeaderElement(CharArrayBuffer buffer, HeaderElement elem, boolean quote)
Formats one header element.
CharArrayBuffer formatNameValuePair(CharArrayBuffer buffer, NameValuePair nvp, boolean quote)
Formats one name-value pair, where the value is optional.
final static String formatNameValuePair(NameValuePair nvp, boolean quote, HeaderValueFormatter formatter)
Formats a name-value pair.
final static String formatParameters(NameValuePair[] nvps, boolean quote, HeaderValueFormatter formatter)
Formats a set of parameters.
CharArrayBuffer formatParameters(CharArrayBuffer buffer, NameValuePair[] nvps, boolean quote)
Formats the parameters of a header element.
Protected Methods
void doFormatValue(CharArrayBuffer buffer, String value, boolean quote)
Actually formats the value of a name-value pair.
int estimateElementsLen(HeaderElement[] elems)
Estimates the length of formatted header elements.
int estimateHeaderElementLen(HeaderElement elem)
Estimates the length of a formatted header element.
int estimateNameValuePairLen(NameValuePair nvp)
Estimates the length of a formatted name-value pair.
int estimateParametersLen(NameValuePair[] nvps)
Estimates the length of formatted parameters.
boolean isSeparator(char ch)
Checks whether a character is a separator.
boolean isUnsafe(char ch)
Checks whether a character is unsafe.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.http.message.HeaderValueFormatter

Constants

public static final String SEPARATORS

Added in API level 1

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

Added in API level 1

Unsafe special characters that must be escaped using the backslash character

Constant Value: ""\"

Fields

public static final BasicHeaderValueFormatter DEFAULT

Added in API level 1

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 Constructors

public BasicHeaderValueFormatter ()

Added in API level 1

Public Methods

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

Added in API level 1

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

public CharArrayBuffer formatElements (CharArrayBuffer buffer, HeaderElement[] elems, boolean quote)

Added in API level 1

Formats an array of header elements.

Parameters
buffer the buffer to append to, or null to create a new buffer
elems the header elements to format
quote 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 not null, that buffer will be used and returned.

public static final String formatHeaderElement (HeaderElement elem, boolean quote, HeaderValueFormatter formatter)

Added in API level 1

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

public CharArrayBuffer formatHeaderElement (CharArrayBuffer buffer, HeaderElement elem, boolean quote)

Added in API level 1

Formats one header element.

Parameters
buffer the buffer to append to, or null to create a new buffer
elem the header element to format
quote 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 not null, that buffer will be used and returned.

public CharArrayBuffer formatNameValuePair (CharArrayBuffer buffer, NameValuePair nvp, boolean quote)

Added in API level 1

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

Parameters
buffer the buffer to append to, or null to create a new buffer
nvp the name-value pair to format
quote 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 not null, that buffer will be used and returned.

public static final String formatNameValuePair (NameValuePair nvp, boolean quote, HeaderValueFormatter formatter)

Added in API level 1

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

public static final String formatParameters (NameValuePair[] nvps, boolean quote, HeaderValueFormatter formatter)

Added in API level 1

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

public CharArrayBuffer formatParameters (CharArrayBuffer buffer, NameValuePair[] nvps, boolean quote)

Added in API level 1

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
buffer the buffer to append to, or null to create a new buffer
nvps the parameters (name-value pairs) to format
quote 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 not null, that buffer will be used and returned.

Protected Methods

protected void doFormatValue (CharArrayBuffer buffer, String value, boolean quote)

Added in API level 1

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)

Added in API level 1

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)

Added in API level 1

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)

Added in API level 1

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)

Added in API level 1

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)

Added in API level 1

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)

Added in API level 1

Checks whether a character is unsafe.

Parameters
ch the character to check
Returns
  • true if the character is unsafe, false otherwise