perf: 优化下载文件时候先用临时名,完成后再改成文件名

iec104
huangfeng 6 months ago
parent 2f7465d765
commit a01bbba2fd

@ -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

@ -64,7 +64,7 @@ public class IecServerService {
}
public void stopServer(Integer fileId) {
this.onlyStopServer(fileId);
this.doStopServer(fileId);
Optional<IcdFile> 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<Integer> it = StaticVariable.iecServerMap.keySet().iterator();
while (it.hasNext()) {
Integer key = it.next();
this.onlyStopServer(key);
this.doStopServer(key);
}
}

@ -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 {

Loading…
Cancel
Save