- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionThe content type that should be used for thisBody.static Bodyempty()Creates an emptyBodywhich will send no bytes to the client.static Bodyof(byte[] value) Creates aBodywrapping the givenbyte[].static Bodyof(InputStream inputStream) Creates aBodywrapping the givenbyte[].static Bodyof(InputStream inputStream, ResponseLength responseLength) Creates aBodywrapping the givenbyte[].static BodyConstructs a body which wraps the givenString.static BodyConstructs a body which wraps the givenString.default ResponseLengthThe length of the response body that will be written whenwriteTo(OutputStream)is called.voidwriteTo(OutputStream outputStream) Writes the response body to the providedOutputStream.
-
Method Details
-
writeTo
Writes the response body to the providedOutputStream. The number of bytes written must match what is returned byresponseLength().It is not expected that calling this method will close any underlying resources of the
Body, though an implementation may choose to do so.This method should not close the provided
OutputStream.- Parameters:
outputStream- TheOutputStreamto write the body to.- Throws:
IOException- If something goes wrong while writing to theOutputStream.
-
responseLength
The length of the response body that will be written whenwriteTo(OutputStream)is called.- Returns:
- The length of the response body.
-
defaultContentType
The content type that should be used for thisBody.It is expected that some types of bodies will have an opinion about what
Content-Typeheader should be sent along with them. The value returned by this method will be used if there is no content type specified by the user.- Returns:
- The content type to use by default.
-
of
-
of
-
of
Creates aBodywrapping the givenbyte[].Note that this does not do any defensive copying of the underlying byte array.
- Parameters:
value- Thebyte[]to send.- Returns:
- A body which wraps the given
byte[].
-
of
Creates aBodywrapping the givenbyte[].Note that the
InputStreamprovided will not be closed whenwriteTo(OutputStream)is called.- Parameters:
inputStream- TheInputStreamto send.- Returns:
- A body which wraps the given
InputStream.
-
of
Creates aBodywrapping the givenbyte[].Note that the
InputStreamprovided will not be closed whenwriteTo(OutputStream)is called.- Parameters:
inputStream- inputStream TheInputStreamto send.responseLength- The expected number of bytes that will be written whenInputStream.transferTo(OutputStream)is called.- Returns:
- A body which wraps the given
InputStream.
-
empty
Creates an emptyBodywhich will send no bytes to the client.- Returns:
- An empty body.
-