I have a JSF page where I generate a PDF and need to show it on the screen.
For this, I created a <p:media>
It's working, but the PDF file gets stuck (it's never closed) and over time it ends up dropping Tomcat by Many files open
.
I have already tried to close FileInputStream
at the end of the getStream()
method, 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;
}