Browse Source

获取文件md5没有关闭输入流

wukai 1 year ago
parent
commit
1ad8abf6f7

+ 1 - 1
sync-admin/src/main/java/com/jjt/RuoYiApplication.java

@@ -23,4 +23,4 @@ public class RuoYiApplication {
                 "╚█████╔╝    ╚█████╔╝       ██║   \n" +
                 " ╚════╝      ╚════╝        ╚═╝   ");
     }
-}
+}

+ 2 - 2
sync-admin/src/main/resources/application-dev.yml

@@ -6,7 +6,7 @@ spring:
     druid:
       # 主库数据源
       master:
-        url: jdbc:mysql://192.168.188.62:3306/xjsync?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+        url: jdbc:mysql://192.168.188.60:3306/xjsync?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
         username: root
         password: 123456
       # 从库数据源
@@ -58,4 +58,4 @@ spring:
           merge-sql: true
         wall:
           config:
-            multi-statement-allow: true
+            multi-statement-allow: true

+ 45 - 0
sync-common/src/main/java/com/jjt/common/utils/GenerateJsonFile.java

@@ -0,0 +1,45 @@
+package com.jjt.common.utils;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.jjt.common.domain.FileDesc;
+import com.jjt.common.enums.SyncType;
+import org.apache.commons.codec.digest.DigestUtils;
+
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+/**
+ * 生成json描述文件
+ *
+ * @author wukai
+ */
+public class GenerateJsonFile {
+    /**
+     * 生成json描述文件
+     *
+     * @param target   目标文件
+     * @param fileName 生成的文件名
+     * @param name     目标文件名称
+     * @param syncType 同步类型
+     */
+    public static void generate(Path target, String fileName, String name, SyncType syncType) {
+        try (InputStream is = Files.newInputStream(target); FileOutputStream os = new FileOutputStream(fileName)) {
+            //主要是为了关闭文件流,大坑
+            String md5 = DigestUtils.md5Hex(is);
+            //组装json对象
+            FileDesc desc = new FileDesc();
+            desc.setName(name);
+            desc.setMd5(md5);
+            desc.setType(syncType);
+            //写入文件
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.writeValue(os, desc);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+}

+ 43 - 107
sync-common/src/main/java/com/jjt/common/utils/LinuxCommand.java

@@ -4,8 +4,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.*;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * Linux命令执行工具
@@ -22,21 +25,8 @@ public class LinuxCommand {
      */
     public static void exec(String cmd) throws Exception {
         Process process = Runtime.getRuntime().exec(cmd);
-        try {
-            log.info("要执行命令了哟:{}", cmd);
-            print(process);
-
-            int code = process.waitFor();
-            log.info("{}命令,执行状态{}", cmd, code);
-
-            if (code != 0) {
-                throw new Exception("执行命令出错啦!" + cmd);
-            }
-        } catch (Exception e) {
-            throw e;
-        } finally {
-            process.destroy();
-        }
+        log.info("要执行命令了哟:{}", cmd);
+        handleProcess(process);
     }
 
     /**
@@ -46,21 +36,8 @@ public class LinuxCommand {
      */
     public static void exec(String[] cmd) throws Exception {
         Process process = Runtime.getRuntime().exec(cmd);
-        try {
-            log.info("要执行命令了哟:{}", Arrays.toString(cmd));
-            print(process);
-
-            int code = process.waitFor();
-            log.info("{}命令,执行状态{}", cmd, code);
-
-            if (code != 0) {
-                throw new Exception("执行命令出错啦!" + cmd);
-            }
-        } catch (Exception e) {
-            throw e;
-        } finally {
-            process.destroy();
-        }
+        log.info("要执行命令了哟:{}", Arrays.toString(cmd));
+        handleProcess(process);
     }
 
 
@@ -79,18 +56,8 @@ public class LinuxCommand {
         processBuilder.redirectOutput(new File(path));
 
         Process process = processBuilder.start();
-        try {
-            print(process);
-            int code = process.waitFor();
-            log.info("mysql备份执行状态:{}", code);
-            if (code != 0) {
-                throw new Exception("执行mysql备份命令出错啦!");
-            }
-        } catch (Exception e) {
-            throw e;
-        } finally {
-            process.destroy();
-        }
+
+        handleProcess(process);
     }
 
     /**
@@ -103,19 +70,7 @@ public class LinuxCommand {
         log.info("要执行命令了哟:{}", Arrays.toString(commands.toArray()));
         ProcessBuilder processBuilder = new ProcessBuilder(commands);
         Process process = processBuilder.start();
-        try {
-            print(process);
-
-            int code = process.waitFor();
-            log.info("命令执行状态:{}", code);
-            if (code != 0) {
-                throw new Exception("执行命令出错啦!");
-            }
-        } catch (Exception e) {
-            throw e;
-        } finally {
-            process.destroy();
-        }
+        handleProcess(process);
     }
 
     /**
@@ -132,68 +87,49 @@ public class LinuxCommand {
         processBuilder.directory(new File(dir));
 
         Process process = processBuilder.start();
-        try {
-            print(process);
-            int code = process.waitFor();
-            log.info("脚本执行状态:{}", code);
-            if (code != 0) {
-                throw new Exception("执行脚本出错啦!");
+        handleProcess(process);
+    }
+
+    private static void handleProcess(Process process) throws Exception {
+        try (InputStream inputStream = process.getInputStream();
+             OutputStream outputStream = process.getOutputStream();
+             PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)), true);
+             InputStream errorStream = process.getErrorStream()) {
+            pw.println("exit");
+            // 异步读取子进程的标准输出和错误输出
+            ExecutorService executor = Executors.newFixedThreadPool(2);
+            executor.submit(() -> readAndLog(inputStream, "子进程标准输出:"));
+            executor.submit(() -> readAndLog(errorStream, "子进程错误输出:"));
+
+            int exitCode = process.waitFor();
+            log.info("命令执行状态:{}", exitCode);
+            if (exitCode != 0) {
+                throw new Exception("执行命令或脚本出错!");
             }
-        } catch (Exception e) {
-            throw e;
+            executor.shutdown();
         } finally {
             process.destroy();
         }
     }
 
-    /**
-     * 打印执行日志
-     *
-     * @param process 进程
-     */
-    private static void print(Process process) {
-        // 获取子进程的输入流
-        InputStream inputStream = process.getInputStream();
-        // 获取子进程的错误流
-        InputStream errorStream = process.getErrorStream();
-        // 获取子进程的输出流
-        OutputStream outputStream = process.getOutputStream();
-
-        try (PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)), true);) {
-            pw.println("exit");
-        } catch (Exception e) {
-            log.error("出错啦:{}", e.getMessage());
-        }
-        //新起线程读取输入流
-        new Thread(() -> {
-            try (BufferedReader readInput = new BufferedReader(new InputStreamReader(inputStream))) {
-                String line;
-                log.info("子进程输入流:");
-                while ((line = readInput.readLine()) != null) {
-                    log.info(line);
-                }
-            } catch (IOException e) {
-                log.error("出错啦:{}", e.getMessage());
-            }
-        }).start();
-        //新开线程读取错误流
-        new Thread(() -> {
-            try (BufferedReader readError = new BufferedReader(new InputStreamReader(errorStream))) {
-                String line;
-                log.info("子进程错误流:");
-                while ((line = readError.readLine()) != null) {
-                    log.info(line);
-                }
-            } catch (IOException e) {
-                log.error("出错啦:{}", e.getMessage());
+    private static void readAndLog(InputStream inputStream, String prefix) {
+        try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
+            String line;
+            while ((line = reader.readLine()) != null) {
+                log.info("{} {}", prefix, line);
             }
-        }).start();
+        } catch (IOException e) {
+            log.error("{}读取时出错:{}", prefix, e.getMessage());
+        }
     }
 
 
     public static void main(String[] args) throws Exception {
-        String[] cmds = {"ipconfig", "/c", "clear"};
-        String cmd = "ipconfig";
-        LinuxCommand.exec(cmds);
+        for (int i = 0; i < 10000; i++) {
+            String[] cmds = {"ipconfig", "/all"};
+            String cmd = "ipconfig";
+            System.err.println("----------------------------" + i);
+            LinuxCommand.exec(cmds);
+        }
     }
 }

