Commit aabd384a by songxiang

配置中心切换到GIT

parent 773e7cdc
...@@ -5,7 +5,7 @@ spring: ...@@ -5,7 +5,7 @@ spring:
enabled: true enabled: true
service-id: cloud-config service-id: cloud-config
profile: default profile: default
label: prod label: master
loadbalancer: loadbalancer:
retry: retry:
enabled: true enabled: true
......
...@@ -5,7 +5,7 @@ spring: ...@@ -5,7 +5,7 @@ spring:
enabled: true enabled: true
service-id: cloud-config service-id: cloud-config
profile: default profile: default
label: uat label: master
loadbalancer: loadbalancer:
retry: retry:
enabled: true enabled: true
......
...@@ -64,7 +64,8 @@ public class CompressUtils { ...@@ -64,7 +64,8 @@ public class CompressUtils {
if (ListUtils.isEmpty(fileUrlList)) { if (ListUtils.isEmpty(fileUrlList)) {
return null; 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; String fileFolderPath = FILE_LOCAL_PATH + tempZipName;
FileUtils.isDir(fileFolderPath); FileUtils.isDir(fileFolderPath);
...@@ -95,32 +96,33 @@ public class CompressUtils { ...@@ -95,32 +96,33 @@ public class CompressUtils {
return uploadResultInfo; return uploadResultInfo;
} }
/** /**
* 压缩文件(带目录) * 压缩文件(带目录)
* *
* @param catalogFiles key : 目录名 * @param catalogFiles
* String[0]=文件名称, String[1]=文件地址 * key : 目录名 String[0]=文件名称, String[1]=文件地址
* @param zipName * @param zipName
* @return * @return
* @throws BizException * @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>"); LOGGER.info("【压缩】压缩文件.<START>");
if (MapUtils.isEmpty(catalogFiles)) { if (MapUtils.isEmpty(catalogFiles)) {
return null; 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; String parentPath = FILE_LOCAL_PATH + tempZipName;
FileUtils.isDir(parentPath); FileUtils.isDir(parentPath);
for(String catalog : catalogFiles.keySet()) { for (String catalog : catalogFiles.keySet()) {
String downloadPath; String downloadPath;
// 检查临时文件夹是否存在,不存在就创建 // 检查临时文件夹是否存在,不存在就创建
if(!StringUtil.isEmpty(catalog)) { if (!StringUtil.isEmpty(catalog)) {
String catalogFolderPath = parentPath +"/"+ catalog; String catalogFolderPath = parentPath + "/" + catalog;
FileUtils.isDir(catalogFolderPath); FileUtils.isDir(catalogFolderPath);
downloadPath = catalogFolderPath; downloadPath = catalogFolderPath;
}else { } else {
downloadPath = parentPath; downloadPath = parentPath;
} }
List<String[]> fileUrlList = catalogFiles.get(catalog); List<String[]> fileUrlList = catalogFiles.get(catalog);
...@@ -129,8 +131,7 @@ public class CompressUtils { ...@@ -129,8 +131,7 @@ public class CompressUtils {
for (String[] files : fileUrlList) { for (String[] files : fileUrlList) {
String fileType = FileUtils.getFileType(files[1]); String fileType = FileUtils.getFileType(files[1]);
String fileName = FileUtils.formatName(files[0]); String fileName = FileUtils.formatName(files[0]);
String downloadLocalPath = downloadPath + "/" + fileName + "_" + idx + "." String downloadLocalPath = downloadPath + "/" + fileName + "_" + idx + "." + fileType;
+ fileType;
FileUtils.downloadFileFromUrl(files[1], downloadLocalPath); FileUtils.downloadFileFromUrl(files[1], downloadLocalPath);
idx++; idx++;
} }
...@@ -153,7 +154,6 @@ public class CompressUtils { ...@@ -153,7 +154,6 @@ public class CompressUtils {
return uploadResultInfo; return uploadResultInfo;
} }
/** /**
* @Desc ZIP文件解压 * @Desc ZIP文件解压
* @param zipPath * @param zipPath
...@@ -250,8 +250,8 @@ public class CompressUtils { ...@@ -250,8 +250,8 @@ public class CompressUtils {
File inputFile = new File(inputFilename); File inputFile = new File(inputFilename);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFilename)); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFilename));
try { try {
compressbyType(inputFile, out, ""); compress(inputFile, out);
// zip(inputFile, out, ""); // zip(inputFile, out, "");
} catch (Exception e) { } catch (Exception e) {
throw e; throw e;
} finally { } finally {
...@@ -305,21 +305,29 @@ public class CompressUtils { ...@@ -305,21 +305,29 @@ public class CompressUtils {
* @param zos * @param zos
* @param baseDir * @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()) if (!src.exists())
return; return;
// 判断文件是否是文件,如果是文件调用compressFile方法,如果是路径,则调用compressDir方法; // 判断文件是否是文件,如果是文件调用compressFile方法,如果是路径,则调用compressDir方法;
if (src.isFile()) { if (src.isFile()) {
// src是文件,调用此方法 // src是文件,调用此方法
compressFile(src, zos, baseDir); compressFile(src, zos, baseDir);
} else if (src.isDirectory()) { } else if (src.isDirectory()) {
// src是文件夹,调用此方法 // src是文件夹,调用此方法
compressDir(src, zos, baseDir); compressDir(src, zos, baseDir, isFirst);
} }
} }
/** /**
...@@ -345,11 +353,11 @@ public class CompressUtils { ...@@ -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()) if (!dir.exists())
return; return;
File[] files = dir.listFiles(); File[] files = dir.listFiles();
if (files.length == 0) { if (files.length == 0 && !StringUtil.isEmpty(baseDir)) {
try { try {
zos.putNextEntry(new ZipEntry(baseDir + dir.getName() + File.separator)); zos.putNextEntry(new ZipEntry(baseDir + dir.getName() + File.separator));
} catch (IOException e) { } catch (IOException e) {
...@@ -357,8 +365,27 @@ public class CompressUtils { ...@@ -357,8 +365,27 @@ public class CompressUtils {
} }
} }
for (File file : files) { 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