code: private static void writeOutContent(final byte[] data, final String filename, final String mime, final boolean asAttachment) {
          try {
              final HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
  
              response.setContentType(mime);
  
              if (asAttachment) response.addHeader("Content-Disposition", "attachment;filename=" + filename);
  
              response.setContentLength(data.length);
  
              final OutputStream writer = response.getOutputStream();
  
              writer.write(data);
  
              writer.flush();
              writer.close();
  
              FacesContext.getCurrentInstance().responseComplete();
          } catch (final Exception ex) {
              LOG.error("Unable to write content to HTTP Output Stream", ex);
          }
      }
docs: Used to send arbitrary to the user.
  
  @param data         The contents of the file to send
  @param filename     The name of the file. This is only useful if asAttachment
  is true
  @param mime         The MIME type of the content
  @param asAttachment If true, the file will be downloaded. If false, it is
  up to the browser to decide whether to display or download the
  file