JSF - File - Download!

Just for reference!
<h:commandButton value="#{text['button.download']}" 
                 action="#{bean.downloadFile(file.name)}"/>
void downloadFile(final String path) throws IOException {
    final FacesContext facesContext = FacesContext.getCurrentInstance();
    final ExternalContext externalContext = facesContext.getExternalContext();
    final File file = new File(path);
 
    externalContext.responseReset();
    externalContext.setResponseContentType("application/octet-stream");
    externalContext.setResponseContentLength(Long.valueOf(file.length()).intValue());
    externalContext.setResponseHeader("Content-Disposition", "attachment;filename=" + file.getName());
 
    final HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
    final FileInputStream input = new FileInputStream(file);
    final ServletOutputStream out = response.getOutputStream();
    byte[] buffer = new byte[1024];
 
    while ((input.read(buffer)) != -1) {
        out.write(buffer);
    }
 
    out.flush();
    facesContext.responseComplete();
}