简体   繁体   中英

Why does netty example for HttpStaticFileServer use RandomAccessFile?

netty HttpStaticFileServerHandler示例使用RandomAccessFile有任何特定原因吗?

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 choose FileInputStream instead of RandomAccessFile which also returns a FileChannel . But I cannot get fileLength from FileInputStream which is a required input for DefaultFileRegion . So I think it is necessary to use RandomAccessFile .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM