Top Description Fields Constructors Methods
org.apache.http.message

public Class BasicLineFormatter

extends Object
implements LineFormatter
Class Inheritance
All Implemented Interfaces
org.apache.http.message.LineFormatter
Annotations
@Contract
threading:IMMUTABLE
Imports
org.apache.http.FormattedHeader, .Header, .ProtocolVersion, .RequestLine, .StatusLine, org.apache.http.annotation.Contract, .ThreadingBehavior, org.apache.http.util.Args, .CharArrayBuffer

Interface for formatting elements of the HEAD section of an HTTP message. This is the complement to 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.
Since
4.0

Field Summary

Modifier and TypeField and Description
public static final BasicLineFormatter
DEFAULT

A default instance of this class, for use as default or fallback.

public static final BasicLineFormatter

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public CharArrayBuffer
appendProtocolVersion(final CharArrayBuffer
a buffer to which to append, or null
buffer
,
final ProtocolVersion
the protocol version to format
version
)

Implements org.apache.http.message.LineFormatter.appendProtocolVersion.

Formats a protocol version.
protected void
doFormatHeader(final CharArrayBuffer
the empty buffer into which to format, never null
buffer
,
final Header
the header to format, never null
header
)

Actually formats a header.

protected void
doFormatRequestLine(final CharArrayBuffer
the empty buffer into which to format, never null
buffer
,
final RequestLine
the request line to format, never null
reqline
)

Actually formats a request line.

protected void
doFormatStatusLine(final CharArrayBuffer
the empty buffer into which to format, never null
buffer
,
final StatusLine
the status line to format, never null
statline
)

Actually formats a status line.

protected int

Returns:

the estimated length of the formatted protocol version, in characters
estimateProtocolVersionLen
(final ProtocolVersion
the protocol version to format, or null
version
)

Guesses the length of a formatted protocol version.

public static String

Returns:

the formatted header
formatHeader
(final Header
the header to format
header
,
final LineFormatter
the formatter to use, or null for the default
formatter
)

Formats a header.

public CharArrayBuffer
formatHeader(final CharArrayBuffer
a buffer available for formatting, or null. The buffer will be cleared before use.
buffer
,
final Header
the header to format
header
)

Implements org.apache.http.message.LineFormatter.formatHeader.

Formats a header.
public static String

Returns:

the formatted protocol version
formatProtocolVersion
(final ProtocolVersion
the protocol version to format
version
,
final LineFormatter
the formatter to use, or null for the default
formatter
)

Formats a protocol version.

public static String

Returns:

the formatted request line
formatRequestLine
(final RequestLine
the request line to format
reqline
,
final LineFormatter
the formatter to use, or null for the default
formatter
)

Formats a request line.

public CharArrayBuffer
formatRequestLine(final CharArrayBuffer
a buffer available for formatting, or null. The buffer will be cleared before use.
buffer
,
final RequestLine
the request line to format
reqline
)

Implements org.apache.http.message.LineFormatter.formatRequestLine.

Formats a request line.
public static String

Returns:

the formatted status line
formatStatusLine
(final StatusLine
the status line to format
statline
,
final LineFormatter
the formatter to use, or null for the default
formatter
)

Formats a status line.

public CharArrayBuffer
formatStatusLine(final CharArrayBuffer
a buffer available for formatting, or null. The buffer will be cleared before use.
buffer
,
final StatusLine
the status line to format
statline
)

Implements org.apache.http.message.LineFormatter.formatStatusLine.

Formats a status line.
protected CharArrayBuffer

Returns:

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

Obtains a buffer for formatting.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULTback to summary
public static final BasicLineFormatter DEFAULT

Deprecated

(4.3) use INSTANCE

A default instance of this class, for use as default or fallback. 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.

Annotations
@Deprecated
INSTANCEback to summary
public static final BasicLineFormatter INSTANCE

Constructor Detail

BasicLineFormatterback to summary
public BasicLineFormatter()

Method Detail

appendProtocolVersionback to summary
public CharArrayBuffer appendProtocolVersion(final CharArrayBuffer buffer, final ProtocolVersion version)

Implements org.apache.http.message.LineFormatter.appendProtocolVersion.

Doc from org.apache.http.message.LineFormatter.appendProtocolVersion.

Formats a protocol 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
buffer:CharArrayBuffer

