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

@@ -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;