|
@@ -220,46 +220,57 @@ public class ExcelUtil {
|
|
|
return cellValue;
|
|
|
}
|
|
|
|
|
|
- public static List<String> extractCompressedFiles(String zipFilePath, String destFilePath) {
|
|
|
+ public static List<String> extractCompressedFiles(String filePath, String destFilePath) {
|
|
|
List<String> filePathList = CollUtil.newArrayList();
|
|
|
try {
|
|
|
- File destFile = new File(destFilePath);
|
|
|
- if (!destFile.exists()) {
|
|
|
- destFile.mkdirs();
|
|
|
- }
|
|
|
- logger.info("开始解压==================="+zipFilePath);
|
|
|
- BufferedInputStream fis = new BufferedInputStream(new FileInputStream(zipFilePath));
|
|
|
- ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(fis);
|
|
|
- ArchiveEntry entry;
|
|
|
- while ((entry = ais.getNextEntry()) != null) {
|
|
|
- String uuid = UUID.randomUUID().toString().replaceAll("-","");
|
|
|
- String entryName = entry.getName();
|
|
|
- String fileName = null;
|
|
|
- if(entryName.contains(".")){
|
|
|
- fileName = uuid + entryName.substring(entryName.lastIndexOf("."),entryName.length());
|
|
|
- }else{
|
|
|
- fileName = uuid;
|
|
|
+ if(ExcelUtil.isZip(filePath)){
|
|
|
+ File destFile = new File(destFilePath);
|
|
|
+ if (!destFile.exists()) {
|
|
|
+ destFile.mkdirs();
|
|
|
}
|
|
|
- File entryFile = new File(destFilePath, fileName);
|
|
|
- if (entry.isDirectory()) {
|
|
|
- entryFile.mkdirs();
|
|
|
- logger.info("解压子文件:{}",entryFile.getName());
|
|
|
- } else {
|
|
|
- try {
|
|
|
- FileOutputStream fos = new FileOutputStream(entryFile);
|
|
|
- IOUtils.copy(ais, fos);
|
|
|
- filePathList.add(entryFile.getPath());
|
|
|
- logger.info("解压子文件:{}",entryFile.getPath());
|
|
|
- fos.close();
|
|
|
- }catch (Exception e){
|
|
|
- logger.error(e.getMessage(),e);
|
|
|
+ logger.info("开始解压==================="+filePath);
|
|
|
+ BufferedInputStream fis = new BufferedInputStream(new FileInputStream(filePath));
|
|
|
+ ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(fis);
|
|
|
+ ArchiveEntry entry;
|
|
|
+ while ((entry = ais.getNextEntry()) != null) {
|
|
|
+ String uuid = UUID.randomUUID().toString().replaceAll("-","");
|
|
|
+ String entryName = entry.getName();
|
|
|
+ String fileName = null;
|
|
|
+ if(entryName.contains(".")){
|
|
|
+ fileName = uuid + entryName.substring(entryName.lastIndexOf("."),entryName.length());
|
|
|
+ }else{
|
|
|
+ fileName = uuid;
|
|
|
}
|
|
|
+ File entryFile = new File(destFilePath, fileName);
|
|
|
+ if (entry.isDirectory()) {
|
|
|
+ entryFile.mkdirs();
|
|
|
+ logger.info("解压子文件:{}",entryFile.getName());
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ FileOutputStream fos = new FileOutputStream(entryFile);
|
|
|
+ IOUtils.copy(ais, fos);
|
|
|
+ filePathList.add(entryFile.getPath());
|
|
|
+ logger.info("解压子文件:{}",entryFile.getPath());
|
|
|
+ fos.close();
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ais.close();
|
|
|
+ fis.close();
|
|
|
+ }
|
|
|
+ if(ExcelUtil.isRAR(filePath)){
|
|
|
+ String destPath = filePath.replaceAll(".rar", "").replaceAll(".RAR", "");
|
|
|
+ File destFile = new File(destPath);
|
|
|
+ if (!destFile.exists()) {
|
|
|
+ destFile.mkdirs();
|
|
|
}
|
|
|
+ List<String> rarDir = ExcelUtil.extractRar(filePath, destPath);
|
|
|
+ filePathList.addAll(rarDir);
|
|
|
}
|
|
|
- ais.close();
|
|
|
- fis.close();
|
|
|
}catch (Exception e) {
|
|
|
- logger.error(zipFilePath+"======="+e.getMessage(),e);
|
|
|
+ logger.error(filePath+"======="+e.getMessage(),e);
|
|
|
}
|
|
|
logger.info("解压结束================");
|
|
|
return filePathList;
|