Interface HttpBody

All Known Subinterfaces:
HttpResource
All Known Implementing Classes:
ByteArrayBody, FileBody, HttpBodyBean, HttpResourceBean, MultipartBody, PartList, ReaderBody, RecordStreamBody, SerializerBody, StreamBody, StringBody

public interface HttpBody
An HTTP message body (entity), providing content and its associated metadata.

Implementations should stream content directly through writeTo(OutputStream) rather than buffering the entire body in memory. Implementations that can determine the content length without buffering may return a non-negative value from getContentLength(), which allows transports to set Content-Length headers efficiently.

See Also:
Since:
9.2.1
  • Method Summary

    Modifier and Type
    Method
    Description
    default long
    Returns the content length in bytes, or -1 if unknown.
    Returns the MIME content type of this body, e.g.
    default boolean
    Returns true if this body can be written more than once.
    void
    Writes the body content to the given output stream.
  • Method Details

    • getContentType

      Returns the MIME content type of this body, e.g. "application/json; charset=UTF-8".
      Returns:
      The content type, or null if unknown.
    • getContentLength

      default long getContentLength()
      Returns the content length in bytes, or -1 if unknown.

      Implementations that buffer content may return the exact length; streaming implementations should return -1 to cause the transport to use chunked transfer encoding.

      Returns:
      The content length, or -1 if unknown.
    • writeTo

      void writeTo(OutputStream out) throws IOException
      Writes the body content to the given output stream.

      Implementations must not close out.

      Parameters:
      out - The stream to write to. Never null.
      Throws:
      IOException - If an I/O error occurs.
    • isRepeatable

      default boolean isRepeatable()
      Returns true if this body can be written more than once.

      Streaming bodies backed by a one-shot InputStream should return false. Buffered bodies (byte arrays, strings, files) should return true.

      Returns:
      true if repeatable.