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. 学习JS基本数据类型与对象的valueOf方法

    https://blog.csdn.net/licheng11403080324/article/details/60128090 https://yq.aliyun.com/articles/399 ...

  2. android中的SQLite数据库

    SQLite是android中集成的一个轻量级的数据库,该数据库支持绝大部分SQL92语法 SQLiteDatabase代表一个数据库(底层就是一个数据库文件),一旦应用程序获得了代表指定数据库的SQ ...

  3. 使用vue.js开发小程序

    写在前面 刚刚开源的mpvue引起了不少前端er们的注意,下图是一个简单的对比. 话不多说,我们现在感受一下如何使用mpvue开发小程序.(以下内容参照mpvue文档完成). 开发环境 node np ...

  4. js canvas 粒子动画 电子表

     前言 从我接触canvas的第一天就觉得canvas很有趣,想搞点事情,这几天终于忍不住了,于是他来了. 先看效果                       这里我做了四个大家有兴趣可以看完文章, ...

  5. 2018焦作网络赛-E- Jiu Yuan Wants to Eat

    题目描述 You ye Jiu yuan is the daughter of the Great GOD Emancipator.  And when she becomes an adult, s ...

  6. PHP-两数相除

    给定两个整数,被除数 dividend 和除数 divisor.将两数相除,要求不使用乘法.除法和 mod 运算符. 返回被除数 dividend 除以除数 divisor 得到的商. 示例 1: 输 ...

  7. leetcood学习笔记-14*-最长公共前缀

    笔记: python if not   判断是否为None的情况 if not x if x is None if not x is None if x is not None`是最好的写法,清晰,不 ...

  8. Windows 获取windows密码

    #include <iostream> #define Main main #define COLOR_GREEN system("color 2"); #includ ...

  9. go声明和初始化

    go声明和初始化 当我们第一次看见变量和声明时,我们仅仅看见一些内置的类型,比如整型和字符串.现在我们将学习结构体,并且我们会深入学习包括指针的内容. 通过一种最简单的方式去创建一个结构体值类型: g ...

  10. sql 聚合查询

    如果我们要统计一张表的数据量,例如,想查询students表一共有多少条记录,难道必须用SELECT * FROM students查出来然后再数一数有多少行吗? 这个方法当然可以,但是比较弱智.对于 ...