我正在编写代码,以便在处理背压时将文件从一个文件异步复制到另一个文件。
我知道有一个方便的类Pump
来执行复制作业,但是,我正在手动复制工作,因为我想在将数据写入目标之前对其进行转换。
要处理背压,我使用下面的代码
fileRead.handler(buffer -> {
fileWrite.write(applyTransform(buffer));
//check if reader is out of capacity for taking more data
if(fileWrite.writeQueueFull()){
System.out.println("writing queue full:");
//this pauses file handler from being called
fileRead.pause();
//Once, the writer is ready to accept more data, let it take up more
fileWrite.drainHandler(done -> {
System.out.println("write queue drained, so resuming now...");
//allow file reader handler to resume so, that it accepts incoming data
fileRead.resume();
});
}
});
我的问题仅针对fileWrite.writeQueueFull()
WriteStream
setWriteQueueMaxSize(int)
所说的
如果写队列中的字节数多于,则返回true 使用setWriteQueueMaxSize(int)
设置的值
问题是如何确定{{1}}
的int值