Package org.apache.juneau.http.entity
Class ByteArrayBody
java.lang.Object
org.apache.juneau.http.entity.ByteArrayBody
- All Implemented Interfaces:
HttpBody
An
HttpBody backed by a raw byte array.
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 ByteArrayBodyof(byte[] content) Creates aByteArrayBodywithapplication/octet-streamcontent type.static ByteArrayBodyCreates aByteArrayBodywith the given content type.voidwriteTo(OutputStream out) Writes the body content to the given output stream.
-
Method Details
-
of
Creates aByteArrayBodywithapplication/octet-streamcontent type.- Parameters:
content- The byte array. Must not benull . The array is defensively copied.- Returns:
- A new instance. Never
null .
-
of
Creates aByteArrayBodywith the given content type.- Parameters:
content- The byte array. Must not benull . The array is defensively copied.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.
-
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.
-