1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
private void openApplication(File file, HttpServletResponse res, String application, String filename) {
ByteArrayOutputStream bos = new ByteArrayOutputStream(5000);
try {
// Et on copie le contenu dedans
bos.write(fileToByte(file));
bos.flush();
bos.close();
//file.delete();
res.setStatus(HttpServletResponse.SC_OK);
res.setHeader("Content-Disposition", "attachment; filename=" + filename);
res.setContentType(application);
res.setContentLength(bos.size());
OutputStream os = res.getOutputStream();
os.write(bos.toByteArray(), 0, bos.size());
os.flush();
os.close();
} catch (Exception exc) {
// TODO Gestion des exceptions
logger.error(exc);
}
} |