Commit aabd384a by songxiang

配置中心切换到GIT

parent 773e7cdc
......@@ -5,7 +5,7 @@ spring:
enabled: true
service-id: cloud-config
profile: default
label: prod
label: master
loadbalancer:
retry:
enabled: true
......
......@@ -5,7 +5,7 @@ spring:
enabled: true
service-id: cloud-config
profile: default
label: uat
label: master
loadbalancer:
retry:
enabled: true
......
......@@ -64,7 +64,8 @@ public class CompressUtils {
if (ListUtils.isEmpty(fileUrlList)) {
return null;
}
String tempZipName = FileUtils.formatName(zipName) + "_" + UUIDUitl.generateString(12);
zipName = FileUtils.formatName(zipName);
String tempZipName = zipName + "_" + UUIDUitl.generateString(12);
// 检查临时文件夹是否存在,不存在就创建
String fileFolderPath = FILE_LOCAL_PATH + tempZipName;
FileUtils.isDir(fileFolderPath);
......@@ -95,32 +96,33 @@ public class CompressUtils {
return uploadResultInfo;
}
/**
* 压缩文件(带目录)
*
* @param catalogFiles key : 目录名
* String[0]=文件名称, String[1]=文件地址
* @param catalogFiles
* key : 目录名 String[0]=文件名称, String[1]=文件地址
* @param zipName
* @return
* @throws BizException
*/
public static UploadResultInfo zipByCatalog(Map<String, List<String[]>> catalogFiles, String zipName) throws BizException {
public static UploadResultInfo zipByCatalog(Map<String, List<String[]>> catalogFiles, String zipName)
throws BizException {
LOGGER.info("【压缩】压缩文件.<START>");
if (MapUtils.isEmpty(catalogFiles)) {
return null;
}
String tempZipName = FileUtils.formatName(zipName) + "_" + UUIDUitl.generateString(12);
zipName = FileUtils.formatName(zipName);
String tempZipName = zipName + "_" + UUIDUitl.generateString(12);
String parentPath = FILE_LOCAL_PATH + tempZipName;
FileUtils.isDir(parentPath);
for(String catalog : catalogFiles.keySet()) {
for (String catalog : catalogFiles.keySet()) {
String downloadPath;
// 检查临时文件夹是否存在,不存在就创建
if(!StringUtil.isEmpty(catalog)) {
String catalogFolderPath = parentPath +"/"+ catalog;
if (!StringUtil.isEmpty(catalog)) {
String catalogFolderPath = parentPath + "/" + catalog;
FileUtils.isDir(catalogFolderPath);
downloadPath = catalogFolderPath;
}else {
} else {
downloadPath = parentPath;
}
List<String[]> fileUrlList = catalogFiles.get(catalog);
......@@ -129,8 +131,7 @@ public class CompressUtils {
for (String[] files : fileUrlList) {
String fileType = FileUtils.getFileType(files[1]);
String fileName = FileUtils.formatName(files[0]);
String downloadLocalPath = downloadPath + "/" + fileName + "_" + idx + "."
+ fileType;
String downloadLocalPath = downloadPath + "/" + fileName + "_" + idx + "." + fileType;
FileUtils.downloadFileFromUrl(files[1], downloadLocalPath);
idx++;
}
......@@ -153,7 +154,6 @@ public class CompressUtils {
return uploadResultInfo;
}
/**
* @Desc ZIP文件解压
* @param zipPath
......@@ -250,8 +250,8 @@ public class CompressUtils {
File inputFile = new File(inputFilename);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFilename));
try {
compressbyType(inputFile, out, "");
// zip(inputFile, out, "");
compress(inputFile, out);
// zip(inputFile, out, "");
} catch (Exception e) {
throw e;
} finally {
......@@ -305,21 +305,29 @@ public class CompressUtils {
* @param zos
* @param baseDir
*/
private static void compressbyType(File src, ZipOutputStream zos, String baseDir) {
private static void compress(File src, ZipOutputStream zos) {
compressbyType(src, zos, "", true);
}
/**
* 按照原路径的类型就行压缩。文件路径直接把文件压缩,
*
* @param src
* @param zos
* @param baseDir
*/
private static void compressbyType(File src, ZipOutputStream zos, String baseDir, boolean isFirst) {
if (!src.exists())
return;
// 判断文件是否是文件,如果是文件调用compressFile方法,如果是路径,则调用compressDir方法;
if (src.isFile()) {
// src是文件,调用此方法
compressFile(src, zos, baseDir);
} else if (src.isDirectory()) {
// src是文件夹,调用此方法
compressDir(src, zos, baseDir);
compressDir(src, zos, baseDir, isFirst);
}
}
/**
......@@ -345,11 +353,11 @@ public class CompressUtils {
/**
* 压缩文件夹
*/
private static void compressDir(File dir, ZipOutputStream zos, String baseDir) {
private static void compressDir(File dir, ZipOutputStream zos, String baseDir, boolean isFirst) {
if (!dir.exists())
return;
File[] files = dir.listFiles();
if (files.length == 0) {
if (files.length == 0 && !StringUtil.isEmpty(baseDir)) {
try {
zos.putNextEntry(new ZipEntry(baseDir + dir.getName() + File.separator));
} catch (IOException e) {
......@@ -357,8 +365,27 @@ public class CompressUtils {
}
}
for (File file : files) {
compressbyType(file, zos, baseDir + dir.getName()+ File.separator);
if (isFirst) {
compressbyType(file, zos, baseDir, false);
} else {
compressbyType(file, zos, baseDir + dir.getName() + File.separator, false);
}
}
}
/**
* @Desc 压缩zip文件 @param inputFilename 待压缩的文件名称或文件夹路径名称 @param zipFilename
* 压缩后的文件完整的路径名称 @throws
*/
public static void zip(String inputFilename, ZipOutputStream out) throws IOException {
File inputFile = new File(inputFilename);
try {
compress(inputFile, out);
// zip(inputFile, out, "");
} catch (Exception e) {
throw e;
} finally {
out.close();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment