feat: 增加61850下载文件功能

iec104
huangfeng 8 months ago
parent 5ecb8193ee
commit bd05b58dc4

@ -0,0 +1,29 @@
package com.xydl.cac.iec;
import com.beanit.iec61850bean.GetFileListener;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import java.io.File;
@Slf4j
public class GetFileAction implements GetFileListener {
File file;
public GetFileAction(String filename) {
file = new File(filename);
}
@Override
@Synchronized
public boolean dataReceived(byte[] fileData, boolean moreFollows) {
try {
FileUtils.writeByteArrayToFile(file, fileData, true);
return true;
} catch (Exception e) {
log.error("61850获取文件异常.", e);
return false;
}
}
}

@ -11,6 +11,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.util.List;
@Slf4j
public class IecClient implements ClientEventListener {
@ -93,6 +94,19 @@ public class IecClient implements ClientEventListener {
}
}
public List<FileInformation> listFile(String path) throws Exception {
List<FileInformation> list = clientAssociation.getFileDirectory(path);
return list;
}
public void getFile(String remotePath, String filename, String localPath, boolean todel) throws Exception {
GetFileAction gfa = new GetFileAction(localPath);
clientAssociation.getFile(remotePath + filename, gfa);
if (todel) {
clientAssociation.deleteFile(remotePath + filename);
}
}
@Override
public void newReport(Report report) {
if (report != null) {
@ -113,6 +127,9 @@ public class IecClient implements ClientEventListener {
System.out.println(str);
str = iecClient.getValue("OMDLMONT/SPDC1.MaxDsch.t", "MX");
System.out.println(str);
List<FileInformation> list = iecClient.listFile("/fdata");
iecClient.getFile("/fdata/web/comtrade/1/18/6/", "20241021_113736_703_0_0.dat", "/eqmid/20241021_113736_703_0_0.dat", true);
} catch (Exception ex) {
ex.printStackTrace();
} finally {

Loading…
Cancel
Save