netty有没有什么具体原因HttpStaticFileServerHandler使用 RandomAccessFile 的示例?
最佳答案
我认为这样他们可以演示 ChunkedFile
的使用,这需要一个 RandomAccessFile
。原因似乎是 ChunkedFile
需要能够获取文件的长度。
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
.
大体上是正确的。但是,您可能会通过其他方式获得文件长度;例如使用 File.length()
。
实际上,获取 FileChannel
和文件长度的方式并没有太大区别。
关于java - 为什么 HttpStaticFileServer 的 netty 示例使用 RandomAccessFile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17857592/