问题描述
我正在研究an open source Swift library,它能够将InputStream分成多个BoundedInputStream对象,给定一个总流大小(知道何时停止创建有界输入流)。我不明白为什么在初始InputStream关闭后没有选择自动停止BoundedInputStream创建的原因。
代码看起来像这样:
protected Long segmentationSize = 5368709120L;
protected Long currentSegment = 0L;
private InputStream inputStream; // supplied externally
private long inputStreamSize; // supplied externally
public void uploadSegmentedobjects() {
InputStream segmentStream = getNextSegment();
while (segmentStream != null) {
// do something
}
}
public InputStream getNextSegment() {
if (done()) {
return null;
}
InputStream segment = createSegment();
currentSegment++;
return segment;
}
protected boolean done() {
return currentSegment * segmentationSize > inputStreamSize;
}
@Override
protected InputStream createSegment() throws IOException {
BoundedInputStream stream = new BoundedInputStream(inputStream,segmentationSize);
stream.setPropagateClose(false);
return stream;
}
从本质上讲,我需要知道如何重写done()方法,以使其不依赖于inputStreamSize变量,而在流关闭时返回null。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)