JSF and PDF’s

This is a quick snipped on transmitting a PDF in a JSF context:

byte[] bytes = getPDFStreamAsArray();
FacesContext faces = FacesContext.getCurrentInstance();
HttpServletResponse response =
(HttpServletResponse) faces.getExternalContext()
.getResponse();
response.reset();
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
response.setHeader("Content-disposition", "inline;filename="file.pdf""); // inline or attachment
response.setHeader("Cache-Control", "cache, must-revalidate");
ServletOutputStream out = response.getOutputStream();
out.write(bytes);
faces.responseComplete();