Package org.apache.juneau.http.entity
Class StreamBody
java.lang.Object
org.apache.juneau.http.entity.StreamBody
- All Implemented Interfaces:
HttpBody
A non-repeatable
HttpBody that streams content from an InputStream.
Because the stream is one-shot, isRepeatable() returns false and HttpBody.getContentLength()
returns -1 (the transport must use chunked transfer encoding).
The caller is responsible for closing the wrapped stream 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 StreamBodyof(InputStream stream) Creates aStreamBodywithapplication/octet-streamcontent type.static StreamBodyof(InputStream stream, String contentType) Creates aStreamBodywith 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 aStreamBodywithapplication/octet-streamcontent type.- Parameters:
stream- The input stream. Must not benull .- Returns:
- A new instance. Never
null .
-
of
Creates aStreamBodywith the given content type.- Parameters:
stream- The input stream. 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.
-