Package org.apache.juneau.http.entity
Class ReaderBody
java.lang.Object
org.apache.juneau.http.entity.ReaderBody
- All Implemented Interfaces:
HttpBody
A non-repeatable
HttpBody that streams character content from a Reader, encoded as UTF-8.
The character analog of StreamBody. Because the reader is one-shot, isRepeatable() returns
false and HttpBody.getContentLength() returns -1 (the transport must use chunked transfer encoding).
Content is streamed directly through writeTo(OutputStream) rather than being drained into a String
first.
The caller is responsible for closing the wrapped reader after the response has been consumed.
- Since:
- 9.2.1
-
Method Summary
Modifier and TypeMethodDescriptionReturns the MIME content type of this body, e.g.booleanReturnstrueif this body can be written more than once.static ReaderBodyCreates aReaderBodywithtext/plaincontent type.static ReaderBodyCreates aReaderBodywith the given content type.voidwriteTo(OutputStream out) Writes the body content to the given output stream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.juneau.http.HttpBody
getContentLength
-
Method Details
-
of
Creates aReaderBodywithtext/plaincontent type.- Parameters:
reader- The reader. Must not benull .- Returns:
- A new instance. Never
null .
-
of
Creates aReaderBodywith the given content type.- Parameters:
reader- The reader. Must not benull .contentType- The MIME content type. 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.
-
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.
-