public abstract class ResponseBody extends Object implements Closeable
Response都实现了Closeable。关闭一个响应就是关闭它的响应体。如果您
调用NewCall.execute()或实现Callback.onResponse(org.aoju.bus.http.NewCall, org.aoju.bus.http.Response),则必须通过
调用以下任何方法来关闭此主体:
bytes()
或string()将整个响应读入内存。或者使用source()、byteStream()
或charStream()来处理响应| Constructor and Description |
|---|
ResponseBody() |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
bytes() |
InputStream |
byteStream() |
Reader |
charStream() |
void |
close() |
abstract long |
contentLength() |
abstract MediaType |
contentType() |
static ResponseBody |
create(MediaType contentType,
byte[] content)
新的响应体,它传输
content |
static ResponseBody |
create(MediaType contentType,
ByteString content)
新的响应体,它传输
content |
static ResponseBody |
create(MediaType contentType,
long contentLength,
BufferSource content)
新的响应体,它传输
content |
static ResponseBody |
create(MediaType contentType,
String content)
返回一个传输
content的新响应体。如果contentType是非空且缺少字符集,则使用UTF-8 |
abstract BufferSource |
source() |
String |
string() |
public static ResponseBody create(MediaType contentType, String content)
content的新响应体。如果contentType是非空且缺少字符集,则使用UTF-8contentType - 媒体类型content - 内容public static ResponseBody create(MediaType contentType, byte[] content)
contentcontentType - 媒体类型content - 内容public static ResponseBody create(MediaType contentType, ByteString content)
contentcontentType - 媒体类型content - 内容public static ResponseBody create(MediaType contentType, long contentLength, BufferSource content)
contentcontentType - 媒体类型contentLength - 内容大小content - 内容public abstract MediaType contentType()
public abstract long contentLength()
public final InputStream byteStream()
public abstract BufferSource source()
public final byte[] bytes()
throws IOException
IOExceptionpublic final Reader charStream()
public final String string() throws IOException
IOExceptionpublic void close()
close in interface Closeableclose in interface AutoCloseableCopyright © 2019. All rights reserved.