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

Interface for formatting elements of the HEAD section of an HTTP message. More...

Inheritance diagram for BasicLineFormatter:
LineFormatter

Description

This is the complement to com.good.gd.apache.http.message.LineParser. There are individual methods for formatting a request line, a status line, or a header line. The formatting does not include the trailing line break sequence CR-LF. The formatted lines are returned in memory, the formatter does not depend on any specific IO mechanism. Instances of this interface are expected to be stateless and thread-safe.

Author
Remy Maucherat
Mike Bowler
Jeff Dever
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 appendProtocolVersion (final CharArrayBuffer buffer, final ProtocolVersion version)
 Formats a protocol version. More...
 
CharArrayBuffer formatRequestLine (CharArrayBuffer buffer, RequestLine reqline)
 Formats a request line. More...
 
CharArrayBuffer formatStatusLine (final CharArrayBuffer buffer, final StatusLine statline)
 Formats a status line. More...
 
CharArrayBuffer formatHeader (CharArrayBuffer buffer, Header header)
 Formats a header. More...
 

Static Public Member Functions

static final String formatProtocolVersion (final ProtocolVersion version, LineFormatter formatter)
 Formats a protocol version. More...
 
static final String formatRequestLine (final RequestLine reqline, LineFormatter formatter)
 Formats a request line. More...
 
static final String formatStatusLine (final StatusLine statline, LineFormatter formatter)
 Formats a status line. More...
 
static final String formatHeader (final Header header, LineFormatter formatter)
 Formats a header. More...
 

Static Public Attributes

static final BasicLineFormatter DEFAULT = new BasicLineFormatter()
 A default instance of this class, for use as default or fallback. More...
 

Protected Member Functions

CharArrayBuffer initBuffer (CharArrayBuffer buffer)
 Obtains a buffer for formatting. More...
 
int estimateProtocolVersionLen (final ProtocolVersion version)
 Guesses the length of a formatted protocol version. More...
 
void doFormatRequestLine (final CharArrayBuffer buffer, final RequestLine reqline)
 Actually formats a request line. More...
 
void doFormatStatusLine (final CharArrayBuffer buffer, final StatusLine statline)
 Actually formats a status line. More...
 
void doFormatHeader (final CharArrayBuffer buffer, final Header header)
 Actually formats a header. More...
 

Member Function Documentation

◆ initBuffer()

CharArrayBuffer initBuffer ( CharArrayBuffer  buffer)
protected
Parameters
buffera buffer already available, or null
Returns
the cleared argument buffer if there is one, or a new empty buffer that can be used for formatting

◆ formatProtocolVersion()

static final String formatProtocolVersion ( final ProtocolVersion  version,
LineFormatter  formatter 
)
static
Parameters
versionthe protocol version to format
formatterthe formatter to use, or null for the default
Returns
the formatted protocol version

◆ appendProtocolVersion()

CharArrayBuffer appendProtocolVersion ( final CharArrayBuffer  buffer,
final ProtocolVersion  version 
)

This method does not follow the general contract for buffer arguments. It does not clear the argument buffer, but appends instead. The returned buffer can always be modified by the caller. Because of these differing conventions, it is not named formatProtocolVersion.

Parameters
buffera buffer to which to append, or null
versionthe protocol version to format
Returns
a buffer with the formatted protocol version appended. The caller is allowed to modify the result buffer. If the buffer argument is not null, the returned buffer is the argument buffer.

Implements LineFormatter.

◆ estimateProtocolVersionLen()

int estimateProtocolVersionLen ( final ProtocolVersion  version)
protected

Needed to guess the length of a formatted request or status line.

Parameters
versionthe protocol version to format, or null
Returns
the estimated length of the formatted protocol version, in characters

◆ formatRequestLine() [1/2]

static final String formatRequestLine ( final RequestLine  reqline,
LineFormatter  formatter 
)
static
Parameters
reqlinethe request line to format
formatterthe formatter to use, or null for the default
Returns
the formatted request line

◆ formatRequestLine() [2/2]

CharArrayBuffer formatRequestLine ( CharArrayBuffer  buffer,
RequestLine  reqline 
)
Parameters
buffera buffer available for formatting, or null. The buffer will be cleared before use.
reqlinethe request line to format
Returns
the formatted request line

Implements LineFormatter.

◆ doFormatRequestLine()

void doFormatRequestLine ( final CharArrayBuffer  buffer,
final RequestLine  reqline 
)
protected

Called from formatRequestLine.

Parameters
bufferthe empty buffer into which to format, never null
reqlinethe request line to format, never null

◆ formatStatusLine() [1/2]

static final String formatStatusLine ( final StatusLine  statline,
LineFormatter  formatter 
)
static
Parameters
statlinethe status line to format
formatterthe formatter to use, or null for the default
Returns
the formatted status line

◆ formatStatusLine() [2/2]

CharArrayBuffer formatStatusLine ( final CharArrayBuffer  buffer,
final StatusLine  statline 
)
Parameters
buffera buffer available for formatting, or null. The buffer will be cleared before use.
statlinethe status line to format
Returns
the formatted status line
Exceptions
ParseExceptionin case of a parse error

Implements LineFormatter.

◆ doFormatStatusLine()

void doFormatStatusLine ( final CharArrayBuffer  buffer,
final StatusLine  statline 
)
protected

Called from formatStatusLine.

Parameters
bufferthe empty buffer into which to format, never null
statlinethe status line to format, never null

◆ formatHeader() [1/2]

static final String formatHeader ( final Header  header,
LineFormatter  formatter 
)
static
Parameters
headerthe header to format
formatterthe formatter to use, or null for the default
Returns
the formatted header

◆ formatHeader() [2/2]

CharArrayBuffer formatHeader ( CharArrayBuffer  buffer,
Header  header 
)

Due to header continuation, the result may be multiple lines. In order to generate well-formed HTTP, the lines in the result must be separated by the HTTP line break sequence CR-LF. There is no trailing CR-LF in the result.
See the class comment for details about the buffer argument.

Parameters
buffera buffer available for formatting, or null. The buffer will be cleared before use.
headerthe header to format
Returns
a buffer holding the formatted header, never null. The returned buffer may be different from the argument buffer.
Exceptions
ParseExceptionin case of a parse error

Implements LineFormatter.

◆ doFormatHeader()

void doFormatHeader ( final CharArrayBuffer  buffer,
final Header  header 
)
protected

Called from formatHeader.

Parameters
bufferthe empty buffer into which to format, never null
headerthe header to format, never null

Member Data Documentation

◆ DEFAULT

final BasicLineFormatter DEFAULT = new BasicLineFormatter()
static

Note that BasicLineFormatter 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.