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())); }
/** * Creates a new stream resource for downloading from stream. * * @param streamSource * the source Stream. * @param filename * the name of the file. */ public StreamResource(StreamSource streamSource, String filename) { setFilename(filename); setStreamSource(streamSource); }
@Override public int hashCode() { return Arrays.hashCode(new Object[] { getStreamSource(), mimeType, getFilename(), getBufferSize(), getCacheTime() }); }
/** * 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; }
@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); }
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; }
new StreamResource(source, filename); resource.setMIMEType("application/pdf"); resource.getStream().setParameter( "Content-Disposition", "attachment; filename="+filename);
/** * Returns the {@link DownloadStream} instance. * Unlike the method of the superclass, this one doesn't create a new instance if it is already existing. */ @Override public DownloadStream getStream() { if (downloadStream == null) { downloadStream = super.getStream(); } return downloadStream; }
@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); }
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);
StreamResource resource = new StreamResource(dataProvider::provide, resourceName); resource.setMIMEType(exportFormat.getContentType()); } else { resource.setMIMEType(FileTypesHelper.getMIMEType(resourceName));
@Override public void setMimeType(String mimeType) { this.mimeType = mimeType; if (resource != null) { ((StreamResource) resource).setMIMEType(mimeType); } }
{ 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 setCacheTime(long cacheTime) { this.cacheTime = cacheTime; if (resource != null) { ((StreamResource) resource).setCacheTime(cacheTime); } }
ServletContext context = ((VaadinServletRequest) request) .getServletContext(); response.setContentType(streamResource.getContentTypeResolver() .apply(streamResource, context)); response.setCacheTime(streamResource.getCacheTime()); writer = streamResource.getWriter(); if (writer == null) { throw new IOException(
@Override public void setFileName(String fileName) { this.fileName = fileName; if (resource != null) { ((StreamResource) resource).setFilename(fileName); } }
public String getMimeType() { return streamResource.getMIMEType(); }
@Override public TempFileStreamSource getStreamSource() { return (TempFileStreamSource) super.getStreamSource(); }
/** * 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; }
@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); }