4
I have a JSF page where I Gero a PDF and need to show it on the screen.
For that, I created a <p:media> 
It is working, but the PDF file gets stuck (never closed) and over time it ends up knocking down the Tomcat by Many files open.
I tried to close the FileInputStream at the end of the method getStream(), but this causes error -> Error in streaming dynamic resource. Stream Close
Does anyone have any suggestions?
xhtml:
<p:dialog>
   <p:media value="#{reportMB.stream}" player="pdf" cache="disable"/>
</p:dialog>
Managedbean (@Sessionscope):
public StreamedContent getStream(){
    StreamedContent content=null;
    FileInputStream fis=null;
    try{
        File pdf = new File("/meudiretorio/meuarquivo.pdf");
        fis = new FileInputStream(pdf);
        content=new DefaultStreamedContent(fis,"application/pdf","nomequalquer");
    }catch(IOException e){
    }
    return content;
}
I just tested a similar approach to the new author’s solution Bytearrayinputstream(Fileutils.readFileToByteArray(pdf)) but tmb think I’ll have a problem with memory. I will try to implement a wrapper as you suggested. Let’s see what comes ;)
– NilsonUehara