org.primefaces.model.DefaultStreamedContent Java Examples

The following examples show how to use org.primefaces.model.DefaultStreamedContent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvestmentSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void linechartBase64Str(){
	 InputStream stream2 = servletContext.getResourceAsStream("/images/line.png");
	 file = new DefaultStreamedContent(stream2, "image/png", "LineChart.png");
	
    if(base64Str.split(",").length > 1){
        String encoded = base64Str.split(",")[1];
        byte[] decoded = Base64.decodeBase64(encoded);
        // Write to a .png file
        try {
            RenderedImage renderedImage = ImageIO.read(new ByteArrayInputStream(decoded));
            ImageIO.write(renderedImage, "png", new File(servletContext.getRealPath("images/line.png"))); 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example #2
Source File: WorkbookService.java    From Html5_Spreadsheet_Editor_by_Aspose.Cells_for_Java with MIT License 6 votes vote down vote up
public StreamedContent getOutputFile(int saveFormat) {
    if (!isLoaded()) {
        return null;
    }

    byte[] buf;
    String ext = getExtensionForSaveFormat(saveFormat);

    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        getAsposeWorkbook().save(out, saveFormat);
        buf = out.toByteArray();
    } catch (Exception x) {
        LOGGER.throwing(null, null, x);
        msg.sendMessageDialog("Could not export", x.getMessage());
        return null;
    }

    return new DefaultStreamedContent(new ByteArrayInputStream(buf), "application/octet-stream", "Spreadsheet." + ext);
}
 
Example #3
Source File: AccountSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void piechartUSBase64Str(){
	 
	 InputStream stream1 = servletContext.getResourceAsStream("/images/pie1.png");
	 file1 = new DefaultStreamedContent(stream1, "image/png", "US_Piechart.png");
    if(base64Str1.split(",").length > 1){
        String encoded = base64Str1.split(",")[1];
        byte[] decoded = Base64.decodeBase64(encoded);
        // Write to a .png file
        try {
            RenderedImage renderedImage = ImageIO.read(new ByteArrayInputStream(decoded));
            ImageIO.write(renderedImage, "png", new File(servletContext.getRealPath("images/pie1.png"))); 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
   
}
 
Example #4
Source File: TransactionSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void donutchartBase64Str(){
	 InputStream stream = servletContext.getResourceAsStream("/images/donut.png");
	 file = new DefaultStreamedContent(stream, "image/png", "DonutChart.png");
	
    if(base64Str.split(",").length > 1){
        String encoded = base64Str.split(",")[1];
        byte[] decoded = Base64.decodeBase64(encoded);
        // Write to a .png file
        try {
            RenderedImage renderedImage = ImageIO.read(new ByteArrayInputStream(decoded));
            ImageIO.write(renderedImage, "png", new File(servletContext.getRealPath("images/donut.png"))); 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example #5
Source File: NetDumperBean.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
public StreamedContent downloadFile(File file) {

		if (!file.exists()) {
			logger.info("File {} does not exist", file.getPath());
			BeanUtil.addErrorMessage("File does not exist", "");
			return null;
		}
		
		try {

            InputStream stream = new BufferedInputStream(new FileInputStream(file));

			return new DefaultStreamedContent(stream, "*/*", file.getName());

        } catch (IOException e) {
			logger.error(e.getMessage(), e);
			BeanUtil.addErrorMessage("Download failed", e.getMessage());
		}
		
		return null;
	}
 
Example #6
Source File: ToolsBean.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
public StreamedContent getConverted() {

        try {
            File outputFile = Files.createTempFile("merged", ".csv").toFile();
            MergeMatrix.mergeMatrix(outputFile, uploadedFiles);
            for (File matrixFile: uploadedFiles) {
                matrixFile.delete();
            }
            uploadedFiles.clear();

            return new DefaultStreamedContent(new FileInputStream(outputFile), ContentType.DEFAULT_BINARY.toString(), outputFile.getName());
        } catch (Exception e) {
            logger.info(e.getMessage(), e);
            BeanUtil.showMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), ExceptionUtils.getStackTrace(e));
            return null;
        }
    }
 
Example #7
Source File: AccountSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void piechartUKBase64Str(){
	 InputStream stream2 = servletContext.getResourceAsStream("/images/pie2.png");
	 file2 = new DefaultStreamedContent(stream2, "image/png", "Uk_Piechart.png");
	
    if(base64Str2.split(",").length > 1){
        String encoded = base64Str2.split(",")[1];
        byte[] decoded = Base64.decodeBase64(encoded);
        // Write to a .png file
        try {
            RenderedImage renderedImage = ImageIO.read(new ByteArrayInputStream(decoded));
            ImageIO.write(renderedImage, "png", new File(servletContext.getRealPath("images/pie2.png"))); 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example #8
Source File: AccountSummaryController.java    From primefaces-blueprints with The Unlicense 6 votes vote down vote up
public void barchartBase64Str(){
	 InputStream stream2 = servletContext.getResourceAsStream("/images/bar.png");
	 file3 = new DefaultStreamedContent(stream2, "image/png", "BarChart.png");
	
    if(base64Str3.split(",").length > 1){
        String encoded = base64Str3.split(",")[1];
        byte[] decoded = Base64.decodeBase64(encoded);
        // Write to a .png file
        try {
            RenderedImage renderedImage = ImageIO.read(new ByteArrayInputStream(decoded));
            ImageIO.write(renderedImage, "png", new File(servletContext.getRealPath("images/bar.png"))); 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example #9
Source File: SessionScopeBean.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
public synchronized StreamedContent getImage() {
	FacesContext context = FacesContext.getCurrentInstance();
	if (PhaseId.RENDER_RESPONSE.equals(context.getCurrentPhaseId())) {
		// So, we're rendering the view. Return a stub StreamedContent so that it will generate right URL.
		return new DefaultStreamedContent();
	} else {
		// So, browser is requesting the image. Return a real StreamedContent with the image bytes.
		String uuid = WebUtil.getParamValue(GetParamNames.UUID);
		if (imageStore.containsKey(uuid)) {
			return imageStore.get(uuid);
		}
		return new DefaultStreamedContent();
	}
}
 
Example #10
Source File: FileDownloadController.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public void downLoadFile(ModelTemplate mt, String mapKey) {
    if (mt != null) {
        System.out.println("mt id  " + mt.getId() + " mt comment " + mt.getComment() + "mapkey " + mapKey);
        byte[] fileMap = mt.getData(mapKey);
        ByteArrayInputStream bis = new ByteArrayInputStream(fileMap);
        file = new DefaultStreamedContent(bis, "text/plain", mapKey + ".txt");

    } else {
        System.out.println("mt is null ");

    }


}
 
Example #11
Source File: FileDownloadController.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public FileDownloadController() {
    System.out.println("fileDowloadController");
    InputStream stream = ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext()).getResourceAsStream("/modelTemplateContainer/test.jpg");
    file = new DefaultStreamedContent(stream, "image/jpg", "test.jpg");
}
 
Example #12
Source File: ModelTemplateContainerController.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public void downLoadFile(ModelTemplate mt, String mapKey) {
    if (mt != null) {
        System.out.println("mt id  " + mt.getId() + " mt comment " + mt.getComment() + "mapkey " + mapKey);
        byte[] fileMap = mt.getData(mapKey);
        ByteArrayInputStream bis = new ByteArrayInputStream(fileMap);
        fileData = new DefaultStreamedContent(bis, "text/plain", mapKey + ".txt");

    } else {
        System.out.println("mt is null ");

    }
}
 
Example #13
Source File: TestScriptsBean.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public StreamedContent getMatrixInZip() {
	logger.debug("getMatrixInZip invoked {}", BeanUtil.getUser());
	try {
		InputStream stream = new FileInputStream(packZip());
		return new DefaultStreamedContent(stream, "application/zip", "matrix.zip");
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		BeanUtil.showMessage(FacesMessage.SEVERITY_ERROR, "Error", e.getMessage());
	}

	return null;

}
 
Example #14
Source File: SessionScopeBean.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
public synchronized StreamedContent putImage(Object key, byte[] image, String mimeType) {
	if (image != null && image.length > 0 && mimeType != null && mimeType.length() > 0) {
		return imageStore.put(key, new DefaultStreamedContent(new ByteArrayInputStream(image), mimeType));
	} else {
		return imageStore.remove(key);
	}
}
 
Example #15
Source File: EnvironmentBean.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public StreamedContent getServicesInZip() {
	logger.info("getServicesInZip invoked {}", getUser());

	try {
		InputStream stream = new FileInputStream(BeanUtil.getSfContext().getServiceMarshalManager().packInZip(exportServices()));
		return new DefaultStreamedContent(stream, "application/zip", "Services.zip");
	} catch (FileNotFoundException e) {
		logger.error(e.getMessage(), e);
	}
	return null;
}
 
Example #16
Source File: MessagesBean.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public StreamedContent getResultsInCSV() {
logger.info("getResultsInCSV invoked {}", getUser());

      if(selectedOptions.isEmpty() && !includeRawMessage) {
          BeanUtil.addWarningMessage("No columns selected", "Select at least one column");
          return null;
      }

      if(messageLazyModel.getRowCount() != 0) {
	try {
              String fileNameCsv = "query_result_" + UUID.randomUUID();
		File temp = File.createTempFile(fileNameCsv, ".csv");
		CsvMessageWriter writer = new CsvMessageWriter(selectedOptions, includeRawMessage);
              writer.writeAndClose(temp, messageLazyModel.load(0, messageLazyModel.getRowCount()));

		File zipFile = new File(temp.getParent(), "messages.zip");
		AppZip appZip = new AppZip();
		appZip.generateFileList(temp);
		appZip.zipIt(zipFile.getAbsoluteFile().toString());

		InputStream stream = new FileInputStream(zipFile);
		return new DefaultStreamedContent(stream, "application/zip", "Messages.zip");
	} catch (IOException e) {
		logger.error("Could not export messages", e);
		BeanUtil.addErrorMessage("Could not export messages", e.getMessage());
		return null;
	}
  	} else {
	BeanUtil.addWarningMessage("No data to export", "Table messages is empty");
}
  	return null;
  }
 
Example #17
Source File: FileAdapter.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public StreamedContent getStrContent()
{
       if(!file.exists()) {
           return null;
       }

	try {
		InputStream stream = new BufferedInputStream(new FileInputStream(file));
		return new DefaultStreamedContent(stream, "*/*", file.getName());
	}
	catch(IOException e) {
		logger.error(e.getMessage(), e);
	}
	return null;
}
 
Example #18
Source File: JobBean.java    From ctsms with GNU Lesser General Public License v2.1 4 votes vote down vote up
public StreamedContent getFileStreamedContent() throws Exception {
	if (isHasFile()) {
		return new DefaultStreamedContent(new ByteArrayInputStream(in.getDatas()), in.getMimeType(), in.getFileName());
	}
	return null;
}
 
Example #19
Source File: JobInstanceControler.java    From jqm with Apache License 2.0 4 votes vote down vote up
public StreamedContent getFile()
{
    InputStream is = JqmClientFactory.getClient().getDeliverableContent(selDel);
    return new DefaultStreamedContent(is, null, selected.getId() + " - " + selDel.getOriginalName());
}
 
Example #20
Source File: JobInstanceControler.java    From jqm with Apache License 2.0 4 votes vote down vote up
public StreamedContent getSelOut()
{
    InputStream is = JqmClientFactory.getClient().getJobLogStdOut(this.selected.getId());
    return new DefaultStreamedContent(is, "text/plain;charset=utf-8", selected.getId() + ".stdout.txt");
}
 
Example #21
Source File: JobInstanceControler.java    From jqm with Apache License 2.0 4 votes vote down vote up
public StreamedContent getSelErr()
{
    InputStream is = JqmClientFactory.getClient().getJobLogStdErr(this.selected.getId());
    return new DefaultStreamedContent(is, "text/plain;charset=utf-8", selected.getId() + ".stderr.txt");
}
 
Example #22
Source File: InputFieldBean.java    From ctsms with GNU Lesser General Public License v2.1 4 votes vote down vote up
public StreamedContent getFileStreamedContent() throws Exception {
	if (isHasImage()) {
		return new DefaultStreamedContent(new ByteArrayInputStream(in.getDatas()), in.getMimeType(), in.getFileName());
	}
	return null;
}
 
Example #23
Source File: MassMailRecipientBeanBase.java    From ctsms with GNU Lesser General Public License v2.1 4 votes vote down vote up
public StreamedContent getEmailAttachmentStreamedContent(EmailAttachmentVO attachment) throws Exception {
	if (attachment != null) {
		return new DefaultStreamedContent(new ByteArrayInputStream(attachment.getDatas()), attachment.getContentType().getMimeType(), attachment.getFileName());
	}
	return null;
}
 
Example #24
Source File: PhotoBeanBase.java    From ctsms with GNU Lesser General Public License v2.1 4 votes vote down vote up
public StreamedContent getFileStreamedContent() throws Exception {
	if (isHasPhoto()) {
		return new DefaultStreamedContent(new ByteArrayInputStream(getData()), getMimeType(), getFileName());
	}
	return null;
}
 
Example #25
Source File: FlightRecorderBean.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
public StreamedContent downloadFile(RecordedFile file) {
	
	File fsFile = new File(file.getPath());
	
	try {
		
		if(!fsFile.exists()) {
			logger.warn("File {} doesn't exists!", file.getPath());
			BeanUtil.addErrorMessage("File does not exists!", "");
			return null;
		}
		
		InputStream stream = new BufferedInputStream (new FileInputStream(fsFile) );
		
		return new DefaultStreamedContent(stream, "*/*", file.getName());
		
	} catch(IOException e) {
		logger.error(e.getMessage(), e);
		BeanUtil.addErrorMessage("Download failed", e.getMessage());
	}
	
	return null;
	
}
 
Example #26
Source File: BigButtonBean.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
public StreamedContent getReportFile() {

        try {

            return new DefaultStreamedContent(new FileInputStream(progressView.getReportFile()),
					"text/csv",
					"SF_Big_Button_results.csv");

		} catch (FileNotFoundException e) {

			logger.error(e.getMessage(), e);
			return null;

		}

    }
 
Example #27
Source File: DictionaryEditorModel.java    From sailfish-core with Apache License 2.0 3 votes vote down vote up
private StreamedContent getNewFile() throws IOException {

        try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
            XmlDictionaryStructureWriter.write(dict, output);

            byte[] bytes = output.toByteArray();

            InputStream input = new ByteArrayInputStream(bytes);

            return new DefaultStreamedContent(input, "application/force-download", selectedFileContainer.getFileName());
        }
    }
 
Example #28
Source File: DownloadBean.java    From sailfish-core with Apache License 2.0 3 votes vote down vote up
public StreamedContent getZipContent() {
	logger.info("getZipContent invoked {}", getUser());

       try {
		
		String absoluteWebPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/");
		File zipFile = new File(absoluteWebPath, ZIP_NAME);
		
		if (zipFile.exists()) {
			zipFile.delete();
		}
	
		AppZip appZip = new AppZip();

           for(FileAdapter fa : selectedFiles) {
			appZip.generateFileList(fa.getFile());
		}
		
		appZip.zipIt(zipFile.getAbsoluteFile().toString());
		
		FileInputStream in = new FileInputStream(zipFile);

           return new DefaultStreamedContent(in, "application/zip", ZIP_NAME);
		
	} catch (IOException e) {
		logger.error("Zip Downloading Error", e.getMessage(), e);
	}

       return null;
}