I have a view, from which the user can first generate a PDF depending on some parameters, and then download and/or send it via mail.
Now, the method for generating the PDF file returns an InputStream, which I then store as field of the class, like this:
public class PDFWindow extends VerticalLayout { ... private InputStream pdfInputStream; ... private void createPDF() { this.pdfInputStream = pdfCreator.createPDF(); } My problem is, that the pdfInputStream is closed after it is consumed by the FileDownloader:
Button download = new Button("Download"); final FileDownloader fileDownloader = new FileDownloader( new StreamResource(() -> this.pdfInputStream, this.pdfFileName)); fileDownloader.extend(download); or the SpringEmailService I wrote:
SpringEmailService.send( "[email protected]", recipients, this.subject.getValue(), this.message.getValue(),this.pdfInputStream,"test.pdf", "application/pdf"); Is there any way, to stop the InputStream from being closed and then closing it manual, or should I look for a completely different way?