1,文件信息是存在数据库中(二进制形式),因为有视频等文件,所以不能先下载到服务器上在进行压缩处理(太大了,很可能有几个G)
2,一个案件有多个图片视频信息,用流的方式处理时,如何处理多个案件,得到的结果一个压缩包,解压后里面有多个文件夹(一个文件夹就是一个案件的相关资源),每个文件夹下有多个视频图片信息。
小弟初了解下载压缩这方面,一知半解,可能问题描述的也不是很清楚,欢迎大佬指教
3.这个方法时处理多个图片信息到一个文件夹中,入参是byte。
/**
* 将文件转为ByteArrayOutputStream后打包成zip
* @param zipOutputStream
* @param outputStreamMap Map<fileName, ByteArrayOutputStream>
*/
private void compressFileToZipStream(ZipOutputStream zipOutputStream,Map<String, byte[]> outputStreamMap) {
byte[] buf = new byte[1024];
try {
for (String key : outputStreamMap.keySet()) {
byte[] content = outputStreamMap.get(key);
ByteArrayInputStream is = new ByteArrayInputStream(content);
BufferedInputStream bis = new BufferedInputStream(is);
zipOutputStream.putNextEntry(new ZipEntry(key));
int len;
while ((len=bis.read(buf)) > 0) {
zipOutputStream.write(buf, 0, len);
}
zipOutputStream.closeEntry();
bis.close();
is.close();
}
}catch (IOException e) {
e.printStackTrace();
}finally {
if (zipOutputStream != null) {
try {
zipOutputStream.close();
}catch (IOException e) {
e.printStackTrace();
}
}
}
}