InputStream[] inputStreamsList = new InputStream[jsonArr.size()];
String[] fileNameList = new String[jsonArr.size()];

这里是前台获取的文件信息,到fastdfs中查询出相应文件流

for(int i=0;i<jsonArr.size();i++) {
JSONObject jsonObj = (JSONObject) jsonArr.get(i);

String fileName = jsonObj.getString("filename");
String fastdir = jsonObj.getString("fastdir");
String conf_filename = this.getClass().getResource("/db.properties").getPath();
ClientGlobal.init(conf_filename);
TrackerClient tracker = null;
tracker = new TrackerClient();
TrackerServer trackerServer = null;
trackerServer = tracker.getConnection();
StorageServer storageServer = null;
StorageClient storageClient = null;
storageClient = new StorageClient(trackerServer, storageServer);
byte[] b = storageClient.download_file("group1", fastdir);

InputStream inputStream = new ByteArrayInputStream(b);
inputStreamsList[i] =inputStream;
fileNameList[i]= fileName;

}

//调用zip打包方法
public static void zip(String[] fileNameList, InputStream[] inputStream,String zipath) throws Exception {
if (fileNameList==null||fileNameList.length==0) {
throw new IllegalArgumentException("fileNameList is empty !");
}
if (fileNameList.length != inputStream.length) {
throw new IllegalArgumentException("fileNameList length is not equals to inputStream length !");
}
if(inputStream==null||inputStream.length==0) {
throw new IllegalArgumentException("inputStream is empty !");
}

ZipOutputStream zipOut = null;
try {

//创建一个空白zip
createNewzip(zipath);

File dir = new File(zipath);
OutputStream out = new FileOutputStream(dir);
zipOut = new ZipOutputStream(out);
for (int i = 0; i < fileNameList.length; i++) {
if (null == inputStream[i]) {
return;
}
try {
zipOut.putNextEntry(new ZipEntry(fileNameList[i]));
byte[] b = new byte[1024];
int len = 0;
while((len = inputStream[i].read(b)) != -1) {
zipOut.write(b,0,len);
}
zipOut.flush();
} catch (Exception e) {
e.printStackTrace();
}finally{
if(inputStream[i] != null) {
inputStream[i].close();
}
}
}
} finally {
try {
zipOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

//创建一个空白zip参考

https://www.cnblogs.com/nje19951205/p/11991395.html

利用字节流文件生成包含多文件的zip文件的更多相关文章

  1. 在Linux下查找文件内容包含某个特定字符串的文件

    如何在Linux下查找文件内容包含某个特定字符串的文件? 我的目录下面有test1和test2两个文件夹,里面都含有很多文件,其中test2里面还包含一个test文件夹 我想请问的是,如何通过查找关键 ...

  2. Python组织文件 实践:将文件的不同版本备份为ZIP文件

    功能:备份文件夹.能将文件的不同版本备份下来,并且每个有不同的名字 #! python3 # backupToZip.py - 备份文件的不同版本到压缩文件中 import zipfile,os #f ...

  3. python用zipfile模块打包文件或是目录、解压zip文件实例

    #!/usr/bin/env python # -*- coding: utf-8 -*- from zipfile import * import zipfile #解压zip文件 def unzi ...

  4. proto文件生成对应的js和ts文件

    安装protobuf 先要安装node.js,然后用npm安装protobuf npm install -g protobufjs 生成js文件 单个文件 pbjs -t static-module ...

  5. C++头文件的包含顺序研究

    一.<Google C++ 编程风格指南>里的观点 公司在推行编码规范,领导提议基本上使用<Google C++ 编程风格指南>.其中<Google C++ 编程风格指南 ...

  6. C_文件包含.h文件和包含.c文件总结

    很多人对C语言中的 “文件包含”都不陌生了,文件包含处理在程序开发中会给我们的模块化程序设计带来很大的好处,通过文件包含的方法把程序中的各个功能模块联系起来是模块化程序设计中的一种非常有利的手段. 文 ...

  7. core文件生成和路径设置

    在程序崩溃时,内核会生成一个core文件,即程序最后崩溃时的内存映像,和程序调试信息. 之后可以通过gdb,打开core文件察看程序崩溃时的堆栈信息,可以找出程序出错的代码所在文件和函数. 1.cor ...

  8. 【grpc proto】python使用proto文件生成简易的服务端和客户端

    1.安装python-grpc(注意,是grpcio包,不是grpc包!) pip install grpcio 2.编写.proto文件 grpc教程:http://doc.oschina.net/ ...

  9. 爬虫文件存储:txt文档,json文件,csv文件

    5.1 文件存储 文件存储形式可以是多种多样的,比如可以保存成 TXT 纯文本形式,也可以保存为 Json 格式.CSV 格式等,本节我们来了解下文本文件的存储方式. 5.1.1 TXT文本存储 将数 ...

随机推荐

  1. 项目案例之GitLab的数据迁移

    项目案例之GitLab的数据迁移 链接:https://pan.baidu.com/s/1CgaEv12cwfbs5RxcNpxdAg 提取码:fytm 复制这段内容后打开百度网盘手机App,操作更方 ...

  2. 洛谷P3979 遥远的国度 树链剖分+分类讨论

    题意:给出一棵树,这棵树每个点有权值,然后有3种操作.操作一:修改树根为rt,操作二:修改u到v路径上点权值为w,操作三:询问以rt为根x子树的最小权值. 解法:如果没有修改树根操作那么这题就是树链剖 ...

  3. 转译es6原生原生对象及方法,如Object.assign,Object.keys等,及promise

    下面主要为兼容恶心的ie 1,首先引入‘babel-polyfill’,可写在webpack.dev.js的entry.vendors数组里面 2,在入口文件如app.js里面import 'babe ...

  4. 每天一个Linux命令:man(0)

    man man命令是Linux下的帮助指令,通过man指令可以查看Linux中的指令帮助.配置文件帮助和编程帮助等信息. 格式 man [-adfhktwW] [section] [-M path] ...

  5. vscode开发vue项目保存时自动执行lint进行修复

    vscode下载eslint插件 vscode进行设置 找到settings.json 在里面写入如下内容进行保存 {     "eslint.autoFixOnSave": tr ...

  6. Vlan的相关知识点收纳

    Q.思科Vlan的上限个数是多少? VLAN的范围:根据平台和软件版本不同,Cisco交换机最多支持4096个VLAN.VLAN号共有4096个,0-4095    0,4095:这两个号保留,仅限系 ...

  7. Python每日一题 002

    做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)? 在此生成由数字,字母组成的20位字 ...

  8. BZOJ 3252: 攻略(思路题)

    传送门 解题思路 比较好想的一道思路题,结果有个地方没开\(long\) \(long\) \(wa\)了三次..其实就是模仿一下树链剖分,重新定义重儿子,一个点的重儿子为所有儿子中到叶节点权值最大的 ...

  9. echarts更新数据的方法

    //初始创建 var myChart = echarts.init(document.getElementById('main')); var option = {........} myChart. ...

  10. [CQOI2011]放棋子 题解(dp+组合数学)

    Description Input 输入第一行为两个整数n, m, c,即行数.列数和棋子的颜色数. 第二行包含c个正整数,即每个颜色的棋子数. 所有颜色的棋子总数保证不超过nm. N,M<=3 ...