Class HttpBody
java.lang.Object
com.google.genai.gaos.utils.transport.HttpBody
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract longReturns the number of bytes in the body, or -1 if unknown.static HttpBodyempty()Returns an empty, repeatable body.abstract booleanReturns true ifstream()can be called more than once.static HttpBodyof(byte[] bytes) Returns a repeatable body backed by the given bytes.static HttpBodyReturns a repeatable body containing the UTF-8 bytes of the given text.static HttpBodyReturns a repeatable body that reads the given file on each call tostream().static HttpBodyReturns a one-shot body backed by the given stream.static HttpBodyofInputStream(InputStream in, long contentLength) Returns a one-shot body backed by the given stream, reporting the given content length (-1 if unknown).abstract InputStreamstream()Returns the body content as anInputStream.
-
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 ifstream()can be called more than once. -
stream
Returns the body content as anInputStream. See the class documentation for repeatability semantics.- Throws:
IOException
-
empty
Returns an empty, repeatable body. -
of
Returns a repeatable body backed by the given bytes. The array is not copied; it must not be modified after this call. -
of
Returns a repeatable body containing the UTF-8 bytes of the given text. -
ofFile
Returns a repeatable body that reads the given file on each call tostream(). -
ofInputStream
Returns a one-shot body backed by the given stream. -
ofInputStream
Returns a one-shot body backed by the given stream, reporting the given content length (-1 if unknown).
-