Jsf 从服务器下载文件并以zip格式压缩

Jsf 从服务器下载文件并以zip格式压缩,jsf,primefaces,Jsf,Primefaces,我正在尝试实现一个下载所有功能,我的要求是文件应该压缩在.zip,这里是用户界面 <p:toolbar> <f:facet name="right"> <p:commandButton value="Download all photos" ajax="false" actionListener="#{ManageActivities.getAllParticipantPhoto}" onclick="PrimeFaces.monitorD

我正在尝试实现一个下载所有功能,我的要求是文件应该压缩在.zip,这里是用户界面

<p:toolbar>
    <f:facet name="right">
         <p:commandButton value="Download all photos" ajax="false" actionListener="#{ManageActivities.getAllParticipantPhoto}" onclick="PrimeFaces.monitorDownload(start, stop);" icon="ui-icon-image">
            <p:fileDownload value="#{ManageActivities.file}" /> 
      </p:commandButton>
  </f:facet></p:toolbar>
}

我可以成功地以ZIP格式下载文件,但无法解压缩,windows正在提示“无法以存档方式打开文件”错误

file = new DefaultStreamedContent(stream, "zip", "photos.zip"); 


修复了它

@Javier我添加了关闭ZipoutStream,仍然无法提取文件的功能。下载ZIP文件时可以发布HTTP响应头吗?它在所有浏览器中都失败了吗?我的问题通过这个解决方案得到了解决。谢谢:)
private byte[] zipBytes () {   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(baos);

    try{
        for(Participants p : partcpnts){
            if(p.getPhoto() != null){
                ZipEntry entry = new ZipEntry(p.getFirstName()+".jpg");
                zos.putNextEntry(entry);
                zos.write(p.getPhoto());
               }                
            }
    }catch(Exception e){
        e.printStackTrace();
    }

    return baos.toByteArray();
}
file = new DefaultStreamedContent(stream, "zip", "photos.zip"); 
file = new DefaultStreamedContent(stream, "application/zip", "photos.zip",  Charsets.UTF_8.name());