public abstract class ResponseBody extends Object implements Closeable
| Constructor and Description |
|---|
ResponseBody() |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
bytes() |
InputStream |
byteStream() |
Reader |
charStream()
Returns the response as a character stream decoded with the charset
of the Content-Type header.
|
void |
close()
Closes the object and release any system resources it holds.
|
abstract long |
contentLength()
Returns the number of bytes in that will returned by
bytes(), or
byteStream(), or -1 if unknown. |
abstract MediaType |
contentType() |
static ResponseBody |
create(MediaType contentType,
byte[] content)
Returns a new response body that transmits
content. |
static ResponseBody |
create(MediaType contentType,
long contentLength,
BufferedSource content)
Returns a new response body that transmits
content. |
static ResponseBody |
create(MediaType contentType,
String content)
Returns a new response body that transmits
content. |
abstract BufferedSource |
source() |
String |
string()
Returns the response as a string decoded with the charset of the
Content-Type header.
|
public abstract MediaType contentType()
public abstract long contentLength()
throws IOException
bytes(), or
byteStream(), or -1 if unknown.IOExceptionpublic final InputStream byteStream() throws IOException
IOExceptionpublic abstract BufferedSource source() throws IOException
IOExceptionpublic final byte[] bytes()
throws IOException
IOExceptionpublic final Reader charStream() throws IOException
IOExceptionpublic final String string() throws IOException
IOExceptionpublic void close()
throws IOException
CloseableAlthough only the first call has any effect, it is safe to call close
multiple times on the same object. This is more lenient than the
overridden AutoCloseable.close(), which may be called at most
once.
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic static ResponseBody create(MediaType contentType, String content)
content. If contentType is non-null and lacks a charset, this will use UTF-8.public static ResponseBody create(MediaType contentType, byte[] content)
content.public static ResponseBody create(MediaType contentType, long contentLength, BufferedSource content)
content.