HandleYmlFile.java 1.3 KB
Newer Older
jianglw's avatar
jianglw committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
package com.ruoyi.common.handlefile;

import com.ruoyi.common.utils.PublicUtils;
import com.ruoyi.common.utils.YamlUtils;
import com.ruoyi.common.utils.file.FileUtils;
import org.springframework.web.multipart.MultipartFile;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;

/**
 * @author jianglw
 * @version 1.0
 * @date 2021/1/28 18:59
 */

public class HandleYmlFile implements HandleFile {

    /**
     * 读取数据
     */
    private Map<String,Object> map;

    @Override
    public HandleFile readFile(MultipartFile file) {
        map=YamlUtils.getYamlFile( file );
        return this;
    }

    @Override
    public HandleFile encryptionFile() throws Exception {
        map=PublicUtils.getEncryptionMap( map ) ;
        return this;
    }

    @Override
    public HandleFile decryptFile() throws Exception {
        map=PublicUtils.getDecryptMap( map ) ;
        return this;
    }

    @Override
    public void createFile(String fileName,String userName,String createdPath) throws IOException {
        Yaml yaml = new Yaml();
        FileUtils.createdFile(fileName,userName,createdPath,yaml.dumpAsMap( map ));
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }
}