Package org.apache.juneau.http.entity
Class FileBody
java.lang.Object
org.apache.juneau.http.entity.FileBody
- All Implemented Interfaces:
HttpBody
A repeatable
HttpBody that streams content from a File.
getContentLength() returns the file size, allowing transports to set Content-Length.
- 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.getFile()Returns the underlying file.booleanReturnstrueif this body can be written more than once.static FileBodyCreates aFileBodywithapplication/octet-streamcontent type.static FileBodyCreates aFileBodywith the given content type.voidwriteTo(OutputStream out) Writes the body content to the given output stream.
-
Method Details
-
of
Creates aFileBodywithapplication/octet-streamcontent type.- Parameters:
file- The file. Must not benull .- Returns:
- A new instance. Never
null .
-
of
Creates aFileBodywith the given content type.- Parameters:
file- The file. Must not benull .contentType- The MIME content type. May benull .- Returns:
- A new instance. Never
null .
-
getFile
Returns the underlying file.- Returns:
- The file. 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.
-