a buffer to which to append, or null

version:ProtocolVersion

the protocol version to format

Returns:CharArrayBuffer

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.

Annotations
@Override
doFormatHeaderback to summary
protected void doFormatHeader(final CharArrayBuffer buffer, final Header header)

Actually formats a header. Called from formatHeader.

Parameters
buffer:CharArrayBuffer

the empty buffer into which to format, never null

header:Header

the header to format, never null

doFormatRequestLineback to summary
protected void doFormatRequestLine(final CharArrayBuffer buffer, final RequestLine reqline)

Actually formats a request line. Called from formatRequestLine.

Parameters
buffer:CharArrayBuffer

the empty buffer into which to format, never null

reqline:RequestLine

the request line to format, never null

doFormatStatusLineback to summary
protected void doFormatStatusLine(final CharArrayBuffer buffer, final StatusLine statline)

Actually formats a status line. Called from formatStatusLine.

Parameters
buffer:CharArrayBuffer

the empty buffer into which to format, never null

statline:StatusLine

the status line to format, never null

estimateProtocolVersionLenback to summary
protected int estimateProtocolVersionLen(final ProtocolVersion version)

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

Parameters
version:ProtocolVersion

the protocol version to format, or null

Returns:int

the estimated length of the formatted protocol version, in characters

formatHeaderback to summary
public static String formatHeader(final Header header, final LineFormatter formatter)

Formats a header.

Parameters
header:Header

the header to format

formatter:LineFormatter

the formatter to use, or null for the default

Returns:String

the formatted header

formatHeaderback to summary
public CharArrayBuffer formatHeader(final CharArrayBuffer buffer, final Header header)

Implements org.apache.http.message.LineFormatter.formatHeader.

Doc from org.apache.http.message.LineFormatter.formatHeader.

Formats a 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
buffer:CharArrayBuffer

a buffer available for formatting, or null. The buffer will be cleared before use.

header:Header

the header to format

Returns:CharArrayBuffer

a buffer holding the formatted header, never null. The returned buffer may be different from the argument buffer.

Annotations
@Override
formatProtocolVersionback to summary
public static String formatProtocolVersion(final ProtocolVersion version, final LineFormatter formatter)

Formats a protocol version.

Parameters
version:ProtocolVersion

the protocol version to format

formatter:LineFormatter

the formatter to use, or null for the default

Returns:String

the formatted protocol version

formatRequestLineback to summary
public static String formatRequestLine(final RequestLine reqline, final LineFormatter formatter)

Formats a request line.

Parameters
reqline:RequestLine

the request line to format

formatter:LineFormatter

the formatter to use, or null for the default

Returns:String

the formatted request line

formatRequestLineback to summary
public CharArrayBuffer formatRequestLine(final CharArrayBuffer buffer, final RequestLine reqline)

Implements org.apache.http.message.LineFormatter.formatRequestLine.

Doc from org.apache.http.message.LineFormatter.formatRequestLine.

Formats a request line.

Parameters
buffer:CharArrayBuffer

a buffer available for formatting, or null. The buffer will be cleared before use.

reqline:RequestLine

the request line to format

Returns:CharArrayBuffer

the formatted request line

Annotations
@Override
formatStatusLineback to summary
public static String formatStatusLine(final StatusLine statline, final LineFormatter formatter)

Formats a status line.

Parameters
statline:StatusLine

the status line to format

formatter:LineFormatter

the formatter to use, or null for the default

Returns:String

the formatted status line

formatStatusLineback to summary
public CharArrayBuffer formatStatusLine(final CharArrayBuffer buffer, final StatusLine statline)

Implements org.apache.http.message.LineFormatter.formatStatusLine.

Doc from org.apache.http.message.LineFormatter.formatStatusLine.

Formats a status line.

Parameters
buffer:CharArrayBuffer

a buffer available for formatting, or null. The buffer will be cleared before use.

statline:StatusLine

the status line to format

Returns:CharArrayBuffer

the formatted status line

Annotations
@Override
initBufferback to summary
protected CharArrayBuffer initBuffer(final CharArrayBuffer charBuffer)

Obtains a buffer for formatting.

Parameters
charBuffer:CharArrayBuffer

a buffer already available, or null

Returns:CharArrayBuffer

the cleared argument buffer if there is one, or a new empty buffer that can be used for formatting