Close StreamResource

Hi all,

maybe I’m overthinking things but I used to learn whenever I have a resoruce Input/Output I’ll do a try-finllay block to close the resource at the end.
In this case I try to display a PDF from a byte array.

For this I create a StreamResource:

StreamResource pdfResource = new StreamResource( () -> new ByteArrayInputStream(pdfContent), filename ); I now wonder where and how to close the InputStream. I don’t want to have a blocked Resource in the Memmory of the server.
Do I have to do this manualy or does the Vaadin-Framework close the given Resources once the ConnectorResource/StreamResouce is not used anymore.

I found following Documentation but that isn’t really clear on the process:

Thanks for any advice

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");

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.