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;
        }
    }
}
