Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8227080

(fs) Files.newInputStream(...).skip(n) is slow

XMLWordPrintable

    • b05
    • generic
    • generic

        Ranged HTTP requests (https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests) may require implementations to use `InputStream.skip(int)` to skip to the requested range.

        java.io.FileInputStream.skip(int) implementation is native and uses "seek" primitives that are very efficient.

        On the contrary, Files.newInputStream(...) returns a `sun.nio.ch.ChannelInputStream` whose `skip(int)` implementation (inherited from `InputStream`) is to read and discard using 2 KiB buffers, which is very inefficient for large files (where ranged HTTP requests are more likely to be used).

        `ChannelInputStream` could override `skip(int)` and check if the channel is a `SeekableByteChannel`, as it is already done for `available()`.

              bpb Brian Burkhalter
              sbordet Simone Bordet
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: