1
0
mirror of https://gitee.com/dromara/hutool.git synced 2025-04-05 17:37:59 +08:00

HttpRequest增加setFixedLengthStreamingMode方法

This commit is contained in:
Looly 2024-09-13 18:57:00 +08:00
parent 6ebca582f1
commit b00844e896
3 changed files with 29 additions and 1 deletions
CHANGELOG.md
hutool-http/src/main/java/cn/hutool/http

View File

@ -2,7 +2,7 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.33(2024-09-11)
# 5.8.33(2024-09-13)
### 🐣新特性
* 【core 】 SyncFinisher增加setExecutorService方法issue#IANKQ1@Gitee
@ -11,6 +11,7 @@
* 【crypto 】 SM2解密时兼容GmSSL非压缩省略的04头的密文issue#IAP1QJ@Gitee
* 【core 】 兼容NumberUtil.add方法传入整型自动类型转换为浮点类型的精度丢失问题pr#3721@Github
* 【core 】 ModifierUtil明确注释并增加hasAllModifiers方法issue#IAQ2U0@Gitee
* 【http 】 HttpRequest增加setFixedLengthStreamingMode方法issue#3462@Github
### 🐞Bug修复
* 【json 】 修复JSONConfig.setDateFormat设置后toBean无效问题issue#3713@Github

View File

@ -351,6 +351,20 @@ public class HttpConnection {
return this;
}
/**
* 设置固定长度流模式默认为0表示不设置固定长度流模式即默认为按需发送数据长度<br>
* 当发送大文件时如果每次发送的数据长度不一致可能造成接收方无法正常接收此时可以设置固定长度流模式此时发送的数据长度为contentLength不足部分用0补齐
*
* @param contentLength 固定长度
* @return this
*/
public HttpConnection setFixedLengthStreamingMode(long contentLength){
if(contentLength > 0){
conn.setFixedLengthStreamingMode(contentLength);
}
return this;
}
/**
* 采用流方式上传数据无需本地缓存数据<br>
* HttpUrlConnection默认是将所有数据读到本地缓存然后再发送给服务器这样上传大文件时就会导致内存溢出

View File

@ -350,6 +350,19 @@ public class HttpRequest extends HttpBase<HttpRequest> {
return this.httpConnection;
}
/**
* 设置固定长度流模式默认为0表示不设置固定长度流模式即默认为按需发送数据长度<br>
* 当发送大文件时如果每次发送的数据长度不一致可能造成接收方无法正常接收此时可以设置固定长度流模式此时发送的数据长度为contentLength不足部分用0补齐
*
* @param contentLength 固定长度
* @return this
* @since 5.8.33
*/
public HttpRequest setFixedLengthStreamingMode(long contentLength){
this.httpConnection.setFixedLengthStreamingMode(contentLength);
return this;
}
/**
* 设置请求方法
*