Package org.apache.juneau.http
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 TypeMethodDescriptiondefault longReturns the content length in bytes, or-1if unknown.Returns the MIME content type of this body, e.g.default booleanReturnstrueif this body can be written more than once.voidwriteTo(OutputStream out) 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
Returns the content length in bytes, or-1if unknown.Implementations that buffer content may return the exact length; streaming implementations should return
-1to cause the transport to use chunked transfer encoding.- Returns:
- The content length, or
-1if unknown.
-
writeTo
Writes the body content to the given output stream.Implementations must not close
out.- Parameters:
out- The stream to write to. Nevernull .- Throws:
IOException- If an I/O error occurs.
-
isRepeatable
Returnstrueif this body can be written more than once.Streaming bodies backed by a one-shot
InputStreamshould returnfalse. Buffered bodies (byte arrays, strings, files) should returntrue.- Returns:
trueif repeatable.
-