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

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

    Details

    • Subcomponent:
    • Resolved In Build:
      b05
    • CPU:
      generic
    • OS:
      generic

      Description

      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()`.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bpb Brian Burkhalter
                Reporter:
                sbordet Simone Bordet
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: