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

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;
}
/**
* 设置请求方法
*