Basic implementation for formatting header value elements. More...
Instances of this class are stateless and thread-safe. Derived classes are expected to maintain these properties.
The following notice applies to the original API on which this API is based, and to its documentation. The documentation of this API has been revised from the original.
/* * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */
Public Member Functions | |
CharArrayBuffer | formatElements (CharArrayBuffer buffer, final HeaderElement[] elems, final boolean quote) |
Formats an array of header elements. More... | |
CharArrayBuffer | formatHeaderElement (CharArrayBuffer buffer, final HeaderElement elem, final boolean quote) |
Formats one header element. More... | |
CharArrayBuffer | formatParameters (CharArrayBuffer buffer, NameValuePair[] nvps, boolean quote) |
Formats the parameters of a header element. More... | |
CharArrayBuffer | formatNameValuePair (CharArrayBuffer buffer, final NameValuePair nvp, final boolean quote) |
Formats one name-value pair, where the value is optional. More... | |
Static Public Member Functions | |
static final String | formatElements (final HeaderElement[] elems, final boolean quote, HeaderValueFormatter formatter) |
Formats an array of header elements. More... | |
static final String | formatHeaderElement (final HeaderElement elem, boolean quote, HeaderValueFormatter formatter) |
Formats a header element. More... | |
static final String | formatParameters (final NameValuePair[] nvps, final boolean quote, HeaderValueFormatter formatter) |
Formats a set of parameters. More... | |
static final String | formatNameValuePair (final NameValuePair nvp, final boolean quote, HeaderValueFormatter formatter) |
Formats a name-value pair. More... | |
Static Public Attributes | |
static final BasicHeaderValueFormatter | DEFAULT = new BasicHeaderValueFormatter() |
A default instance of this class, for use as default or fallback. More... | |
static final String | SEPARATORS = " ;,:@()<>\\\"/[]?={}\t" |
Special characters that can be used as separators in HTTP parameters. More... | |
static final String | UNSAFE_CHARS = "\"\\" |
Unsafe special characters that must be escaped using the backslash character. | |
Protected Member Functions | |
int | estimateElementsLen (final HeaderElement[] elems) |
Estimates the length of formatted header elements. More... | |
int | estimateHeaderElementLen (final HeaderElement elem) |
Estimates the length of a formatted header element. More... | |
int | estimateParametersLen (final NameValuePair[] nvps) |
Estimates the length of formatted parameters. More... | |
int | estimateNameValuePairLen (final NameValuePair nvp) |
Estimates the length of a formatted name-value pair. More... | |
void | doFormatValue (final CharArrayBuffer buffer, final String value, boolean quote) |
Actually formats the value of a name-value pair. More... | |
boolean | isSeparator (char ch) |
Checks whether a character is a separator . More... | |
boolean | isUnsafe (char ch) |
Checks whether a character is unsafe . More... | |
|
static |
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 |
CharArrayBuffer formatElements | ( | CharArrayBuffer | buffer, |
final HeaderElement[] | elems, | ||
final boolean | quote | ||
) |
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 |
buffer
argument was not null
, that buffer will be used and returned. Implements HeaderValueFormatter.
|
protected |
elems | the header elements to format, or null |
|
static |
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 |
CharArrayBuffer formatHeaderElement | ( | CharArrayBuffer | buffer, |
final HeaderElement | elem, | ||
final boolean | quote | ||
) |
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 |
buffer
argument was not null
, that buffer will be used and returned. Implements HeaderValueFormatter.
|
protected |
elem | the header element to format, or null |
|
static |
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 |
CharArrayBuffer formatParameters | ( | CharArrayBuffer | buffer, |
NameValuePair[] | nvps, | ||
boolean | quote | ||
) |
That's a list of name-value pairs, to be separated by semicolons. This method will not generate a leading semicolon.
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 |
buffer
argument was not null
, that buffer will be used and returned. Implements HeaderValueFormatter.
|
protected |
nvps | the parameters to format, or null |
|
static |
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 |
CharArrayBuffer formatNameValuePair | ( | CharArrayBuffer | buffer, |
final NameValuePair | nvp, | ||
final boolean | quote | ||
) |
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 |
buffer
argument was not null
, that buffer will be used and returned. Implements HeaderValueFormatter.
|
protected |
nvp | the name-value pair to format, or null |
|
protected |
This does not include a leading = character. Called from 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 necessary |
|
protected |
ch | the character to check |
true
if the character is a separator, false
otherwise
|
protected |
ch | the character to check |
true
if the character is unsafe, false
otherwise
|
static |
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.
|
static |
These special characters MUST be in a quoted string to be used within a parameter value .