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"); } } }
file = new DefaultStreamedContent(stream, "download/csv", "FileName.csv");
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); }
graphicImage = new DefaultStreamedContent(is, "image/png"); } catch (Exception e) { e.printStackTrace();
ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { DynamicReports.report() .setTemplate(Templates.reportTemplate) .columns(stateColumn, statePorc) .title(Templates.createTitleComponent2("Tittle")) .summary( DynamicReports.cht.pie3DChart() .setTitleFont(boldFont) .seriesColorsByName(seriesColors) .setKey(stateColumn) .series( DynamicReports.cht.serie(itemColumn).setSeries(stateColumn) ) ) .pageFooter(Templates.footerComponent) .setDataSource(createDataSource4()) .toPdf(baos); InputStream inputStream = new ByteArrayInputStream(baos.toByteArray()); barStream = new DefaultStreamedContent(inputStream, "application/pdf", "example.pdf"); setBarStream(barStream); } catch (DRException e) { e.printStackTrace(); }
@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)); } } }
private StreamedContent txtFile; public void createTxt(ActionEvent actionEvent) { try { Class.forName("com.mysql.jdbc.Driver"); StringBuilder builder = new StringBuilder(); conn = DriverManager.getConnection(DB_URL, USER, PASS); stmt = conn.createStatement(); String sql = "SELECT id, name, amount FROM Employee"; ResultSet rs = stmt.executeQuery(sql); while(rs.next()){ int id = rs.getInt("id"); int age = rs.getString("name"); String first = rs.getInt("amount"); builder.append(id+"|"+age+"|"+first+"\n"); } rs.close(); String result = builder.toString(); InputStream inputStream = new ByteArrayInputStream(result.getBytes(Charset.forName("UTF-8"))); txtFile = new DefaultStreamedContent(inputStream, "application/txt", "sample.txt"); } catch (Exception e) { e.printStackTrace(); } }