zoukankan      html  css  js  c++  java
  • 下载压缩文件并打包

    public String downloadjsglfj(){
    String id = getServletRequest().getParameter("id");
    String jsmc = getServletRequest().getParameter("jsmc");
    List<FjxxbVO> list=fjxxService.getJsglFjByFId(id,"jsglfj");
    if(list.size()>0){
    try {
    fileName= jsmc+".zip";
    this.inputStream=SftpUtils.batchDownload(list);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }else{
    return null;
    }


    return SUCCESS;
    }

    --------------------------

    public static InputStream batchDownload(List<FjxxbVO> list){
    ByteArrayOutputStream bos=new ByteArrayOutputStream();
    try{
    sftp = connect(ftpServer, ftpPort, ftpAccount, ftpPassword);
    ZipOutputStream out = new ZipOutputStream(bos);
    byte[] buf = new byte[4096];
    for (FjxxbVO fjxxbVO : list) {
    InputStream in = null;
    try {

    in=sftp.get(fjxxbVO.getLj()+"/"+fjxxbVO.getSsmc());

    out.putNextEntry(new ZipEntry(fjxxbVO.getOrgname()+"."+fjxxbVO.getWjlx()));

    int len;
    while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
    }
    out.closeEntry();
    in.close();


    } catch (Exception e) {
    e.printStackTrace();
    }

    }

    //inputStream=sftp.get(fileDir);
    out.close();
    bos.close();

    } catch (FileNotFoundException e) {
    } catch (Exception e) {
    e.printStackTrace();
    }

    return new ByteArrayInputStream(bos.toByteArray());

    }

  • 相关阅读:
    分布式服务框架的雪崩问题
    分布式系统中的幂等性
    Exception引起的性能问题
    TFS2017新特性(一)
    云平台架构变迁
    MQ基本概念
    SVN版本管理
    1年内4次架构调整,谈Nice的服务端架构变迁之路
    鏖战双十一-阿里直播平台面临的技术挑战
    统一日志平台初探
  • 原文地址:https://www.cnblogs.com/wanghongwei123/p/7154308.html
Copyright © 2011-2022 走看看