add method

This commit is contained in:
looly 2021-12-24 16:34:34 +08:00
parent e37dfc32a8
commit 246966d5f5
4 changed files with 25 additions and 1 deletions

View File

@ -3,7 +3,7 @@
-------------------------------------------------------------------------------------------------------------
# 5.7.18 (2021-12-23)
# 5.7.18 (2021-12-24)
### 🐣新特性
* 【core 】 新增CollStreamUtil.groupKeyValuepr#479@Gitee
@ -15,6 +15,7 @@
* 【core 】 增加CollStreamUtil.groupBypr#484@Gitee
* 【core 】 增加CollUtil.setValueByMappr#482@Gitee
* 【core 】 LocalDateTimeUtil增加endOfDay重载issue#2025@Github
* 【core 】 IoCopier增加setFlushEveryBuffer方法issue#2022@Github
*
### 🐞Bug修复
* 【core 】 LineReadWatcher#onModify文件清空判断问题issue#2013@Github

View File

@ -25,6 +25,11 @@ public abstract class IoCopier<S, T> {
*/
protected StreamProgress progress;
/**
* 是否每次写出一个buffer内容就执行flush
*/
protected boolean flushEveryBuffer;
/**
* 构造
*
@ -56,4 +61,16 @@ public abstract class IoCopier<S, T> {
protected int bufferSize(long count) {
return (int) Math.min(this.bufferSize, count);
}
/**
* 设置是否每次写出一个buffer内容就执行flush
*
* @param flushEveryBuffer 是否每次写出一个buffer内容就执行flush
* @return this
* @since 5.7.18
*/
public IoCopier<S, T> setFlushEveryBuffer(boolean flushEveryBuffer){
this.flushEveryBuffer = flushEveryBuffer;
return this;
}
}

View File

@ -101,6 +101,9 @@ public class ReaderWriterCopier extends IoCopier<Reader, Writer> {
break;
}
target.write(buffer, 0, read);
if(flushEveryBuffer){
target.flush();
}
numToRead -= read;
total += read;

View File

@ -100,6 +100,9 @@ public class StreamCopier extends IoCopier<InputStream, OutputStream> {
break;
}
target.write(buffer, 0, read);
if(flushEveryBuffer){
target.flush();
}
numToRead -= read;
total += read;