private ResponseEntity<OutputStream> downAttachment(InputStream is, OutputStream os, String fileName)
throws IOException {
byte[] buffer = new byte[1024];
int length = 0;
while (-1 != (length = is.read(buffer, 0, buffer.length))) {
os.write(buffer, 0, length);
}
return export(os, fileName);
}
private ResponseEntity<OutputStream> export(OutputStream os, String fileName) {
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition", "attachment; filename=" + System.currentTimeMillis() + fileName);
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
return ResponseEntity.ok().headers(headers).contentType(MediaType.parseMediaType("application/octet-stream"))
.body(os);
}