• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.0.1.79
BasicHeaderValueFormatter Class Reference

Basic implementation for formatting header value elements. More...

Inheritance diagram for BasicHeaderValueFormatter:
HeaderValueFormatter

Description

Instances of this class are stateless and thread-safe. Derived classes are expected to maintain these properties.

Author
Oleg Kalnichevski
and others
Version
Revision
574185
Since
4.0

Notice

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...
 

Member Function Documentation

◆ formatElements() [1/2]

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

◆ formatElements() [2/2]

CharArrayBuffer formatElements ( CharArrayBuffer  buffer,
final HeaderElement[]  elems,
final boolean  quote 
)
Parameters
bufferthe buffer to append to, or null to create a new buffer
elemsthe header elements to format
quotetrue 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.

Implements HeaderValueFormatter.

◆ estimateElementsLen()

int estimateElementsLen ( final HeaderElement[]  elems)
protected
Parameters
elemsthe header elements to format, or null
Returns
a length estimate, in number of characters

◆ formatHeaderElement() [1/2]

static final String formatHeaderElement ( final HeaderElement  elem,
boolean  quote,
HeaderValueFormatter  formatter 
)
static
Parameters
elemthe header element to format
quotetrue to always format with quoted values, false to use quotes only when necessary
formatterthe formatter to use, or null for the default
Returns
the formatted header element

◆ formatHeaderElement() [2/2]

CharArrayBuffer formatHeaderElement ( CharArrayBuffer  buffer,
final HeaderElement  elem,
final boolean  quote 
)
Parameters
bufferthe buffer to append to, or null to create a new buffer
elemthe header element to format
quotetrue 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.

Implements HeaderValueFormatter.

◆ estimateHeaderElementLen()

int estimateHeaderElementLen ( final HeaderElement  elem)
protected
Parameters
elemthe header element to format, or null
Returns
a length estimate, in number of characters

◆ formatParameters() [1/2]

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

◆ formatParameters() [2/2]

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.

Parameters
bufferthe buffer to append to, or null to create a new buffer
nvpsthe parameters (name-value pairs) to format
quotetrue 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.

Implements HeaderValueFormatter.

◆ estimateParametersLen()

int estimateParametersLen ( final NameValuePair[]  nvps)
protected
Parameters
nvpsthe parameters to format, or null
Returns
a length estimate, in number of characters

◆ formatNameValuePair() [1/2]

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

◆ formatNameValuePair() [2/2]

CharArrayBuffer formatNameValuePair ( CharArrayBuffer  buffer,
final NameValuePair  nvp,
final boolean  quote 
)
Parameters
bufferthe buffer to append to, or null to create a new buffer
nvpthe name-value pair to format
quotetrue 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.

Implements HeaderValueFormatter.

◆ estimateNameValuePairLen()

int estimateNameValuePairLen ( final NameValuePair  nvp)
protected
Parameters
nvpthe name-value pair to format, or null
Returns
a length estimate, in number of characters

◆ doFormatValue()

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

This does not include a leading = character. Called from formatNameValuePair .

Parameters
bufferthe buffer to append to, never null
valuethe value to append, never null
quotetrue to always format with quotes, false to use quotes only when necessary

◆ isSeparator()

boolean isSeparator ( char  ch)
protected
Parameters
chthe character to check
Returns
true if the character is a separator, false otherwise

◆ isUnsafe()

boolean isUnsafe ( char  ch)
protected
Parameters
chthe character to check
Returns
true if the character is unsafe, false otherwise

Member Data Documentation

◆ DEFAULT

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.

◆ SEPARATORS

final String SEPARATORS = " ;,:@()<>\\\"/[]?={}\t"
static

These special characters MUST be in a quoted string to be used within a parameter value .