|
|
|
@ -48,7 +48,51 @@ public class CompressUtil {
|
|
|
|
|
if (keepDirStructure != null && keepDirStructure) {
|
|
|
|
|
zos.putNextEntry(new ZipEntry(relativePath));
|
|
|
|
|
} else {
|
|
|
|
|
zos.putNextEntry(new ZipEntry(i + "_" + relativeName));
|
|
|
|
|
zos.putNextEntry(new ZipEntry(relativeName));
|
|
|
|
|
}
|
|
|
|
|
int len;
|
|
|
|
|
while ((len = fis.read(buf)) > 0) {
|
|
|
|
|
zos.write(buf, 0, len);
|
|
|
|
|
}
|
|
|
|
|
zos.closeEntry();
|
|
|
|
|
// zos.close();
|
|
|
|
|
}
|
|
|
|
|
zos.close();
|
|
|
|
|
if (!zipFile.exists()) {
|
|
|
|
|
zipFile.createNewFile();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成zip压缩文件
|
|
|
|
|
* @param filePaths
|
|
|
|
|
* @param zipFilePath
|
|
|
|
|
* @param keepDirStructure
|
|
|
|
|
*/
|
|
|
|
|
public static void compress11(List<Map<String, String>> filePaths, String zipFilePath, Boolean keepDirStructure) {
|
|
|
|
|
byte[] buf = new byte[1024];
|
|
|
|
|
File zipFile = new File(zipFilePath);
|
|
|
|
|
try {
|
|
|
|
|
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
|
|
|
|
|
for (int i = 0; i < filePaths.size(); i++) {
|
|
|
|
|
String relativeName = filePaths.get(i).get("resource_name");
|
|
|
|
|
String relativePath = filePath+filePaths.get(i).get("url");
|
|
|
|
|
if (StringUtils.isEmpty(relativePath)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
File sourceFile = new File(relativePath);
|
|
|
|
|
if (sourceFile == null || !sourceFile.exists()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
FileInputStream fis = new FileInputStream(sourceFile);
|
|
|
|
|
if (keepDirStructure != null && keepDirStructure) {
|
|
|
|
|
zos.putNextEntry(new ZipEntry(relativePath));
|
|
|
|
|
} else {
|
|
|
|
|
zos.putNextEntry(new ZipEntry(relativeName));
|
|
|
|
|
}
|
|
|
|
|
int len;
|
|
|
|
|
while ((len = fis.read(buf)) > 0) {
|
|
|
|
|