Package org.apache.juneau.http.entity
Class StringBody
java.lang.Object
org.apache.juneau.http.entity.StringBody
- All Implemented Interfaces:
HttpBody
An
HttpBody backed by a UTF-8 string.
Repeatable: the same instance may be written multiple times.
- 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 StringBodyCreates aStringBodywith the given content andtext/plain; charset=UTF-8content type.static StringBodyCreates aStringBodywith the given content and content type.toString()voidwriteTo(OutputStream out) Writes the body content to the given output stream.
-
Method Details
-
of
Creates aStringBodywith the given content andtext/plain; charset=UTF-8content type.- Parameters:
content- The string content. Must not benull .- Returns:
- A new instance. Never
null .
-
of
Creates aStringBodywith the given content and content type.- Parameters:
content- The string content. Must not benull .contentType- The MIME content type (e.g."application/json; charset=UTF-8"). May 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.
-
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.
-
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.
-
toString
-