Very slow Files.newInputStream(...).skip(n)

Alan Bateman Alan.Bateman at oracle.com
Tue Jul 2 09:08:32 UTC 2019


On 02/07/2019 10:01, Simone Bordet wrote:
> Hi,
>
> we have moved Jetty to use newer APIs, replacing
> java.io.FileInputStream with Files.newInputStream(Path), which
> delegates to FileSystemProvider.newInputStream() which eventually
> returns a sun.nio.ch.ChannelInputStream.
>
> Unfortunately, ChannelInputStream.skip() implementation is very naive
> and very slow for large files.
> On the contrary, FileInputStream.skip() goes native and uses "seek"
> primitives to be efficient.
>
> The use case is that to read a large file (e.g. a movie) using HTTP's
> range requests: the browser sends a request and asks e.g. for the
> bytes ranging from 1 GiB to 1 GiB + 128 KiB.
>
> Calling skip(1073741824) in the two cases will have very different performances.
>
> I am a JDK Author and I can open a bug about this if you think it's appropriate.
>
Yes, please.

-Alan


More information about the nio-dev mailing list