Java Code Examples for org.ini4j.Ini#load()

The following examples show how to use org.ini4j.Ini#load() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IniModuleConfigParser.java    From nuls-v2 with MIT License 7 votes vote down vote up
@Override
public Map<String, Map<String,ConfigurationLoader.ConfigItem>> parse(String configFile,InputStream inputStream) throws Exception {
    Config cfg = new Config();
    cfg.setMultiSection(true);
    Ini ini = new Ini();
    ini.setConfig(cfg);
    ini.load(inputStream);
    Map<String,Map<String,ConfigurationLoader.ConfigItem>> res = new HashMap<>(ini.size());
    ini.values().forEach(s-> {
        Map<String,ConfigurationLoader.ConfigItem> domainValues = new HashMap<>(s.size());
        s.forEach((key, value) -> domainValues.put(key, new ConfigurationLoader.ConfigItem(configFile, value)));
        res.put(s.getName(),domainValues);
    });
    Log.debug("{},加载配置:{}",configFile,res);
    return res;
}
 
Example 2
Source File: SdkIniFileReader.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
   * @param basePath  the base path to attach to, if relative file name is used
   * @param fileName  the name of the file to be loaded 
   * @param enableMultiOption  the state of multi-option configuration flag  
   */
private Ini loadFile ( String basePath, String fileName
                     , boolean enableMultiOption ) throws Exception 
{
    String full_name = FilenameUtils.concat(basePath, fileName);
    File file = new File(full_name); 
       if (file.exists() && file.isFile()) {
           Ini ini = new Wini();
           Config config = ini.getConfig();
           
           config.setMultiSection(true);
           config.setMultiOption(enableMultiOption);
           config.setGlobalSection(true);
           config.setComment(true);

           ini.setFile(file);
           ini.setComment(COMMENT_LINE_CHARS);
           try(InputStreamReader inputStreamReader = TextEncoding.getInputStreamReader(file)){
           	ini.load(inputStreamReader);
           }
           return ini;
       }
    return null;
}
 
Example 3
Source File: FromHereCredentialsIniStream.java    From here-aaa-java-sdk with Apache License 2.0 6 votes vote down vote up
static Properties getPropertiesFromIni(InputStream inputStream, String sectionName) throws IOException {
    Ini ini = new Ini();
    try (Reader reader = new InputStreamReader(inputStream, OAuthConstants.UTF_8_CHARSET)) {
        ini.load(reader);
        Ini.Section section = ini.get(sectionName);
        Properties properties = new Properties();
        properties.put(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_ENDPOINT_URL_PROPERTY,
                section.get(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_ENDPOINT_URL_PROPERTY));
        properties.put(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_ID_PROPERTY,
                section.get(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_ID_PROPERTY));
        properties.put(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_SECRET_PROPERTY,
                section.get(OAuth1ClientCredentialsProvider.FromProperties.ACCESS_KEY_SECRET_PROPERTY));
        // scope is optional
        String scope = section.get(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_SCOPE_PROPERTY);
        if (null != scope)
            properties.put(OAuth1ClientCredentialsProvider.FromProperties.TOKEN_SCOPE_PROPERTY, scope);

        return properties;
    }
}
 
Example 4
Source File: WifImporter.java    From Jabit with Apache License 2.0 6 votes vote down vote up
public WifImporter(BitmessageContext ctx, InputStream in, Pubkey.Feature... features) throws IOException {
    this.ctx = ctx;

    Ini ini = new Ini();
    ini.load(in);

    for (Entry<String, Profile.Section> entry : ini.entrySet()) {
        if (!entry.getKey().startsWith("BM-"))
            continue;

        Profile.Section section = entry.getValue();
        BitmessageAddress address = Factory.createIdentityFromPrivateKey(
            entry.getKey(),
            getSecret(section.get("privsigningkey")),
            getSecret(section.get("privencryptionkey")),
            Long.parseLong(section.get("noncetrialsperbyte")),
            Long.parseLong(section.get("payloadlengthextrabytes")),
            Pubkey.Feature.bitfield(features)
        );
        if (section.containsKey("chan")) {
            address.setChan(Boolean.parseBoolean(section.get("chan")));
        }
        address.setAlias(section.get("label"));
        identities.add(address);
    }
}
 
