FileChannel#force 是否等同于 OutputStream#flush?我总是必须打电话给它吗?
Is FileChannel#force is equivalent to OutputStream#flush? Do I always have to call it?
我有一个 class 像 FilterOutputStream
.
public class WritableFilterChannel implements WritableChannel {
public WritableFilterChannel(final WritableByteChannel channel) {
super();
this.channel = channel;
}
// isOpen(), close() delegates to the channel
// write(ByteBuffer) overridden to work differently
protected WritableByteChannel channel;
}
当我传递 FileChannel
的实例时,除了 close()
之外没有其他方法 force()
。
FileChannel#force
是否等同于OutputStream#flush
?我总是必须调用它吗?
我必须这样做吗?
@Override
public void close() {
if (channel instanceof FileChannel) throws IOException {
((FileChannel) channel).force(); // general solution?
}
channel.close();
}
我有一个 class 像 FilterOutputStream
.
public class WritableFilterChannel implements WritableChannel {
public WritableFilterChannel(final WritableByteChannel channel) {
super();
this.channel = channel;
}
// isOpen(), close() delegates to the channel
// write(ByteBuffer) overridden to work differently
protected WritableByteChannel channel;
}
当我传递 FileChannel
的实例时,除了 close()
之外没有其他方法 force()
。
FileChannel#force
是否等同于OutputStream#flush
?我总是必须调用它吗?
我必须这样做吗?
@Override
public void close() {
if (channel instanceof FileChannel) throws IOException {
((FileChannel) channel).force(); // general solution?
}
channel.close();
}