code: 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;
        }
      }
    }
docs: Copy from an input stream to a file minimizing cache impact on the destination.. This happens chunk by chunk
  so only at most chunk size will be present in the OS page cache. Posix (Linux, BSD) only. The implementation
  in this method is based on a post by Linus Torvalds here:
  http://lkml.iu.edu/hypermail/linux/kernel/1005.2/01845.html
  
  @param src Source InputStream where to copy from
  @param dest Destination file to copy to
  @throws IOException