String filename = (item.getDescription());
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
FileInputStream fis = new FileInputStream(f);
FileChannel in = fis.getChannel();
WritableByteChannel out = Channels.newChannel(response.getOutputStream());
try {
in.transferTo(0, in.size(), out);
service.removeFile(id);
} catch (Exception e) {
throw e;
} finally {
in.close();
// make sure servlet doesn't append anything unnecessary:
out.close();
}
}
} catch (FileNotFoundException e) {
log.warn("Error retrieving file: " + e.getMessage());
response.setStatus(HttpServletResponse.SC_NOT_FOUND);