## org.apache.http.message
Class BasicLineFormatter

    java.lang.Object
      org.apache.http.message.BasicLineFormatter

All Implemented Interfaces:
  LineFormatter

    @Immutable
    public class BasicLineFormatter

extends Object
implements LineFormatter

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

Constructor Summary
`BasicLineFormatter()`

Method Summary
`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 String` `formatHeader(Header header, LineFormatter formatter)` Formats a header.
`static String` `formatProtocolVersion(ProtocolVersion version, LineFormatter formatter)` Formats a protocol version.
`CharArrayBuffer` `formatRequestLine(CharArrayBuffer buffer, RequestLine reqline)` Formats a request line.
`static String` `formatRequestLine(RequestLine reqline, LineFormatter formatter)` Formats a request line.
`CharArrayBuffer` `formatStatusLine(CharArrayBuffer buffer, StatusLine statline)` Formats a status line.
`static String` `formatStatusLine(StatusLine statline, LineFormatter formatter)` Formats a status line.
`protected CharArrayBuffer` `initBuffer(CharArrayBuffer buffer)` Obtains a buffer for formatting.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT

    public static final BasicLineFormatter DEFAULT

  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.

Constructor Detail

### BasicLineFormatter

    public BasicLineFormatter()

Method Detail

### initBuffer

    protected CharArrayBuffer initBuffer(CharArrayBuffer buffer)

  Obtains a buffer for formatting.

  Parameters:
    `buffer` - a 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

    public static final String formatProtocolVersion(ProtocolVersion version,
                                                     LineFormatter formatter)

  Formats a protocol version.

  Parameters:
    `version` - the protocol version to format
    `formatter` - the formatter to use, or `null` for the `default`
  Returns:
    the formatted protocol version

### appendProtocolVersion

    public CharArrayBuffer appendProtocolVersion(CharArrayBuffer buffer,
                                                 ProtocolVersion version)

  Description copied from interface: `LineFormatter`
  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`.

  Specified by:
    `appendProtocolVersion` in interface `LineFormatter`
  Parameters:
    `buffer` - a buffer to which to append, or `null`
    `version` - 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 `buffer` argument is not `null`, the returned buffer is the argument buffer.

### estimateProtocolVersionLen

    protected int estimateProtocolVersionLen(ProtocolVersion version)

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

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

### formatRequestLine

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

  Formats a request line.

  Parameters:
    `reqline` - the request line to format
    `formatter` - the formatter to use, or `null` for the `default`
  Returns:
    the formatted request line

### formatRequestLine

    public CharArrayBuffer formatRequestLine(CharArrayBuffer buffer,
                                             RequestLine reqline)

  Description copied from interface: `LineFormatter`
  Formats a request line.

  Specified by:
    `formatRequestLine` in interface `LineFormatter`
  Parameters:
    `buffer` - a buffer available for formatting, or `null`. The buffer will be cleared before use.
    `reqline` - the request line to format
  Returns:
    the formatted request line

### doFormatRequestLine

    protected void doFormatRequestLine(CharArrayBuffer buffer,
                                       RequestLine reqline)

  Actually formats a request line. Called from `formatRequestLine(org.apache.http.RequestLine, org.apache.http.message.LineFormatter)`.

  Parameters:
    `buffer` - the empty buffer into which to format, never `null`
    `reqline` - the request line to format, never `null`

### formatStatusLine

    public static final String formatStatusLine(StatusLine statline,
                                                LineFormatter formatter)

  Formats a status line.

  Parameters:
    `statline` - the status line to format
    `formatter` - the formatter to use, or `null` for the `default`
  Returns:
    the formatted status line

### formatStatusLine

    public CharArrayBuffer formatStatusLine(CharArrayBuffer buffer,
                                            StatusLine statline)

  Description copied from interface: `LineFormatter`
  Formats a status line.

  Specified by:
    `formatStatusLine` in interface `LineFormatter`
  Parameters:
    `buffer` - a buffer available for formatting, or `null`. The buffer will be cleared before use.
    `statline` - the status line to format
  Returns:
    the formatted status line

### doFormatStatusLine

    protected void doFormatStatusLine(CharArrayBuffer buffer,
                                      StatusLine statline)

  Actually formats a status line. Called from `formatStatusLine(org.apache.http.StatusLine, org.apache.http.message.LineFormatter)`.

  Parameters:
    `buffer` - the empty buffer into which to format, never `null`
    `statline` - the status line to format, never `null`

### formatHeader

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

  Formats a header.

  Parameters:
    `header` - the header to format
    `formatter` - the formatter to use, or `null` for the `default`
  Returns:
    the formatted header

### formatHeader

    public CharArrayBuffer formatHeader(CharArrayBuffer buffer,
                                        Header header)

  Description copied from interface: `LineFormatter`
  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.

  Specified by:
    `formatHeader` in interface `LineFormatter`
  Parameters:
    `buffer` - a buffer available for formatting, or `null`. 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.

### doFormatHeader

    protected void doFormatHeader(CharArrayBuffer buffer,
                                  Header header)

  Actually formats a header. Called from `formatHeader(org.apache.http.Header, org.apache.http.message.LineFormatter)`.

  Parameters:
    `buffer` - the empty buffer into which to format, never `null`
    `header` - the header to format, never `null`

Copyright © 2005-2013 The Apache Software Foundation. All Rights Reserved.