Example 5
Source File: AuditConfigCommandIntegrationTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigAuditEntireConfig() throws IOException {
  ProjectWorkspace workspace =
      TestDataHelper.createProjectWorkspaceForScenario(this, "audit_config", tmp);
  workspace.setUp();

  ProcessResult result = workspace.runBuckCommand("audit", "config");

  // Use low level ini parser to build config.
  Ini auditIni = Inis.makeIniParser(true);
  auditIni.load(new StringReader(result.getStdout()));
  // Ini object doesn't really provide a good way to compare 2 ini files.
  // Convert that into immutable map so that we can compare sorted maps instead.
  ImmutableMap.Builder<String, ImmutableMap<String, String>> audit_config =
      ImmutableMap.builder();
  auditIni.forEach(
      (section_name, section) -> {
        ImmutableMap.Builder<String, String> section_builder = ImmutableMap.builder();
        section.forEach((k, v) -> section_builder.put(k, v));
        audit_config.put(section_name, section_builder.build());
      });

  assertEquals(workspace.getConfig().getSectionToEntries(), audit_config.build());
}
 
Example 6
Source File: TestDataHelper.java    From buck with Apache License 2.0 6 votes vote down vote up
public static void overrideBuckconfig(
    ProjectWorkspace projectWorkspace,
    Map<String, ? extends Map<String, String>> buckconfigOverrides)
    throws IOException {
  String config = projectWorkspace.getFileContents(".buckconfig");
  Ini ini = Inis.makeIniParser(true);
  ini.load(new StringReader(config));
  for (Map.Entry<String, ? extends Map<String, String>> section :
      buckconfigOverrides.entrySet()) {
    for (Map.Entry<String, String> entry : section.getValue().entrySet()) {
      ini.put(section.getKey(), entry.getKey(), entry.getValue());
    }
  }
  StringWriter writer = new StringWriter();
  ini.store(writer);
  Files.write(projectWorkspace.getPath(".buckconfig"), writer.toString().getBytes(UTF_8));
}
 
