Java 类org.elasticsearch.common.settings.loader.YamlSettingsLoader 实例源码

项目:elasticsearch-analysis-rosette    文件:AnalysisRosettePlugin.java   
private boolean setBTRootFromConfig() {
    boolean rc = false;

    // NB: This file name construction only works if this code is run from our plugin's
    // jar file in the standard elascticsearch directory tree.  If you are running this
    // in some other way, either pass -Dbt.root=<BT root path> to the VM or set the
    // BT_ROOT environment variable.
    Environment environment = new Environment();
    File myJarPath = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
    File myConfigFile = new File(String.format("%s/../../%s/bt/%s-config.yml", myJarPath.getParent(), environment.configFile().getName(), PLUGIN_NAME));

    logger.info(String.format("Attempting to set BT root directory from the configuration file '%s'.", myConfigFile.getAbsolutePath()));
    try {
        YamlSettingsLoader sl = new YamlSettingsLoader();
        Map<String, String> settings = sl.load(readFile(myConfigFile));
        String btRoot = settings.get(BT_ROOT_PARAM);
        rc = setBTRoot(btRoot);
    } catch (IOException e) {
        logger.error(String.format("Error reading config file %s\n Caused by: %s", myConfigFile.getAbsolutePath(), e.getStackTrace()));
    }
    return rc;
}
项目:elasticsearch-cloud-rackspace    文件:SettingsLoader.java   
public static Settings getSettingsFromResource(String path) throws IOException {
    InputStream is = SettingsLoader.class.getResourceAsStream(path);

    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder out = new StringBuilder();
    String line;
    while((line = reader.readLine()) != null){
        out.append("\n").append(line);
    }
    reader.close();
    Map<String,String> settingsMap = new YamlSettingsLoader().load(out.toString());

    return ImmutableSettings.settingsBuilder().put(settingsMap).build();
}