org.apache.hc.core5.http.impl.io

## Class AbstractMessageWriter<T extends HttpMessage>

- java.lang.Object
- - org.apache.hc.core5.http.impl.io.AbstractMessageWriter<T>

- All Implemented Interfaces:
    HttpMessageWriter<T>
  Direct Known Subclasses:
    DefaultHttpRequestWriter, DefaultHttpResponseWriter

      public abstract class AbstractMessageWriter<T extends HttpMessage>
      extends Object
      implements HttpMessageWriter<T>

  Abstract base class for HTTP message writers that serialize output to an instance of `SessionOutputBuffer`.
  Since:
    4.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractMessageWriter(LineFormatter formatter)` Creates an instance of AbstractMessageWriter.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `write(T message, SessionOutputBuffer buffer, OutputStream outputStream)` Serializes an instance of `MessageHeaders` to the given output stream.
    `protected abstract void` | `writeHeadLine(T message, CharArrayBuffer lineBuf)` Subclasses must override this method to write out the first header line based on the `HttpMessage` passed as a parameter.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AbstractMessageWriter

          public AbstractMessageWriter(LineFormatter formatter)

      Creates an instance of AbstractMessageWriter.
      Parameters:
        `formatter` - the line formatter If `null` `BasicLineFormatter.INSTANCE` will be used.
      Since:
        4.3

  - ### Method Detail

    - #### writeHeadLine

          protected abstract void writeHeadLine(T message,
                           CharArrayBuffer lineBuf)
                                         throws IOException

      Subclasses must override this method to write out the first header line based on the `HttpMessage` passed as a parameter.
      Parameters:
        `message` - the message whose first line is to be written out.
        `lineBuf` - line buffer
      Throws:
        `IOException` - in case of an I/O error.

    - #### write

          public void write(T message,
                   SessionOutputBuffer buffer,
                   OutputStream outputStream)
                     throws IOException,
                            HttpException

      Description copied from interface: `HttpMessageWriter`
      Serializes an instance of `MessageHeaders` to the given output stream.
      Specified by:
        `write` in interface `HttpMessageWriter<T extends HttpMessage>`
      Parameters:
        `message` - HTTP message head
        `buffer` - session output buffer
      Throws:
        `IOException` - in case of an I/O error
        `HttpException` - in case of HTTP protocol violation

Copyright © 2005–2022 The Apache Software Foundation. All rights reserved.