Example 7
Source File: IniUtil.java    From spring-boot-plus with Apache License 2.0 5 votes vote down vote up
public static Map<String,String> parseIni(String string) {
    Config config = new Config();
    config.setGlobalSection(true);
    config.setGlobalSectionName("");
    Ini ini = new Ini();
    ini.setConfig(config);
    try {
        ini.load(new StringReader(string));
        Profile.Section section = ini.get("");
        return section;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 8
Source File: IniUtil.java    From spring-boot-plus with Apache License 2.0 5 votes vote down vote up
public static Map<String,String> parseIni(String sectionName,String string) {
    Ini ini = new Ini();
    try {
        ini.load(new StringReader(string));
        Profile.Section section = ini.get(sectionName);
        return section;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 9
Source File: DBUtils.java    From nuls-v2 with MIT License 5 votes vote down vote up
private static String getProjectDbPath() throws Exception {
        Config cfg = new Config();
        cfg.setMultiSection(true);
        Ini ini = new Ini();
        ini.setConfig(cfg);
        ini.load(new File("module.ncf"));  //可以读取到nuls_2.0项目根目录下的module.ncf,在生产环境读到jar同目录下的module.ncf
        IniEntity ie = new IniEntity(ini);
        String filePath = ie.getCfgValue("Module", "DataPath");
//        Log.debug(filePath); //读取配置的data文件夹路径
        return filePath;
    }
 
Example 10
Source File: MyKernelBootstrap.java    From nuls-v2 with MIT License 5 votes vote down vote up
/**
 * 启动模块
 * @param modules
 * @throws Exception
 */
private void startModule(File modules) throws Exception {
    Config cfg = new Config();
    cfg.setMultiSection(true);
    Ini ini = new Ini();
    ini.setConfig(cfg);
    ini.load(new File(modules.getAbsolutePath() + File.separator + "Module.ncf"));
    IniEntity ie = new IniEntity(ini);
    String managed = ie.getCfgValue("Core", "Managed");
    if ("1".equals(managed)) {
        ThreadUtils.createAndRunThread("module-start", () -> {
            Process process = null;
            try {
                String cmd = modules.getAbsolutePath() + File.separator + "start.sh "
                        + " --jre " + System.getProperty("java.home")
                        + " --managerurl " + "ws://127.0.0.1:7771/ "
                        + (StringUtils.isNotBlank(logPath) ? " --logpath " + logPath: "")
                        + (StringUtils.isNotBlank(dataPath) ? " --datapath " + dataPath : "")
                        + (StringUtils.isNotBlank(logLevel) ? " --loglevel " + logLevel : "")
                        + " --debug " + debug
                        + (StringUtils.isNotBlank(config) ? " --config " + config : "")
                        + " -r ";
                Log.info("run script:{}",cmd);
                process = Runtime.getRuntime().exec(cmd);
                synchronized (MODULE_STOP_LIST_SCRIPT){
                    MODULE_STOP_LIST_SCRIPT.add(modules.getAbsolutePath() + File.separator + "stop.sh ");
                }
                printRuntimeConsole(process);
            } catch (IOException e) {
                log.error("启动模块异常",e);
            }
        });
    }
}
 
Example 11
Source File: SvnConfigFilesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Section getSection(File serversFile) throws FileNotFoundException, IOException {
    FileInputStream is = new FileInputStream(serversFile);
    Ini ini = new Ini();
    try {
        ini.load(is);
    } finally {
        is.close();
    }
    return ini.get("global");
}
 
Example 12
Source File: ConfigLoader.java    From nuls with MIT License 5 votes vote down vote up
public static IniEntity loadIni(String fileName) throws IOException {
    Config cfg = new Config();
    URL url = ConfigLoader.class.getClassLoader().getResource(fileName);
    cfg.setMultiSection(true);
    Ini ini = new Ini();
    ini.setConfig(cfg);
    ini.load(url);
    return new IniEntity(ini);
}
 
Example 13
Source File: GtConfig.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@NotNull
public static GtConfig load(@NotNull File configFile) {
  if (!configFile.exists()) {
    LOG.info("No .git/config file at " + configFile.getPath());
    return EMPTY;
  } else {
    Ini ini = new Ini();
    ini.getConfig().setMultiOption(true);
    ini.getConfig().setTree(false);

    try {
      ini.load(configFile);
    } catch (IOException exception) {
      LOG.warn(new RepoStateException("Couldn\'t load .git/config file at " + configFile.getPath(), exception));
      return EMPTY;
    }
    ImmutableSet.Builder<String> svnRemotes = ImmutableSet.builder();
    for (Entry<String, Section> section : ini.entrySet()) {
      Matcher matcher = SVN_REMOTE_SECTION.matcher(section.getKey());
      if (matcher.matches()) {
        String name = matcher.group(1);
        svnRemotes.add(name);
      }
    }
    return new GtConfig(svnRemotes);
  }
}
 
Example 14
Source File: Inis.java    From buck with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public static ImmutableMap<String, ImmutableMap<String, String>> read(Reader reader)
    throws IOException {
  Ini ini = makeIniParser(/*enable_includes=*/ false);
  ini.load(reader);
  return toMap(ini);
}
 
Example 15
Source File: IniTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testSecondaryLoadOverridesOriginalDefs() throws IOException {
  Ini ini = Inis.makeIniParser(false);
  Reader originalInput =
      new StringReader(
          Joiner.on("\n")
              .join(
                  "[alias]",
                  "  buck = //src/com/facebook/buck/cli:cli",
                  "[cache]",
                  "  mode = dir"));
  Reader overrideInput =
      new StringReader(
          Joiner.on("\n")
              .join(
                  "[alias]",
                  "  test_util = //test/com/facebook/buck/util:util",
                  "[cache]",
                  "  mode ="));
  ini.load(originalInput);
  ini.load(overrideInput);

  Section aliasSection = ini.get("alias");
  assertEquals(
      "Should be the union of the two [alias] sections.",
      ImmutableMap.of(
          "buck", "//src/com/facebook/buck/cli:cli",
          "test_util", "//test/com/facebook/buck/util:util"),
      aliasSection);

  Section cacheSection = ini.get("cache");
  assertEquals(
      "Values from overrideInput should supercede those from originalInput, as appropriate.",
      ImmutableMap.of("mode", ""),
      cacheSection);
}