docs: public static void chunkedCopy(InputStream src, File dest) throws IOException
    {
  
      final byte[] buf = new byte[8 << 20]; // 8Mb buffer
      long offset = 0;
      long lastOffset = 0;
  
      try (final RandomAccessFile raf = new RandomAccessFile(dest, "rw")) {
        final int fd = getfd(raf.getFD());
  
        for (int numBytes = 0, bytesRead = 0, lastBytes = 0; bytesRead > -1;) {
          bytesRead = src.read(buf, numBytes, buf.length - numBytes);
  
          if (numBytes >= buf.length || bytesRead == -1) {
            raf.write(buf, 0, numBytes);
  
            // This won't block, but will start writeout asynchronously
            trySyncFileRange(fd, offset, numBytes, SYNC_FILE_RANGE_WRITE);
            if (offset > 0) {
              // This does a blocking write-and-wait on any old ranges
              trySyncFileRange(fd, lastOffset, lastBytes,
                  SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE | SYNC_FILE_RANGE_WAIT_AFTER);
              // Remove the old range from the cache
              trySkipCache(fd, lastOffset, lastBytes);
            }
            lastOffset = offset;
            offset = raf.getFilePointer();
            numBytes = 0;
          }
          lastBytes = numBytes;
  
          numBytes += bytesRead;
        }
      }
    }