Package org.apache.http.message
Class BasicLineFormatter
- java.lang.Object
-
- org.apache.http.message.BasicLineFormatter
-
- All Implemented Interfaces:
LineFormatter
@Contract(threading=IMMUTABLE) public class BasicLineFormatter extends java.lang.Object implements LineFormatter
Interface for formatting elements of the HEAD section of an HTTP message. This is the complement toLineParser. 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
Fields Modifier and Type Field Description static BasicLineFormatterDEFAULTDeprecated.(4.3) useINSTANCEstatic BasicLineFormatterINSTANCE
-
Constructor Summary
Constructors Constructor Description BasicLineFormatter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CharArrayBufferappendProtocolVersion(CharArrayBuffer buffer, ProtocolVersion version)Formats a protocol version.static java.lang.StringformatHeader(Header header, LineFormatter formatter)Formats a header.CharArrayBufferformatHeader(CharArrayBuffer buffer, Header header)Formats a header.static java.lang.StringformatProtocolVersion(ProtocolVersion version, LineFormatter formatter)Formats a protocol version.static java.lang.StringformatRequestLine(RequestLine reqline, LineFormatter formatter)Formats a request line.CharArrayBufferformatRequestLine(CharArrayBuffer buffer, RequestLine reqline)Formats a request line.static java.lang.StringformatStatusLine(StatusLine statline, LineFormatter formatter)Formats a status line.CharArrayBufferformatStatusLine(CharArrayBuffer buffer, StatusLine statline)Formats a status line.
-
-
-
Field Detail
-
DEFAULT
@Deprecated public static final BasicLineFormatter DEFAULT
Deprecated.(4.3) useINSTANCEA default instance of this class, for use as default or fallback. Note thatBasicLineFormatteris not a singleton, there can be many instances of the class itself and of derived classes. The instance here provides non-customized, default behavior.
-
INSTANCE
public static final BasicLineFormatter INSTANCE
-
-
Method Detail
-
formatProtocolVersion
public static java.lang.String formatProtocolVersion(ProtocolVersion version, LineFormatter formatter)
Formats a protocol version.- Parameters:
version- the protocol version to formatformatter- the formatter to use, ornullfor thedefault- Returns:
- the formatted protocol version
-
appendProtocolVersion
public CharArrayBuffer appendProtocolVersion(CharArrayBuffer buffer, ProtocolVersion version)
Description copied from interface:LineFormatterFormats a protocol version. This method does not follow the general contract forbufferarguments. 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 namedformatProtocolVersion.- Specified by:
appendProtocolVersionin interfaceLineFormatter- Parameters:
buffer- a buffer to which to append, ornullversion- the protocol version to format- Returns:
- a buffer with the formatted protocol version appended.
The caller is allowed to modify the result buffer.
If the
bufferargument is notnull, the returned buffer is the argument buffer.
-
formatRequestLine
public static java.lang.String formatRequestLine(RequestLine reqline, LineFormatter formatter)
Formats a request line.- Parameters:
reqline- the request line to formatformatter- the formatter to use, ornullfor thedefault- Returns:
- the formatted request line
-
formatRequestLine
public CharArrayBuffer formatRequestLine(CharArrayBuffer buffer, RequestLine reqline)
Description copied from interface:LineFormatterFormats a request line.- Specified by:
formatRequestLinein interfaceLineFormatter- Parameters:
buffer- a buffer available for formatting, ornull. The buffer will be cleared before use.reqline- the request line to format- Returns:
- the formatted request line
-
formatStatusLine
public static java.lang.String formatStatusLine(StatusLine statline, LineFormatter formatter)
Formats a status line.- Parameters:
statline- the status line to formatformatter- the formatter to use, ornullfor thedefault- Returns:
- the formatted status line
-
formatStatusLine
public CharArrayBuffer formatStatusLine(CharArrayBuffer buffer, StatusLine statline)
Description copied from interface:LineFormatterFormats a status line.- Specified by:
formatStatusLinein interfaceLineFormatter- Parameters:
buffer- a buffer available for formatting, ornull. The buffer will be cleared before use.statline- the status line to format- Returns:
- the formatted status line
-
formatHeader
public static java.lang.String formatHeader(Header header, LineFormatter formatter)
Formats a header.- Parameters:
header- the header to formatformatter- the formatter to use, ornullfor thedefault- Returns:
- the formatted header
-
formatHeader
public CharArrayBuffer formatHeader(CharArrayBuffer buffer, Header header)
Description copied from interface:LineFormatterFormats 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.
- Specified by:
formatHeaderin interfaceLineFormatter- Parameters:
buffer- a buffer available for formatting, ornull. The buffer will be cleared before use.header- the header to format- Returns:
- a buffer holding the formatted header, never
null. The returned buffer may be different from the argument buffer.
-
-