I tried to use nio to download photo file by API, but I am not sure how to create a channel to response, is this code correct?
@RequestMapping(value = "/photosFast/{filename}.jpg", method = RequestMethod.GET)
@ResponseBody
...
FileChannel srcChannel = new FileInputStream(src.getAbsolutePath()).getChannel();
FileChannel destChannel = new FileOutputStream(response.getHeader("localtion")).getChannel();
try {
srcChannel.transferTo(0, srcChannel.size(), destChannel);
} finally {
srcChannel.close();
destChannel.close();
}
...