| Constructor and Description |
|---|
ResponseBody(Response response,
InputStream in)
构造,不读取响应体,忽略响应体EOF错误
|
ResponseBody(Response response,
InputStream in,
boolean isAsync,
boolean isIgnoreEOFError)
构造
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
long |
contentLength()
获取写出字节长度,未知为-1
|
String |
contentType()
获取Content-Type
根据实现不同,Content-Type可能包含编码信息,也可以不包含 |
byte[] |
getBytes()
获取响应内容的bytes
|
InputStream |
getStream()
获取body资源流
|
String |
getString()
获取响应字符串,自动识别判断编码
|
ResponseBody |
sync()
同步数据到内存,以bytes形式存储
|
String |
toString() |
File |
write(File targetFileOrDir)
将响应内容写出到文件
异步模式下直接读取Http流写出,同步模式下将存储在内存中的响应内容写出 写出后会关闭Http流(异步模式) |
File |
write(File targetFileOrDir,
StreamProgress streamProgress)
将响应内容写出到文件-避免未完成的文件
来自:https://gitee.com/dromara/hutool/pulls/407
此方法原理是先在目标文件同级目录下创建临时文件,下载之,等下载完毕后重命名,避免因下载错误导致的文件不完整。 |
File |
write(File targetFileOrDir,
String tempFileSuffix,
StreamProgress streamProgress)
将响应内容写出到文件-避免未完成的文件
来自:https://gitee.com/dromara/hutool/pulls/407
此方法原理是先在目标文件同级目录下创建临时文件,下载之,等下载完毕后重命名,避免因下载错误导致的文件不完整。 |
void |
write(OutputStream out)
写出数据,不关闭流
|
long |
write(OutputStream out,
boolean isCloseOut,
StreamProgress streamProgress)
|
File |
write(String targetFileOrDir)
将响应内容写出到文件
|
File |
writeDirect(File targetFileOrDir,
String customParamName,
StreamProgress streamProgress)
将响应内容直接写出到文件,目标为目录则从Content-Disposition中获取文件名
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcontentType, writeClosepublic ResponseBody(Response response, InputStream in)
response - 响应体in - HTTP主体响应流public ResponseBody(Response response, InputStream in, boolean isAsync, boolean isIgnoreEOFError)
response - 响应体in - HTTP主体响应流isAsync - 是否异步模式isIgnoreEOFError - 是否忽略EOF错误public String contentType()
HttpBodycontentType in interface HttpBodypublic long contentLength()
HttpBodycontentLength in interface HttpBodypublic InputStream getStream()
HttpBodygetStream in interface HttpBodyInputStreampublic void write(OutputStream out)
HttpBodypublic ResponseBody sync()
public byte[] getBytes()
public String getString()
public long write(OutputStream out, boolean isCloseOut, StreamProgress streamProgress)
out - 写出的流isCloseOut - 是否关闭输出流streamProgress - 进度显示接口,通过实现此接口显示下载进度public File write(String targetFileOrDir)
targetFileOrDir - 写出到的文件或目录的路径public File write(File targetFileOrDir)
targetFileOrDir - 写出到的文件或目录public File write(File targetFileOrDir, StreamProgress streamProgress)
targetFileOrDir - 写出到的文件或目录streamProgress - 进度显示接口,通过实现此接口显示下载进度public File write(File targetFileOrDir, String tempFileSuffix, StreamProgress streamProgress)
targetFileOrDir - 写出到的文件或目录tempFileSuffix - 临时文件后缀,默认".temp"streamProgress - 进度显示接口,通过实现此接口显示下载进度public File writeDirect(File targetFileOrDir, String customParamName, StreamProgress streamProgress)
targetFileOrDir - 写出到的文件customParamName - 自定义的Content-Disposition中文件名的参数名streamProgress - 进度显示接口,通过实现此接口显示下载进度public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2025. All rights reserved.