rdebusscher / AdvancedGraphicImageRenderer

Advanced PrimeFaces Graphic Image renderer for dynamic content
0 stars 6 forks source link

GraphicImageManager.RegisterImage should not close the input stream #5

Closed 99sono closed 9 years ago

99sono commented 9 years ago

Hi,

It is my impression that it is a mistake for the registerImage mechanism to be closing the InputStream. Primefaces standard implementation seems not to do it themselves. They leave the stream content instance associated to bean being rendered untouched. And for me this makes perfect sense, especially when you consider that the typical use case for a stream content is not to be holding data of a physical file system file, but only raw bytes helds in memory of an image.

I would say that the best way of managing a StreamContent on a Bean is to leave it to the application to decide what to do with it and when to close it. And even if the application never closes the input stream of the stream content then there is the following: (1) A very high likelihood that the inputstream is not related to any file system file - otherwise the application would be using a normal static resource rather than StreamContent resource. Most cases it will be in memory.

(2) Any proper implementation of an InputStream will close itself if needed during the finalize() call.

So if we leave the stream content untouched much the same way that primefaces seems to do it, that StreamContent will sooner or later get closed.

The other point is that the decision for forcefully close the input stream has bad side effects namely on my labrador sample applicaiton used to file the bug to delta spike and prime faces, If I try to render onto the UI the StreamContent labrador using both the standard implementation of graphic imaged and the advanced one, only the advanced one will suceed.

''' SNIPPET:

```





Here we could potentially have problems upon since the advanced graphic image renderer will close the StreamContent input stream. Therefore the element previewImageG will have problems upon trying to render the image the stream will be closed.








``` ''' I will modify the 1.0.1-SNAPSHOT code to not close the input stream. Many thanks.
rdebusscher commented 9 years ago

PrimeFaces does close the InputStream.

See org/primefaces/application/resource/StreamedContentHandler.java:99

Otherwise all those streams would be left open.

99sono commented 9 years ago

HI,

You are absolutely right.

This issue is incorrect.

PrimeResourceHandler

The primefaces implementation does close the input stream: if(streamedContent != null) { streamedContent.getStream().close(); }

The problem is therefore obvious there should not be two ui elements competing for the same stream.

Thanks.