From a01bbba2fdaf5feef48590658f43dcab3939bc01 Mon Sep 17 00:00:00 2001 From: huangfeng Date: Fri, 27 Dec 2024 11:23:05 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=97=B6=E5=80=99=E5=85=88=E7=94=A8=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E5=90=8D=EF=BC=8C=E5=AE=8C=E6=88=90=E5=90=8E=E5=86=8D?= =?UTF-8?q?=E6=94=B9=E6=88=90=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/xydl/cac/iec/IecClient.java | 6 +++++- src/main/java/com/xydl/cac/iec/IecServerService.java | 6 +++--- src/main/java/com/xydl/cac/util/SFTPTool.java | 5 ++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/xydl/cac/iec/IecClient.java b/src/main/java/com/xydl/cac/iec/IecClient.java index d87fbb0..c671ea3 100644 --- a/src/main/java/com/xydl/cac/iec/IecClient.java +++ b/src/main/java/com/xydl/cac/iec/IecClient.java @@ -11,6 +11,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.util.CollectionUtils; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -168,11 +169,14 @@ public class IecClient implements ClientEventListener { } public void getFile(String remotePath, String localPath, Integer todel) throws Exception { - GetFileAction gfa = new GetFileAction(localPath); + String tmpFile = localPath + ".tmp"; + GetFileAction gfa = new GetFileAction(tmpFile); clientAssociation.getFile(remotePath, gfa); if (todel != null && todel == Constants.TRUE) { clientAssociation.deleteFile(remotePath); } + File file = new File(tmpFile); + file.renameTo(new File(localPath)); } @Override diff --git a/src/main/java/com/xydl/cac/iec/IecServerService.java b/src/main/java/com/xydl/cac/iec/IecServerService.java index 38cc22b..f02518d 100644 --- a/src/main/java/com/xydl/cac/iec/IecServerService.java +++ b/src/main/java/com/xydl/cac/iec/IecServerService.java @@ -64,7 +64,7 @@ public class IecServerService { } public void stopServer(Integer fileId) { - this.onlyStopServer(fileId); + this.doStopServer(fileId); Optional optional = fileRepository.findById(fileId); if (optional.isPresent()) { IcdFile icdFile = optional.get(); @@ -73,7 +73,7 @@ public class IecServerService { } } - private void onlyStopServer(Integer fileId) { + private void doStopServer(Integer fileId) { IecServer iecServer = StaticVariable.iecServerMap.get(fileId); if (iecServer != null) { iecServer.stop(); @@ -87,7 +87,7 @@ public class IecServerService { Iterator it = StaticVariable.iecServerMap.keySet().iterator(); while (it.hasNext()) { Integer key = it.next(); - this.onlyStopServer(key); + this.doStopServer(key); } } diff --git a/src/main/java/com/xydl/cac/util/SFTPTool.java b/src/main/java/com/xydl/cac/util/SFTPTool.java index ba6ac97..3ea8a6e 100644 --- a/src/main/java/com/xydl/cac/util/SFTPTool.java +++ b/src/main/java/com/xydl/cac/util/SFTPTool.java @@ -55,7 +55,10 @@ public class SFTPTool { } public void download(String remoteFileName, String localFilePath) throws Exception { - sftp.get(remoteFileName, new FileOutputStream(localFilePath)); + String tmpFile = localFilePath + ".tmp"; + sftp.get(remoteFileName, new FileOutputStream(tmpFile)); + File file = new File(tmpFile); + file.renameTo(new File(localFilePath)); } public void delete(String remoteFileName) throws SftpException {