I think it so that they can demonstrate the use of ChunkedFile
, which requires a RandomAccessFile
. And the reason for that seems to be that ChunkedFile
needs to be able to get the file's length.
If I am not using https, I need not use
ChunkedFile
. So I can chooseFileInputStream
instead ofRandomAccessFile
which also returns aFileChannel
. But I cannot get fileLength fromFileInputStream
which is a required input forDefaultFileRegion
. So I think it is necessary to useRandomAccessFile
.
That's roughly correct. However, you could potentially get the file length some other way; eg using File.length()
.
Actually, it doesn't make much difference which way you get the FileChannel
and the file length.
需要一个RAF支持零拷贝,该拷贝需要一个FileChannel,该文件通道是最经常从RAF获取的。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.