| 构造器和说明 |
|---|
ResponseBody(Response response,
InputStream in,
boolean isAsync,
boolean isIgnoreEOFError)
构造
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close() |
byte[] |
getBytes()
获取响应内容的bytes
|
String |
getContentType()
获取Content-Type
|
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, waitgetContentType, writeClosepublic ResponseBody(Response response, InputStream in, boolean isAsync, boolean isIgnoreEOFError)
response - 响应体in - HTTP主体响应流isAsync - 是否异步模式isIgnoreEOFError - 是否忽略EOF错误public String getContentType()
HttpBodygetContentType 在接口中 HttpBodypublic InputStream getStream()
HttpBodygetStream 在接口中 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 在接口中 Closeableclose 在接口中 AutoCloseableIOExceptionCopyright © 2023. All rights reserved.