@Immutable public class BasicLineFormatter extends java.lang.Object implements LineFormatter
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.Modifier and Type | Field and Description |
---|---|
static BasicLineFormatter |
DEFAULT
Deprecated.
(4.3) use
INSTANCE |
static BasicLineFormatter |
INSTANCE |
Constructor and Description |
---|
BasicLineFormatter() |
Modifier and Type | Method and Description |
---|---|
CharArrayBuffer |
appendProtocolVersion(CharArrayBuffer buffer,
ProtocolVersion version)
Formats a protocol version.
|
protected void |
doFormatHeader(CharArrayBuffer buffer,
Header header)
Actually formats a header.
|
protected void |
doFormatRequestLine(CharArrayBuffer buffer,
RequestLine reqline)
Actually formats a request line.
|
protected void |
doFormatStatusLine(CharArrayBuffer buffer,
StatusLine statline)
Actually formats a status line.
|
protected int |
estimateProtocolVersionLen(ProtocolVersion version)
Guesses the length of a formatted protocol version.
|
CharArrayBuffer |
formatHeader(CharArrayBuffer buffer,
Header header)
Formats a header.
|
static java.lang.String |
formatHeader(Header header,
LineFormatter formatter)
Formats a header.
|
static java.lang.String |
formatProtocolVersion(ProtocolVersion version,
LineFormatter formatter)
Formats a protocol version.
|
CharArrayBuffer |
formatRequestLine(CharArrayBuffer buffer,
RequestLine reqline)
Formats a request line.
|
static java.lang.String |
formatRequestLine(RequestLine reqline,
LineFormatter formatter)
Formats a request line.
|
CharArrayBuffer |
formatStatusLine(CharArrayBuffer buffer,
StatusLine statline)
Formats a status line.
|
static java.lang.String |
formatStatusLine(StatusLine statline,
LineFormatter formatter)
Formats a status line.
|
protected CharArrayBuffer |
initBuffer(CharArrayBuffer charBuffer)
Obtains a buffer for formatting.
|
@Deprecated public static final BasicLineFormatter DEFAULT
INSTANCE
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.public static final BasicLineFormatter INSTANCE
protected CharArrayBuffer initBuffer(CharArrayBuffer charBuffer)
charBuffer
- a buffer already available, or null
public static java.lang.String formatProtocolVersion(ProtocolVersion version, LineFormatter formatter)
version
- the protocol version to formatformatter
- the formatter to use, or
null
for the
default
public CharArrayBuffer appendProtocolVersion(CharArrayBuffer buffer, ProtocolVersion version)
LineFormatter
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
.appendProtocolVersion
in interface LineFormatter
buffer
- a buffer to which to append, or null
version
- the protocol version to formatbuffer
argument is not null
,
the returned buffer is the argument buffer.protected int estimateProtocolVersionLen(ProtocolVersion version)
version
- the protocol version to format, or null
public static java.lang.String formatRequestLine(RequestLine reqline, LineFormatter formatter)
reqline
- the request line to formatformatter
- the formatter to use, or
null
for the
default
public CharArrayBuffer formatRequestLine(CharArrayBuffer buffer, RequestLine reqline)
LineFormatter
formatRequestLine
in interface LineFormatter
buffer
- a buffer available for formatting, or
null
.
The buffer will be cleared before use.reqline
- the request line to formatprotected void doFormatRequestLine(CharArrayBuffer buffer, RequestLine reqline)
formatRequestLine(org.apache.http.RequestLine, org.apache.http.message.LineFormatter)
.buffer
- the empty buffer into which to format,
never null
reqline
- the request line to format, never null
public static java.lang.String formatStatusLine(StatusLine statline, LineFormatter formatter)
statline
- the status line to formatformatter
- the formatter to use, or
null
for the
default
public CharArrayBuffer formatStatusLine(CharArrayBuffer buffer, StatusLine statline)
LineFormatter
formatStatusLine
in interface LineFormatter
buffer
- a buffer available for formatting, or
null
.
The buffer will be cleared before use.statline
- the status line to formatprotected void doFormatStatusLine(CharArrayBuffer buffer, StatusLine statline)
formatStatusLine(org.apache.http.StatusLine, org.apache.http.message.LineFormatter)
.buffer
- the empty buffer into which to format,
never null
statline
- the status line to format, never null
public static java.lang.String formatHeader(Header header, LineFormatter formatter)
header
- the header to formatformatter
- the formatter to use, or
null
for the
default
public CharArrayBuffer formatHeader(CharArrayBuffer buffer, Header header)
LineFormatter
See the class comment for details about the buffer argument.
formatHeader
in interface LineFormatter
buffer
- a buffer available for formatting, or
null
.
The buffer will be cleared before use.header
- the header to formatnull
.
The returned buffer may be different from the argument buffer.protected void doFormatHeader(CharArrayBuffer buffer, Header header)
formatHeader(org.apache.http.Header, org.apache.http.message.LineFormatter)
.buffer
- the empty buffer into which to format,
never null
header
- the header to format, never null