HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection();
InputStream in = conn.getInputStream();
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[1024];
int len = 0;
while ((len = in.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, len);
}
byte[] body = swapStream.toByteArray();
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment;filename=" + fileName);
HttpStatus statusCode = HttpStatus.OK;
ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(body, headers, statusCode);
return response;