+ 16 - 3
sync-in/src/main/java/com/jjt/in/service/impl/InProcessServiceImpl.java

@@ -4,7 +4,10 @@ import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.jjt.common.constant.Constants;
 import com.jjt.common.domain.FileDesc;
-import com.jjt.common.utils.*;
+import com.jjt.common.utils.CompressZip;
+import com.jjt.common.utils.FtpUtil;
+import com.jjt.common.utils.LinuxCommand;
+import com.jjt.common.utils.StringUtils;
 import com.jjt.in.domain.InSyncInfo;
 import com.jjt.in.service.IInEsService;
 import com.jjt.in.service.IInMongoService;
@@ -21,6 +24,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
@@ -87,7 +91,11 @@ public class InProcessServiceImpl extends InBaseService implements IInProcessSer
                     ObjectMapper mapper = new ObjectMapper();
                     FileDesc desc = mapper.readValue(file, FileDesc.class);
                     File zipFile = new File(ftpDir + desc.getName());
-                    String md5 = DigestUtils.md5Hex(Files.newInputStream(zipFile.toPath()));
+                    String md5 = "";
+                    try (InputStream is = Files.newInputStream(zipFile.toPath())) {
+                        md5 = DigestUtils.md5Hex(is);
+                    }
+
                     if (md5.equals(desc.getMd5())) {
                         Files.move(file.toPath(), Paths.get(syncDir + file.getName()), StandardCopyOption.REPLACE_EXISTING);
                         Files.move(zipFile.toPath(), Paths.get(syncDir + zipFile.getName()), StandardCopyOption.REPLACE_EXISTING);
@@ -136,7 +144,12 @@ public class InProcessServiceImpl extends InBaseService implements IInProcessSer
                         syncInfo.setCreateTime(st);
 
                         File zipFile = new File(syncDir + desc.getName());
-                        String md5 = DigestUtils.md5Hex(Files.newInputStream(zipFile.toPath()));
+
+                        String md5 = "";
+                        try (InputStream is = Files.newInputStream(zipFile.toPath())) {
+                            md5 = DigestUtils.md5Hex(is);
+                        }
+
                         syncInfo.setSyncFileMd5(md5);
                         syncInfo.setSyncFileSize(zipFile.length());
                         if (md5.equals(desc.getMd5())) {

+ 4 - 15
sync-out/src/main/java/com/jjt/out/service/impl/OutEsServiceImpl.java

@@ -3,17 +3,16 @@ package com.jjt.out.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.pagehelper.PageHelper;
-import com.jjt.common.domain.FileDesc;
 import com.jjt.common.domain.IndexDO;
 import com.jjt.common.enums.SyncType;
 import com.jjt.common.utils.CompressZip;
 import com.jjt.common.utils.DateUtils;
+import com.jjt.common.utils.GenerateJsonFile;
 import com.jjt.common.utils.LinuxCommand;
 import com.jjt.out.domain.OutProcessInfo;
 import com.jjt.out.service.IOutEsService;
 import com.jjt.out.service.IOutProcessInfoService;
 import com.jjt.system.service.ISysConfigService;
-import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpHost;
 import org.apache.http.entity.ContentType;
@@ -165,18 +164,8 @@ public class OutEsServiceImpl extends OutBaseService implements IOutEsService {
         //打包文件--end
 
         //生成描述json文件--start
-        try {
-            String descName = syncDir + "sync-99-" + time + ".json";
-            String md5 = DigestUtils.md5Hex(Files.newInputStream(zipFile.toPath()));
-            FileDesc desc = new FileDesc();
-            desc.setName(zipName);
-            desc.setMd5(md5);
-            desc.setType(SyncType.es);
-            File descFile = new File(descName);
-            ObjectMapper mapper = new ObjectMapper();
-            mapper.writeValue(descFile, desc);
-        } catch (IOException e) {
-        }
+        String descName = syncDir + "sync-99-" + time + ".json";
+        GenerateJsonFile.generate(zipFile.toPath(), descName, zipName, SyncType.es);
         //生成描述json文件--end
 
         Date et = new Date();
@@ -251,7 +240,7 @@ public class OutEsServiceImpl extends OutBaseService implements IOutEsService {
     private IndexDO getIndexInfo(String indexName) {
         try (RestHighLevelClient client = getClient()) {
             Request request = new Request("GET", "/" + indexName);
-            HttpEntity entity = entity = client.getLowLevelClient().performRequest(request).getEntity();
+            HttpEntity entity = client.getLowLevelClient().performRequest(request).getEntity();
 
             String res = EntityUtils.toString(entity);
             //结果转json

+ 7 - 20
sync-out/src/main/java/com/jjt/out/service/impl/OutMongoServiceImpl.java

@@ -1,24 +1,21 @@
 package com.jjt.out.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.pagehelper.PageHelper;
-import com.jjt.common.domain.FileDesc;
 import com.jjt.common.enums.SyncType;
 import com.jjt.common.utils.CompressZip;
 import com.jjt.common.utils.DateUtils;
+import com.jjt.common.utils.GenerateJsonFile;
 import com.jjt.common.utils.LinuxCommand;
 import com.jjt.out.domain.OutProcessInfo;
 import com.jjt.out.service.IOutMongoService;
 import com.jjt.out.service.IOutProcessInfoService;
-import com.jjt.system.domain.SysConfig;
 import com.jjt.system.service.ISysConfigService;
 import com.mongodb.BasicDBObject;
 import com.mongodb.MongoClient;
 import com.mongodb.client.MongoCollection;
 import com.mongodb.client.MongoDatabase;
 import net.lingala.zip4j.ZipFile;
-import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.io.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -26,7 +23,6 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.io.File;
-import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -124,22 +120,13 @@ public class OutMongoServiceImpl extends OutBaseService implements IOutMongoServ
             FileUtils.deleteDirectory(targetDir);
 
             //生成描述json文件--start
-            try {
-                String descName = syncDir + "sync-78-" + nowTime + ".json";
-                if (!isInc) {
-                    //如果是全量,执行顺序要靠前,内网解析时,顺序号77代表全量,78代表增量
-                    descName = syncDir + "sync-77-" + nowTime + ".json";
-                }
-                String md5 = DigestUtils.md5Hex(Files.newInputStream(zipFile.getFile().toPath()));
-                FileDesc desc = new FileDesc();
-                desc.setName(zipName);
-                desc.setMd5(md5);
-                desc.setType(SyncType.mongo);
-                File descFile = new File(descName);
-                ObjectMapper mapper = new ObjectMapper();
-                mapper.writeValue(descFile, desc);
-            } catch (IOException e) {
+            String descName = syncDir + "sync-78-" + nowTime + ".json";
+            if (!isInc) {
+                //如果是全量,执行顺序要靠前,内网解析时,顺序号77代表全量,78代表增量
+                descName = syncDir + "sync-77-" + nowTime + ".json";
             }
+
+            GenerateJsonFile.generate(zipFile.getFile().toPath(), descName, zipName, SyncType.mongo);
             //生成描述json文件--end
 
             Date et = new Date();

+ 2 - 24
sync-out/src/main/java/com/jjt/out/service/impl/OutMysqlServiceImpl.java

@@ -1,32 +1,17 @@
 package com.jjt.out.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.jjt.common.constant.Constants;
-import com.jjt.common.domain.FileDesc;
-import com.jjt.common.domain.IndexDO;
 import com.jjt.common.enums.SyncType;
-import com.jjt.common.utils.CompressZip;
 import com.jjt.common.utils.DateUtils;
+import com.jjt.common.utils.GenerateJsonFile;
 import com.jjt.common.utils.LinuxCommand;
-import com.jjt.out.service.IOutEsService;
 import com.jjt.out.service.IOutMysqlService;
 import com.jjt.system.service.ISysConfigService;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpHost;
-import org.apache.http.util.EntityUtils;
-import org.elasticsearch.client.Request;
-import org.elasticsearch.client.RestClient;
-import org.elasticsearch.client.RestHighLevelClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -96,14 +81,7 @@ public class OutMysqlServiceImpl extends OutBaseService implements IOutMysqlServ
 
             //生成描述json文件--start
             String descName = syncDir + "sync-60-" + time + ".json";
-            String md5 = DigestUtils.md5Hex(Files.newInputStream(target));
-            FileDesc desc = new FileDesc();
-            desc.setName(exportName);
-            desc.setMd5(md5);
-            desc.setType(SyncType.mysql);
-            File descFile = new File(descName);
-            ObjectMapper mapper = new ObjectMapper();
-            mapper.writeValue(descFile, desc);
+            GenerateJsonFile.generate(target, descName, exportName, SyncType.mysql);
             //生成描述json文件--end
         } catch (Exception e) {
             e.printStackTrace();

+ 11 - 9
sync-out/src/main/java/com/jjt/out/service/impl/OutProcessInfoServiceImpl.java

@@ -9,21 +9,23 @@ import com.jjt.out.domain.OutProcessInfo;
 import com.jjt.out.service.IOutProcessInfoService;
 import com.jjt.common.core.text.Convert;
 
+import javax.annotation.Resource;
+
 /**
  * 外网数据操作记录Service业务层处理
- * 
+ *
  * @author ruoyi
  * @date 2023-06-20
  */
 @Service
-public class OutProcessInfoServiceImpl implements IOutProcessInfoService 
+public class OutProcessInfoServiceImpl implements IOutProcessInfoService
 {
-    @Autowired
+    @Resource
     private OutProcessInfoMapper outProcessInfoMapper;
 
     /**
      * 查询外网数据操作记录
-     * 
+     *
      * @param infoId 外网数据操作记录主键
      * @return 外网数据操作记录
      */
@@ -35,7 +37,7 @@ public class OutProcessInfoServiceImpl implements IOutProcessInfoService
 
     /**
      * 查询外网数据操作记录列表
-     * 
+     *
      * @param outProcessInfo 外网数据操作记录
      * @return 外网数据操作记录
      */
@@ -47,7 +49,7 @@ public class OutProcessInfoServiceImpl implements IOutProcessInfoService
 
     /**
      * 新增外网数据操作记录
-     * 
+     *
      * @param outProcessInfo 外网数据操作记录
      * @return 结果
      */
@@ -60,7 +62,7 @@ public class OutProcessInfoServiceImpl implements IOutProcessInfoService
 
     /**
      * 修改外网数据操作记录
-     * 
+     *
      * @param outProcessInfo 外网数据操作记录
      * @return 结果
      */
@@ -72,7 +74,7 @@ public class OutProcessInfoServiceImpl implements IOutProcessInfoService
 
     /**
      * 批量删除外网数据操作记录
-     * 
+     *
      * @param infoIds 需要删除的外网数据操作记录主键
      * @return 结果
      */
@@ -84,7 +86,7 @@ public class OutProcessInfoServiceImpl implements IOutProcessInfoService
 
     /**
      * 删除外网数据操作记录信息
-     * 
+     *
      * @param infoId 外网数据操作记录主键
      * @return 结果
      */

+ 16 - 9
sync-out/src/main/java/com/jjt/out/service/impl/OutProcessServiceImpl.java

@@ -21,8 +21,8 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.nio.file.Files;
-import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
 import java.util.*;
@@ -82,7 +82,10 @@ public class OutProcessServiceImpl extends OutBaseService implements IOutProcess
                         FileDesc desc = mapper.readValue(file, FileDesc.class);
                         boolean isZip = desc.getName().indexOf(".zip") != -1;
                         File syncFile = new File(syncDir + desc.getName());
-                        String md5 = DigestUtils.md5Hex(Files.newInputStream(syncFile.toPath()));
+                        String md5 = "";
+                        try (InputStream is = Files.newInputStream(syncFile.toPath())) {
+                            md5 = DigestUtils.md5Hex(is);
+                        }
                         if (md5.equals(desc.getMd5())) {
                             Date start = new Date();
                             //上传json文件
@@ -150,7 +153,7 @@ public class OutProcessServiceImpl extends OutBaseService implements IOutProcess
         String syncDir = syncDIr();
         //获取外网同步备份目录
         String bakDir = bakDir();
-        String target="/home/ftp/upload/";
+        String target = "/home/ftp/upload/";
 
         try {
             // 创建File对象
@@ -174,11 +177,15 @@ public class OutProcessServiceImpl extends OutBaseService implements IOutProcess
                     FileDesc desc = mapper.readValue(file, FileDesc.class);
                     boolean isZip = desc.getName().indexOf(".zip") != -1;
                     File syncFile = new File(syncDir + desc.getName());
-                    String md5 = DigestUtils.md5Hex(Files.newInputStream(syncFile.toPath()));
+                    String md5 = "";
+                    try (InputStream is = Files.newInputStream(syncFile.toPath())) {
+                        md5 = DigestUtils.md5Hex(is);
+                    }
+
                     if (md5.equals(desc.getMd5())) {
                         Date start = new Date();
                         //上传json文件
-                        Files.copy(file.toPath(), Paths.get(target+file.getName()), StandardCopyOption.REPLACE_EXISTING);
+                        Files.copy(file.toPath(), Paths.get(target + file.getName()), StandardCopyOption.REPLACE_EXISTING);
                         boolean flag = true;
                         boolean flag1 = false;
                         //上传zip文件
@@ -189,16 +196,16 @@ public class OutProcessServiceImpl extends OutBaseService implements IOutProcess
                                 //如果是分卷压缩文件,则需要读取所有文件名上传
                                 list = zipFile.getSplitZipFiles();
                                 for (File f : list) {
-                                    Files.copy(f.toPath(), Paths.get(target+f.getName()), StandardCopyOption.REPLACE_EXISTING);
+                                    Files.copy(f.toPath(), Paths.get(target + f.getName()), StandardCopyOption.REPLACE_EXISTING);
                                     flag1 = true;
                                 }
                             } else {
-                                Files.copy(zipFile.getFile().toPath(), Paths.get(target+zipFile.getFile().getName()), StandardCopyOption.REPLACE_EXISTING);
+                                Files.copy(zipFile.getFile().toPath(), Paths.get(target + zipFile.getFile().getName()), StandardCopyOption.REPLACE_EXISTING);
                                 flag1 = true;
                             }
                         } else {
                             flag1 = true;
-                            Files.copy(syncFile.toPath(), Paths.get(target+syncFile.getName()), StandardCopyOption.REPLACE_EXISTING);
+                            Files.copy(syncFile.toPath(), Paths.get(target + syncFile.getName()), StandardCopyOption.REPLACE_EXISTING);
                         }
 
                         Date end = new Date();
@@ -289,4 +296,4 @@ public class OutProcessServiceImpl extends OutBaseService implements IOutProcess
             }
         }
     }
-}
+}

+ 7 - 4
sync-out/src/test/java/com/test/FileWriteTest.java

@@ -1,11 +1,11 @@
 package com.test;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.jjt.common.domain.IndexDO;
 import com.jjt.common.enums.SyncType;
 import org.apache.commons.codec.digest.DigestUtils;
 
-import java.io.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 import java.nio.file.Files;
 
 public class FileWriteTest {
@@ -14,7 +14,10 @@ public class FileWriteTest {
 
         File baseFile = new File("D:\\SYSTEM\\Desktop\\temp\\sync\\test.json");
 
-        String md5 = DigestUtils.md5Hex(Files.newInputStream(baseFile.toPath()));
+        String md5 = "";
+        try (InputStream is = Files.newInputStream(baseFile.toPath())) {
+            md5 = DigestUtils.md5Hex(is);
+        }
         System.err.println(md5);
 
 //        IndexDO ido = new IndexDO();