Erro Stream Closed/download de arquivo com primefaces[RESOLVIDO]

6 respostas
B

Sempre que do cancelar no download, da esse erro. somento qdo cancelo, quando baixo normal nao acontecer esse erro, e algo no cancelar que tenho q tratar??

java.io.IOException: Stream Closed

at java.io.FileInputStream.readBytes(Native Method)

at java.io.FileInputStream.read(FileInputStream.java:220)

at org.primefaces.component.filedownload.FileDownloadActionListener.processAction(FileDownloadActionListener.java:71)

at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)

at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)

at javax.faces.component.UICommand.broadcast(UICommand.java:300)

at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)

at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)

at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)

at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

at java.lang.Thread.run(Thread.java:722)

6 Respostas

B

alguem??

R

poste o código de como está fazendo o download.

B
@ManagedBean(name = "fileDownloadBean")
@SessionScoped

public class FileDownloadController {  
  
    private StreamedContent file;  
      
    public FileDownloadController() throws FileNotFoundException {
        DownloadPG dDao = new DownloadPG();
        Download down = new Download();
        DownBean bean = new DownBean();

	String idArquivoUrl = "";
        String tipoArquivo = "";
	int idArquivo = 0;
        
        HttpSession s = (HttpSession) FacesContext.getCurrentInstance()
                .getExternalContext().getSession(true);
        
        try {
              idArquivoUrl = s.getAttribute("a").toString();

        } catch (Exception e) {
            
        }
          
        idArquivo = Integer.parseInt(idArquivoUrl);

//        long l = bean.getDownloadSelecionado().getIdArquivo();

        down = dDao.dadosParaDownload(idArquivo);

        //dDao.inclur(0,iduser , idArquivo, data); incluir para os downloads realizados
        
        String nome = down.getNome();
        String tipo = down.getTipo();
        String url = down.getUrl();

        if (tipo.equals("jpg") || tipo.equals("JPG") || tipo.equals("png")) {
            tipoArquivo = "image";
        } else if (tipo.equals("txt") || tipo.equals("docx") || tipo.equals("xlsx") || tipo.equals("pdf")) {
            tipoArquivo = "application";
        }

        InputStream stream = new FileInputStream(url);
        file = new DefaultStreamedContent(stream, tipoArquivo + "/" + tipo, nome + "." + tipo);
    }
  
    public StreamedContent getFile() {  
        return file;  
    } 
}
<h:form >
                 <p:dialog  modal="true" widgetVar="downloadArquivo" header="Download Arquivo" 
                           draggable="false"
                           resizable="false" width="400" showEffect="explode" hideEffect="explode">
                    <h:outputLabel value="Deseja realmente fazer o download desse arquivo" />
                    <br/><br/>#<h:outputLabel value="#{DownBean.downloadSelecionado.idArquivo}"/>#
                    
                    <p:commandButton value="Sim" onclick="PrimeFaces.monitorDownload(start, stop)"
                                     ajax="false" type="submit" >
                         <p:fileDownload value="#{fileDownloadBean.file}"  /> 
                    </p:commandButton>
                    
                    <p:commandButton value="Nao" style="margin-left: 20px"
                                     onclick="downloadArquivo.close()"/>/
  
                </p:dialog>    
            </h:form>
B

faltou isso tbm

<p:tab title="Downloads Disponiveis" id="tabDownDisp">
                        <center>
                            <h:panelGrid >
                                <p:dataTable id="tableDownDisp" var="arquivos" value="#{DownBean.listDonw}"
                                             paginator="true" rows="5" rowKey="#{arquivos.idArquivo}"
                                             selection="#{DownBean.downloadSelecionado}"
                                             selectionMode="single"
                                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}
                                             {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                             rowsPerPageTemplate="5,10">

                                    <p:column headerText="# id" style="width:185px" >
                                        <h:outputText value="#{arquivos.idArquivo}" />
                                    </p:column>

                                    <p:column headerText="Nome Do Arquivo" style="width:185px" >
                                        <h:outputText value="#{arquivos.nome}" />
                                    </p:column>

                                    <p:column headerText="Tipo" style="width:185px">
                                        <center>
                                            <h:outputText value="#{arquivos.tipo}" />
                                        </center>
                                    </p:column>

                                    <p:column headerText="Tamanho" style="width:185px">
                                        <center>
                                            <h:outputText value="#{arquivos.tamanho}" />
                                        </center>
                                    </p:column>

                                    <p:column headerText="Data de Upload" style="width:185px">
                                        <center>
                                            <h:outputText  value="#{arquivos.dataUpload}" >
                                                <f:convertDateTime  dateStyle="medium"/>
                                            </h:outputText>
                                        </center>
                                    </p:column>

                                    <p:column headerText="Compartilhado Por" style="width:185px">
                                        <center>
                                            <h:outputText value="#{arquivos.amigo}"  />
                                        </center>
                                    </p:column>


                                    <f:facet name="footer">
                                        <p:commandButton  value="Download" 
                                                          style="height: 45px;margin-left: 10px;width: 128px;"
                                                          icon="ui-icon-arrowthichk-s" 
                                                          oncomplete="downloadArquivo.show()"/>
                                    </f:facet>

                                </p:dataTable>

                            </h:panelGrid>
                        </center>

                    </p:tab>
B

entao resolvi colocando tudo que estava no construtor para o getfile, nao sei se a maneiro correta, mas funciona!!!ate o momento

A
Boa noite amigo vc teria como colocar os métodos que faltam do seu bean como :

DownloadPG dDao = new DownloadPG();

Download down = new Download();

DownBean bean = new DownBean();

dDao.dadosParaDownload(idArquivo);  ?
Criado 29 de outubro de 2012
Ultima resposta 7 de jul. de 2013
Respostas 6
Participantes 3