All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rrsunhome.excelsql.parser.FileParserManager Maven / Gradle / Ivy

There is a newer version: 2.1.2
Show newest version
package com.github.rrsunhome.excelsql.parser;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : wangqijia
 * create at:  2021/11/8  下午8:16
 */
public class FileParserManager {

    private List fileParsers = new ArrayList<>();

    public FileParserManager() {
        addDefaultFileParsers();
    }

    public void registerFileParser(FileParser fileParser) {
        fileParsers.add(fileParser);
    }

    public FileParser findFileParser(String fileExtension) {
        for (FileParser fileParser : fileParsers) {
            if (fileParser.canParseExtension(fileExtension)) {
                return fileParser;
            }
        }
        throw new RuntimeException(String.format("无法找到 %s 对应的解析器", fileExtension));
    }

    private void addDefaultFileParsers() {
        registerFileParser(new ExcelFileParser());
        registerFileParser(new CsvFileParser());
        registerFileParser(new TextFileParser());
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy