/** * Helper method to get the stream associated with the export of the file. * * @return the StreamResource associated with the export. */ private StreamResource getPayloadDownloadStream() { StreamResource.StreamSource source = new StreamResource.StreamSource() { public InputStream getStream() { ByteArrayOutputStream stream = null; try { stream = getPayloadStream(); } catch (IOException e) { logger.error(e.getMessage(), e); } InputStream input = new ByteArrayInputStream(stream.toByteArray()); return input; } }; StreamResource resource = new StreamResource ( source,"payload.txt"); return resource; }
/** * Helper method to get the stream associated with the export of the file. * * @return the StreamResource associated with the export. */ private StreamResource getComponentConfigurationExportStream() { StreamResource.StreamSource source = new StreamResource.StreamSource() { public InputStream getStream() { ByteArrayOutputStream stream = null; try { stream = getComponentConfigurationExport(); } catch (IOException e) { logger.error(e.getMessage(), e); } InputStream input = new ByteArrayInputStream(stream.toByteArray()); return input; } }; StreamResource resource = new StreamResource ( source,"componentConfigurationExport.xml"); return resource; }
/** * Helper method to get the stream associated with the export of the file. * * @return the StreamResource associated with the export. */ private StreamResource getComponentConfigurationExportStream() { StreamResource.StreamSource source = new StreamResource.StreamSource() { public InputStream getStream() { ByteArrayOutputStream stream = null; try { stream = getComponentConfigurationExport(); } catch (IOException e) { logger.error(e.getMessage(), e); } InputStream input = new ByteArrayInputStream(stream.toByteArray()); return input; } }; StreamResource resource = new StreamResource ( source,"componentConfigurationExport.xml"); return resource; }
/** * Helper method to get the stream associated with the export of the file. * * @return the StreamResource associated with the export. */ private StreamResource getFlowConfigurationExportStream(final Flow flow) { StreamResource.StreamSource source = new StreamResource.StreamSource() { public InputStream getStream() { ByteArrayOutputStream stream = null; try { stream = getFlowConfigurationExport(flow); } catch (IOException e) { logger.error(e.getMessage(), e); } InputStream input = new ByteArrayInputStream(stream.toByteArray()); return input; } }; StreamResource resource = new StreamResource ( source,"flowConfigurationExport.xml"); return resource; }
/** * Helper method to get the stream associated with the export of the file. * * @return the StreamResource associated with the export. */ private StreamResource getExcelDownloadStream() { StreamResource.StreamSource source = new StreamResource.StreamSource() { public InputStream getStream() { ByteArrayOutputStream stream = null; try { stream = getExcelStream(); } catch (IOException e) { logger.error(e.getMessage(), e); } InputStream input = new ByteArrayInputStream(stream.toByteArray()); return input; } }; StreamResource resource = new StreamResource ( source,"exclusions.csv"); return resource; }
private void init() { if (initialized) { return; } LoginFormState state = getState(); state.userNameFieldConnector = createUsernameField(); state.passwordFieldConnector = createPasswordField(); state.loginButtonConnector = createLoginButton(); StreamResource resource = new StreamResource(new LoginStreamSource(), LoginFormConstants.LOGIN_RESOURCE_NAME); resource.setMIMEType(ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8); resource.setCacheTime(-1); setResource(LoginFormConstants.LOGIN_RESOURCE_NAME, resource); registerRpc((LoginFormRpc) this::login); initialized = true; setContent(createContent(getUsernameField(), getPasswordField(), getLoginButton())); }
final ImagePojo imagePojo = new ImagePojo(); imagePojo.setName("superman"); imagePojo.setImageContent(new byte[0]); BeanItem<ImagePojo> item = new BeanItem<ImagePojo>(imagePojo); final StreamResource imageResource = new StreamResource(new StreamResource.StreamSource() { @Override public InputStream getStream() { return new ByteArrayInputStream(imagePojo.getImageContent()); } }, "myimage"); imageResource.setCacheTime(0); final Image image = new Image("Image", imageResource); addComponent(image);
@Override public void setSource(String fileName, final InputStream src) { if (src != null) { resource = new StreamResource((StreamResource.StreamSource) () -> { try { src.reset(); } catch (IOException e) { Logger log = LoggerFactory.getLogger(WebEmbedded.this.getClass()); log.debug("Ignored IOException on stream reset", e); } return src; }, fileName); component.setSource(resource); } else { resetSource(); } }
FileDownloader f = new FileDownloader(new StreamResource(null, null)) { @Override public Resource getFileDownloadResource() { tmpFileErzeuger.erzeugeXMLDatei(selectedItems); return new FileResource(tmpFileErzeuger.addToZipFile()); } }; f.extend(downloadButton);
public StreamResource getResource() { StreamSource source = new MyPdfSource((String) name.getValue()); String filename = new Random().nextInt() + "pdf_printing_example.pdf"; StreamResource resource = new StreamResource(source, filename); resource.setMIMEType("application/pdf"); resource.setCacheTime(0); resource.getStream().setParameter("Content-Disposition", "attachment; filename=" + filename); return resource; }
@Override public void setSource(String fileName, final ExportDataProvider dataProvider) { if (dataProvider != null) { resource = new StreamResource( dataProvider::provide, fileName ); component.setSource(resource); } else { resetSource(); } }
File file = new File(localFile); final FileResource fileResource = new FileResource(file); if (!file.exists()) { throw new IllegalStateException(); } final StreamResource stream = new StreamResource( new StreamSource() { @Override public InputStream getStream() { return fileResource.getStream().getStream(); } }, "newname.txt"); FileDownloader fileDownloader = new FileDownloader(stream); fileDownloader.extend(downloadButton);
@Override protected void createResource() { String name = StringUtils.isNotEmpty(fileName) ? fileName : RandomStringUtils.random(16, true, true); resource = new com.vaadin.server.StreamResource(() -> streamSupplier.get(), name); com.vaadin.server.StreamResource vStreamResource = (com.vaadin.server.StreamResource) this.resource; vStreamResource.setCacheTime(cacheTime); vStreamResource.setBufferSize(bufferSize); vStreamResource.setMIMEType(mimeType); }
protected void provideType() { switch (type) { case OBJECT: component.setType(com.vaadin.ui.Embedded.TYPE_OBJECT); break; case IMAGE: component.setType(com.vaadin.ui.Embedded.TYPE_IMAGE); break; case BROWSER: component.setType(com.vaadin.ui.Embedded.TYPE_BROWSER); if (resource == null) { component.setSource(new StreamResource(() -> { return new ByteArrayInputStream("<html></html>".getBytes(StandardCharsets.UTF_8)); }, UUID.randomUUID() + ".html")); } break; } }
@Override protected void createResource() { String name = StringUtils.isNotEmpty(fileName) ? fileName : FilenameUtils.getName(path); resource = new StreamResource(() -> AppBeans.get(Resources.class).getResourceAsStream(path), name); StreamResource streamResource = (StreamResource) this.resource; streamResource.setMIMEType(mimeType); streamResource.setCacheTime(cacheTime); streamResource.setBufferSize(bufferSize); }
Embedded image = new Embedded(); image.setMimeType("image/svg+xml"); //also unnecessary here :p layout.addComponent(image); StreamSource source = //define your source image.setSource(new StreamResource(source, "image.svg"));
{ final Button downloadButton = new Button("Download file"); final StreamResource stream = new StreamResource( new StreamSource() { @Override public InputStream getStream() { return new ByteArrayInputStream("Hola".getBytes()); } }, "badname.txt"); FileDownloader downloader = new FileDownloader(stream) { @Override public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException { stream.setFilename("better-name.txt"); return super .handleConnectorRequest(request, response, path); } }; downloader.extend(downloadButton); layout.addComponent(downloadButton); }
@Override public void resetSource() { resource = null; component.markAsDirty(); component.setMimeType("image/png"); component.setType(com.vaadin.ui.Embedded.TYPE_IMAGE); component.setSource(new StreamResource(new EmptyStreamSource(), UUID.randomUUID() + ".png")); }
@Override protected void createResource() { String name = StringUtils.isNotEmpty(fileName) ? fileName : fileDescriptor.getName(); resource = new StreamResource(() -> { try { return new ByteArrayDataProvider(AppBeans.get(FileStorageService.class).loadFile(fileDescriptor)) .provide(); } catch (FileStorageException e) { throw new RuntimeException(FILE_STORAGE_EXCEPTION_MESSAGE, e); } }, name); StreamResource streamResource = (StreamResource) this.resource; streamResource.setCacheTime(cacheTime); streamResource.setBufferSize(bufferSize); }
@Override public ImagePanel createComponent(final VisualizerInput visInput, VisualizationToggle visToggle) { final ByteArrayOutputStream out = new ByteArrayOutputStream(); writeOutput(visInput, out); String fileName = "vis_" + UUID.randomUUID().toString() + ".png"; StreamResource resource = new StreamResource(new StreamResource.StreamSource() { @Override public InputStream getStream() { return new ByteArrayInputStream(out.toByteArray()); } }, fileName); Embedded emb = new Embedded("", resource); emb.setMimeType(getContentType()); emb.setSizeUndefined(); emb.setStandby("loading image"); emb.setAlternateText("Visualization of the result"); return new ImagePanel(emb); }