}
public void downloadFileAction(ActionEvent event) throws IOException {
StoredFileDao fileDao = StoredFileDao.createInstance();
StoredFile storedFile = (StoredFile) this.selectedFolder.getStoredFilesModel().getRowData();
StoredFile file2download = fileDao.retrieve(storedFile.getId());
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
//text/plain, vnd.ms-excel, application/x-download, ...
response.setContentType(file2download.getMimeType());
response.setHeader("Content-disposition","attachment; filename=\"" + file2download.getName() + "\"");
ServletOutputStream out = response.getOutputStream();
InputStream stream = file2download.getData();
int bytesRead = 0;
byte[] buffer = new byte[8192];
//Write to servlet output stream
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {