Conversion constructor that accepts a ByteBuffer.
the actual body content (also known as response entity)
the content type received from the webserver, if any, or else some suitable default
(Since version since v0.21.6) Use the simpler constructor
Get the body of the response as an array of bytes.
Get the body of the response as an array of bytes.
Get the body of the response as a string.
Get the body of the response as a string. This uses the character encoding of the contentType, or UTF-8 as a default. If the data is binary, this method always returns a blank string.
the actual body content (also known as response entity)
Closes the input stream that provides the data for this response.
Closes the input stream that provides the data for this response. If the implementation buffers the body, the input stream will have been closed automatically.
Gets the length of the content as the number of bytes received.
Gets the length of the content as the number of bytes received. If compressed on the wire, this will be the uncompressed length so will differ from the 'Content-Length' header. Because 'contentLength' represents the byte array size, 'asString.length' will probably compute a different value.
the content type received from the webserver, if any, or else some suitable default
the content type received from the webserver, if any, or else some suitable default
Gets the content as an input stream.
Gets the content as an input stream. Each time this is called, a new ByteArrayInputStream is returned. This should be closed by the calling code when it has been finished with.
Tests whether the implementation has buffered the whole response body.
Tests whether the implementation has buffered the whole response body. If this returns false, toBufferedBody
provides an easy route to accumulate the entire body in a buffer.
Tests whether this response body can be represented as text, or whether the data is binary.
Tests whether this response body can be represented as text, or whether the data is binary.
Always false.
Always false.
Gets the body as a string split into lines, if available.
Gets the body as a string split into lines, if available. This is only possible for textual content. An IllegalStateException is thrown if the data is binary.
(Changed in version 2.9.0) The behavior of scanRight
has changed. The previous behavior can be reproduced with scanRight.reverse.
Returns 'this'.
Returns 'this'.
Gets the response body as a string for diagnostic purposes.
Gets the response body as a string for diagnostic purposes.
Returns a new StringResponseBody containing the text in this body in immutable form.
Returns a new StringResponseBody containing the text in this body in immutable form. The returned object is safe for sharing between threads.
(Changed in version 2.9.0) transpose
throws an IllegalArgumentException
if collections are not uniformly sized.
Provides a body implementation that copies the whole response from the response input stream into a ByteBuffer. The content is also available as a string without much performance penalty.
If no media type was specified in the response from the server, this class attempts to guess a sensible fallback. This works via the following steps: 1. If the request was a GET request and was successful and the URL ended with a file extension, use a MIME type table to look up the content type. 2. Empty data is application/octet-stream. 3. Data containing control codes is application/octet-stream. 4. Data starting with '<' is text/html. 5. Otherwise text/plain is assumed.
This implementation of uk.co.bigbeeconsultants.http.response.ResponseBody has the advantage of being simple to use. However, take care because the memory footprint will be large when dealing with large volumes of response data. As an alternative, consider uk.co.bigbeeconsultants.http.response.InputStreamResponseBody.
It is safe to share instances between threads provided no thread alters the byteArray data. A tricky design decision was made here: the byte array is mutable because the alternatie would have been awkward to use: immutable alternatives are not widely available, and would not be compatible with standard Java I/O APIs. If required, use
toStringBody
to obtain the immutableStringResponseBody
copy of the data.This class ensures that the socket input stream is always closed correctly, meaning the calling code is simpler because it need not be concerned with cleaning up.
the actual body content (also known as response entity)
the content type received from the webserver, if any, or else some suitable default