I want to download and save a file in local directory from server by Spring-OpenFeign with zero-copy.
Naive download method as following:
import org.apache.commons.io.FileUtils
@GetMapping("/api/v1/files")
ResponseEntity<byte[]> getFile(@RequestParam(value = "key") String key) {
ResponseEntity<byte[]> resp = getFile("filename.txt")
File fs = new File("/opt/test")
FileUtils.write(file, resp.getBody())
}
In this code, data flow will be like this feign Internal Stream -> Buffer -> ByteArray -> Buffer -> File
How can I downalod and save a file memory-efficiently and faster way?