public DefaultStreamedContent byteToImage(byte[] imgBytes) throws IOException { ByteArrayInputStream img = new ByteArrayInputStream(imgBytes); return new DefaultStreamedContent(img,"image/jpg"); }
public void getImage(ExpenseTO to) { ExpenseTO fetchEntityById = accountService.fetchEntityById( ExpenseTO.class, to.getExpenseId()); byte[] fileScanned = fetchEntityById.getUploadedScanedFile(); if (fileScanned.length <= 20) { outPutPdfToDisplay=null; } else { outPutPdfToDisplay = new DefaultStreamedContent( new ByteArrayInputStream(fileScanned)); } }
@ManagedBean(name="fileDownloadController", eager = true) @ViewScoped public class FileDownloadController implements Serializable{ public StreamedContent generateFile(String fileName) { InputStream stream = null; try { stream = new FileInputStream("D:/myFileDir/"+fileName); } catch (FileNotFoundException ex) { } return new DefaultStreamedContent(stream, "image/jpg", fileName); }
@Named public class ImageBean { private StreamedContent image; @PostConstruct public void init() { image = new DefaultStreamedContent(new ByteArrayInputStream(byteArray)); // your byte array } // setter and getter for image omitted }
public StreamedContent getFile() { InputStream stream = new ByteArrayInputStream( mytext.getBytes() ); StreamedContent file = new DefaultStreamedContent(stream, "xml", "yourfile.xml"); return file; } public String getMytext() { return mytext; } public void setMytext(String mytext) { this.mytext = mytext; }
public DefaultStreamedContent getContent(){ FacesContext context = FacesContext.getCurrentInstance(); if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) { return new DefaultStreamedContent(); }else{ if (img == null){ return new DefaultStreamedContent(); }else{ return new DefaultStreamedContent(new ByteArrayInputStream(img), "image/png"); } } }
return new DefaultStreamedContent(new ByteArrayInputStream(dr.getImage()),"image/svg+xml");
public StreamedContent getFileStreamedContent() { try { InputStream is = new BufferedInputStream( new FileInputStream("/your/file/path/fileXYZ.jpg")); return new DefaultStreamedContent(is, "image/jpeg", "fileXYZ.jpg"); } catch (FileNotFoundException e) { } }
InputStream is = new ByteArrayInputStream((byte[]) yourBlobData); myImage = new DefaultStreamedContent(is, "image/png");
return new DefaultStreamedContent(new ByteArrayInputStream(u.getPhoto()));
public StreamedContent getImage() { FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest myRequest = (HttpServletRequest) context.getExternalContext().getRequest(); String imageID = (String) myRequest.getParameter("imageID"); return new DefaultStreamedContent(new ByteArrayInputStream(themeFacade.find(Long.parseLong(imageID)).getImage())); }
try { ThermometerPlot plot = new ThermometerPlot(createThermometerDataset()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JFreeChart chart = new JFreeChart(plot); ChartUtilities.writeChartAsPNG(baos, chart, 50, 50); thermoChart = new DefaultStreamedContent( new ByteArrayInputStream(baos.toByteArray()), "image/png"); } catch (Exception e) { logger.severe(e.getMessage()); }
@ManagedBean public class ImageBean { private StreamedContent leftImage; private StreamedContent rightImage; public ImageBean() { InputStream stream1 = this.getClass().getResourceAsStream("lara-ps3.jpg"); //or something else leftImage = new DefaultStreamedContent(stream1, "image/jpeg"); InputStream stream2 = this.getClass().getResourceAsStream("lara-ps4.jpg"); //or something else rightImage = new DefaultStreamedContent(stream2, "image/jpeg"); } public StreamedContent getLeftImage() { return this.leftImage; } public StreamedContent getRightImage() { return this.rightImage; } }
public void prepareToDownload(ActionEvent actionEvent){ String fileName = (String)actionEvent.getComponent().getAttributes().get("fileName"); InputStream stream = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/tmp/" + fileName); file = new DefaultStreamedContent(stream, "text/plain", fileName); }
@Named @ApplicationScoped public class Bean { private byte[] imageLoadedFromDatabase; // code to set (or load) image from database ... public StreamedContent getImage() { if (FacesContext.getCurrentInstance().getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) { return new DefaultStreamedContent(); } else { return new ByteArrayContent(imageLoadedFromDatabase); } } }
public StreamedContent getAgencyPhoto() throws IOException { FacesContext context = FacesContext.getCurrentInstance(); if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) { return new DefaultStreamedContent(); } else { String agencyId = context.getExternalContext() .getRequestParameterMap().get("agencyId"); TAgency currentAgency = new TAgency(); for (TAgency currAgency : agencyList) { if (currAgency.gettUserId() == Long.valueOf(agencyId)) currentAgency = currAgency; } byte[] image = (byte[]) currentAgency.gettUser().getPhoto(); if (image == null) { return new DefaultStreamedContent(); } else { return new DefaultStreamedContent(new ByteArrayInputStream( image)); } } }
public StreamedContent exportPdf(String name) throws JRException, IOException { DynamicReport dynamicReport = dynamicReportBuilder.build(); File arquivoPdfGeracao = File.createTempFile(name, ".pdf"); String path = arquivoPdfGeracao.getPath().substring(0, arquivoPdfGeracao.getPath().indexOf(arquivoPdfGeracao.getName())); JRFileVirtualizer virtualizer = new JRFileVirtualizer(5, path); parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer); JRDataSource ds = new JRBeanCollectionDataSource(listData); JasperPrint jasperPrint = DynamicJasperHelper.generateJasperPrint(dynamicReport, new ClassicLayoutManager(), ds, parameters); InputStream pdfStream = new FileInputStream(arquivoPdfGeracao.getAbsolutePath()); JasperExportManager.exportReportToPdfFile(jasperPrint, arquivoPdfGeracao.getAbsolutePath()); return new DefaultStreamedContent(pdfStream, "application/pdf", name + ".pdf"); }
private StreamedContent fileDownload; public void createPDF() { try { Document pdf = new Document(PageSize.LETTER); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer; writer = PdfWriter.getInstance(pdf, baos); if (!pdf.isOpen()) { pdf.open(); } //Adding content to pdf pdf.close(); String fileName = "factura No " + this.selectedFactura.getNoFactura(); InputStream stream = new ByteArrayInputStream(baos.toByteArray()); fileDownload = new DefaultStreamedContent(stream, "application/pdf", fileName); } catch (Exception e) { JsfUtil.addErrorMessage(e, "Error: createPDF() " + e.getMessage()); } }
@Override public StreamedContent exportExcel(Collection<?> listData, ColumnsList columnsList) { try (ByteArrayOutputStream fos = new ByteArrayOutputStream()) { List<Map<String, Object>> listaRegistro = montaListaRegistro(listData, columnsList); ExcelUtils.generate("Listagem", "lista", listaRegistro, fos); InputStream inputStream = new ByteArrayInputStream(fos.toByteArray()); return new DefaultStreamedContent(inputStream, FileType.DOC.getContentType(), "lista.xlsx"); } catch (Exception ex) { LogUtils.generate(ex); } return null; }
public void upload() throws IOException { if (this.uploadedFile != null) { this.downloadFile = new DefaultStreamedContent(this.uploadedFile.getInputstream(), this.uploadedFile.getContentType(), this.uploadedFile.getFileName()); } } }