Class HttpBody

java.lang.Object
com.google.genai.gaos.utils.transport.HttpBody

public abstract class HttpBody extends Object
A request body carrier that is independent of the underlying HTTP client.

Bodies created from a byte array, String or Path are repeatable: stream() may be called any number of times (for example on retry). Bodies created from an InputStream return the same underlying stream on each call and therefore may be empty or partial if replayed after the stream has been consumed.

  • Constructor Details

    • HttpBody

      public HttpBody()
  • Method Details

    • contentLength

      public abstract long contentLength()
      Returns the number of bytes in the body, or -1 if unknown.
    • isRepeatable

      public abstract boolean isRepeatable()
      Returns true if stream() can be called more than once.
    • stream

      public abstract InputStream stream() throws IOException
      Returns the body content as an InputStream. See the class documentation for repeatability semantics.
      Throws:
      IOException
    • empty

      public static HttpBody empty()
      Returns an empty, repeatable body.
    • of

      public static HttpBody of(byte[] bytes)
      Returns a repeatable body backed by the given bytes. The array is not copied; it must not be modified after this call.
    • of

      public static HttpBody of(String text)
      Returns a repeatable body containing the UTF-8 bytes of the given text.
    • ofFile

      public static HttpBody ofFile(Path path)
      Returns a repeatable body that reads the given file on each call to stream().
    • ofInputStream

      public static HttpBody ofInputStream(InputStream in)
      Returns a one-shot body backed by the given stream.
    • ofInputStream

      public static HttpBody ofInputStream(InputStream in, long contentLength)
      Returns a one-shot body backed by the given stream, reporting the given content length (-1 if unknown).