提交 41f8a2ac 编写于 作者: tangyaolong's avatar tangyaolong

补充tar.gz压缩逻辑

上级 b28c5359
......@@ -42,7 +42,7 @@ public class DynamicModelConfigExService extends DynamicModelConfigServiceImpl {
return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1);
}
@Value("${ibiz.filePath:/app/file/}")
@Value("${ibiz.filePath:d:/app/file/}")
private String fileRoot;
@Autowired
......@@ -52,7 +52,7 @@ public class DynamicModelConfigExService extends DynamicModelConfigServiceImpl {
@Lazy
private IBZWFFeignClient wfClient;
@Value("${ibiz.dynamic.publishpath:/app/file/dynamicModel/publicpath}")
@Value("${ibiz.dynamic.publishpath:d:/app/file/dynamicModel/publicpath}")
private String publishPath;
@Autowired
......@@ -80,7 +80,13 @@ public class DynamicModelConfigExService extends DynamicModelConfigServiceImpl {
throw new BadRequestAlertException("单次只允许上传一个模型文件", "DynamicModelConfig", "unzip");
File modelFile = fileService.getFile(items.get(0).getId());
String unzipPath = modelFile.getParent().replace("ibizutil", "dynamicmodel");
FileHelper.unzip(modelFile, unzipPath, true);
if(".gz".equals(modelFile.getName().substring(modelFile.getName().lastIndexOf(".")))){
FileHelper.unTarGz(modelFile, unzipPath);
}else if(".zip".equals(modelFile.getName().substring(modelFile.getName().lastIndexOf(".")))){
FileHelper.unzip(modelFile, unzipPath, true);
}
JSONObject system = getSystem(unzipPath);
et.setSystemId(system.getString("name"));
} catch (IOException e) {
......
package cn.ibizlab.util.helper;
import cn.ibizlab.util.domain.FileItem;
import cn.ibizlab.util.errors.BadRequestAlertException;
import com.alibaba.fastjson.JSONArray;
import lombok.extern.slf4j.Slf4j;
import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarInputStream;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.*;
import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
......@@ -62,7 +70,75 @@ public class FileHelper {
}
return true;
}
public static void unTarGz(File zipFile, String descDir) throws IOException{
TarInputStream tarIn = null;
try{
tarIn = new TarInputStream(new GZIPInputStream(
new BufferedInputStream(new FileInputStream(zipFile))),
1024 * 2);
//创建输出目录
createDirectory(descDir,null);
TarEntry entry = null;
while((entry = tarIn.getNextEntry()) != null ){
if(entry.isDirectory()){
//是目录
entry.getName();
//创建空目录
createDirectory(descDir,entry.getName());
}else{
//是文件
File tmpFile = new File(descDir + "/" + entry.getName());
//创建输出目录
createDirectory(tmpFile.getParent() + "/",null);
OutputStream out = null;
try{
out = new FileOutputStream(tmpFile);
int length = 0;
byte[] b = new byte[2048];
while((length = tarIn.read(b)) != -1){
out.write(b, 0, length);
}
}catch(IOException ex){
throw ex;
}finally{
if(out!=null)
out.close();
}
}
}
}catch(IOException ex){
throw new IOException("解压归档文件出现异常",ex);
} finally{
try{
if(tarIn != null){
tarIn.close();
}
}catch(IOException ex){
throw new IOException("关闭tarFile出现异常",ex);
}
}
}
/**
* 构建目录
* @param outputDir
* @param subDir
*/
public static void createDirectory(String outputDir,String subDir) {
File file = new File(outputDir);
//子目录不为空
if (!(subDir == null || subDir.trim().equals(""))) {
file = new File(outputDir + "/" + subDir);
}
if (!file.exists()) {
if (!file.getParentFile().exists())
file.getParentFile().mkdirs();
file.mkdirs();
}
}
/**
* 复制文件夹
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册