Java Code Examples for com.vaadin.server.StreamResource#StreamSource
The following examples show how to use
com.vaadin.server.StreamResource#StreamSource .
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: ArtifactDetailsLayout.java From hawkbit with Eclipse Public License 1.0 | 6 votes |
private StreamResource createStreamResource(final Long id) { Optional<Artifact> artifact = this.artifactManagement.get(id); if (artifact.isPresent()) { Optional<AbstractDbArtifact> file = artifactManagement.loadArtifactBinary(artifact.get().getSha1Hash()); return new StreamResource(new StreamResource.StreamSource() { private static final long serialVersionUID = 1L; @Override public InputStream getStream() { if (file.isPresent()) { return file.get().getFileInputStream(); } return null; } }, artifact.get().getFilename()); } return null; }
Example 2
Source File: PolicyEditor.java From XACML with MIT License | 6 votes |
protected void initializeDownload() { // // Create a stream resource pointing to the file // StreamResource r = new StreamResource(new StreamResource.StreamSource() { private static final long serialVersionUID = 1L; @Override public InputStream getStream() { try { return new FileInputStream(self.file); } catch (Exception e) { logger.error("Failed to open input stream " + self.file); } return null; } }, self.file.getName()); r.setCacheTime(-1); r.setMIMEType("application/xml"); // // Extend a downloader to attach to the Export Button // FileDownloader downloader = new FileDownloader(r); downloader.extend(this.buttonExport); }
Example 3
Source File: ExternalAttachmentDownloadLink.java From cia with Apache License 2.0 | 5 votes |
@Override public void attach() { super.attach(); final StreamResource.StreamSource source = new StreamSourceImplementation(fileUrl); final StreamResource resource = new StreamResource(source, fileName); resource.getStream().setParameter("Content-Disposition", "attachment;filename=\"" + fileName + "\""); resource.setMIMEType("application/" + fileType); resource.setCacheTime(0); setResource(resource); }
Example 4
Source File: PageReadViewImpl.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
@Override protected HorizontalLayout createButtonControls() { ProjectPreviewFormControlsGenerator<Page> pagesPreviewForm = new ProjectPreviewFormControlsGenerator<>(previewForm); HorizontalLayout buttonControls = pagesPreviewForm.createButtonControls( ProjectPreviewFormControlsGenerator.ADD_BTN_PRESENTED | ProjectPreviewFormControlsGenerator.EDIT_BTN_PRESENTED | ProjectPreviewFormControlsGenerator.DELETE_BTN_PRESENTED, ProjectRolePermissionCollections.PAGES); MButton exportPdfBtn = new MButton("").withIcon(VaadinIcons.FILE_O).withStyleName(WebThemes .BUTTON_OPTION).withDescription(UserUIContext.getMessage(GenericI18Enum.BUTTON_EXPORT_PDF)); OnDemandFileDownloader fileDownloader = new OnDemandFileDownloader(new LazyStreamSource() { @Override protected StreamResource.StreamSource buildStreamSource() { return new PageReportStreamSource(beanItem); } @Override public String getFilename() { return "Document.pdf"; } }); fileDownloader.extend(exportPdfBtn); pagesPreviewForm.insertToControlBlock(exportPdfBtn); pageVersionsSelection = new PageVersionSelectionBox(); pagesPreviewForm.insertToControlBlock(pageVersionsSelection); return buttonControls; }
Example 5
Source File: ByteArrayImageResource.java From mycollab with GNU Affero General Public License v3.0 | 5 votes |
public ByteArrayImageResource(final byte[] imageData, String mimeType) { super(new StreamResource.StreamSource() { private static final long serialVersionUID = 1L; public InputStream getStream() { return new ByteArrayInputStream(imageData); } }, "avatar"); this.setMIMEType(mimeType); }
Example 6
Source File: PolicyEditor.java From XACML with MIT License | 5 votes |
protected void initializeButtons() { // // The Save button // this.buttonSave.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { self.savePolicy(); } }); // // Attach a window opener to the View XML button // BrowserWindowOpener opener = new BrowserWindowOpener(new StreamResource(new StreamResource.StreamSource() { private static final long serialVersionUID = 1L; @Override public InputStream getStream() { try { if (logger.isDebugEnabled()) { logger.debug("Setting view xml button to: " + self.file.getAbsolutePath()); } return new FileInputStream(self.file); } catch (Exception e) { logger.error("Failed to open input stream " + self.file); } return null; } }, self.file.getName())); opener.setWindowName("_new"); opener.extend(this.buttonViewXML); }