Package org.apache.juneau.http.entity
Class HttpBodyBean
java.lang.Object
org.apache.juneau.http.entity.HttpBodyBean
- All Implemented Interfaces:
HttpBody
A mutable wrapper around an
HttpBody that allows overriding the content type.
Use this class when you need to wrap an existing body and attach (or override) its Content-Type.
Create instances via the static factory methods:
See Also:
- Since:
- 9.2.1
-
Method Summary
Modifier and TypeMethodDescriptionlongReturns the content length in bytes, or-1if unknown.Returns the MIME content type of this body, e.g.booleanReturnstrueif this body can be written more than once.static HttpBodyBeanCreates anHttpBodyBeanwrapping the given body and retaining its content type.static HttpBodyBeanCreates anHttpBodyBeanwrapping the given body with the specified content type.toString()voidwriteTo(OutputStream out) Writes the body content to the given output stream.
-
Method Details
-
of
Creates anHttpBodyBeanwrapping the given body with the specified content type.- Parameters:
body- The underlying body. Must not benull .contentType- The content type to report. May benull .- Returns:
- A new instance. Never
null .
-
of
Creates anHttpBodyBeanwrapping the given body and retaining its content type.- Parameters:
body- The underlying body. Must not benull .- Returns:
- A new instance. Never
null .
-
getContentType
Description copied from interface:HttpBodyReturns the MIME content type of this body, e.g."application/json; charset=UTF-8".- Specified by:
getContentTypein interfaceHttpBody- Returns:
- The content type, or
null if unknown.
-
getContentLength
Description copied from interface:HttpBodyReturns 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.- Specified by:
getContentLengthin interfaceHttpBody- Returns:
- The content length, or
-1if unknown.
-
isRepeatable
Description copied from interface:HttpBodyReturnstrueif 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.- Specified by:
isRepeatablein interfaceHttpBody- Returns:
trueif repeatable.
-
writeTo
Description copied from interface:HttpBodyWrites the body content to the given output stream.Implementations must not close
out.- Specified by:
writeToin interfaceHttpBody- Parameters:
out- The stream to write to. Nevernull .- Throws:
IOException- If an I/O error occurs.
-
toString
-