Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Close StreamResource

Marc Poy
6 years ago Oct 06, 2015 9:54am
Petrus Viljoen
6 years ago Oct 13, 2015 9:27am

It should be closed by DownloadStream.writeResponse if I'm not mistaken.

It is simple to test if close is called properly though.

StreamResource pdfResource = new StreamResource(
  () -> new ByteArrayInputStream(pdfContent) {
       public void close() throws IOException {
            LOGGER.fine("StreamResource closing");
            super.close();
       }
  },
  filename
);

But as a side note, ByteArrayInputStream.close does nothing, and the ByteArrayInputStream does not hold onto any system resources(other than the original byte[]) so the garbage collector should be able to remove if safely once it is dereferenced.