Java Code Examples for org.apache.commons.configuration.HierarchicalINIConfiguration#save()

The following examples show how to use org.apache.commons.configuration.HierarchicalINIConfiguration#save() . 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: EurostagImpactAnalysis.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
private void writeWp43Configs(List<Contingency> contingencies, Path workingDir) throws IOException, ConfigurationException {
    Path baseWp43ConfigFile = PlatformConfig.defaultConfig().getConfigDir().resolve(WP43_CONFIGS_FILE_NAME);

    // generate one variant of the base config for all the contingency
    // this allow to add extra variables for some indexes
    HierarchicalINIConfiguration configuration = new HierarchicalINIConfiguration(baseWp43ConfigFile.toFile());
    SubnodeConfiguration node = configuration.getSection("smallsignal");
    node.setProperty("f_instant", parameters.getFaultEventInstant());
    for (int i = 0; i < contingencies.size(); i++) {
        Contingency contingency = contingencies.get(i);
        if (contingency.getElements().isEmpty()) {
            throw new AssertionError("Empty contingency " + contingency.getId());
        }
        Iterator<ContingencyElement> it = contingency.getElements().iterator();
        // compute the maximum fault duration
        double maxDuration = getFaultDuration(contingency, it.next());
        while (it.hasNext()) {
            maxDuration = Math.max(maxDuration, getFaultDuration(contingency, it.next()));
        }
        node.setProperty("f_duration", maxDuration);
        Path wp43Config = workingDir.resolve(WP43_CONFIGS_PER_FAULT_FILE_NAME.replace(CommandConstants.EXECUTION_NUMBER_PATTERN, Integer.toString(i)));
        try (Writer writer = Files.newBufferedWriter(wp43Config, StandardCharsets.UTF_8)) {
            configuration.save(writer);
        }
    }
}
 
Example 2
Source File: SlackNotifier.java    From yfiton with Apache License 2.0 6 votes vote down vote up
@Override
protected void storeAccessTokenData(AccessTokenData accessTokenData, HierarchicalINIConfiguration configuration) throws NotificationException {
    String teamId = accessTokenData.get("teamId");
    configuration.setProperty(KEY_DEFAULT_TEAM_ID, teamId);

    SubnodeConfiguration section = configuration.getSection(teamId);

    section.setProperty(KEY_ACCESS_TOKEN, accessTokenData.getAccessToken());
    for (Map.Entry<String, String> entry : accessTokenData.getData()) {
        section.setProperty(entry.getKey(), entry.getValue());
    }

    try {
        configuration.save();
    } catch (ConfigurationException e) {
        throw new NotificationException(e);
    }
}
 
Example 3
Source File: SlackNotifier.java    From yfiton with Apache License 2.0 6 votes vote down vote up
@Override
protected void storeAccessTokenData(AccessTokenData accessTokenData, HierarchicalINIConfiguration configuration) throws NotificationException {
    String teamId = accessTokenData.get("teamId");
    configuration.setProperty(KEY_DEFAULT_TEAM_ID, teamId);

    SubnodeConfiguration section = configuration.getSection(teamId);

    section.setProperty(KEY_ACCESS_TOKEN, accessTokenData.getAccessToken());
    for (Map.Entry<String, String> entry : accessTokenData.getData()) {
        section.setProperty(entry.getKey(), entry.getValue());
    }

    try {
        configuration.save();
    } catch (ConfigurationException e) {
        throw new NotificationException(e);
    }
}
 
Example 4
Source File: OAuthNotifier.java    From yfiton with Apache License 2.0 5 votes vote down vote up
protected void storeAccessTokenData(AccessTokenData accessTokenData, HierarchicalINIConfiguration configuration) throws NotificationException {
    configuration.setProperty(KEY_ACCESS_TOKEN, accessTokenData.getAccessToken());

    for (Map.Entry<String, String> entry : accessTokenData.getData()) {
        configuration.setProperty(entry.getKey(), entry.getValue());
    }

    try {
        configuration.save();
    } catch (ConfigurationException e) {
        throw new NotificationException(e);
    }
}
 
Example 5
Source File: HierarchicalIniConfigurationWrapper.java    From StatsAgg with Apache License 2.0 5 votes vote down vote up
public static void saveHierarchicalIniConfigurationFile(String filePath, String filename, HierarchicalINIConfiguration hierarchicalIniConfiguration) {
    try {
        File hierarchicalIniConfigurationFile = new File(filePath + File.separator + filename);
        hierarchicalIniConfiguration.save(hierarchicalIniConfigurationFile);
    }
    catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
    }
}
 
Example 6
Source File: HierarchicalIniConfigurationWrapper.java    From StatsAgg with Apache License 2.0 5 votes vote down vote up
public static void saveHierarchicalIniConfigurationFile(File hierarchicalIniConfigurationFile, HierarchicalINIConfiguration hierarchicalIniConfiguration) {
    try {
        hierarchicalIniConfiguration.save(hierarchicalIniConfigurationFile);
    }
    catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
    }
}
 
Example 7
Source File: HierarchicalIniConfigurationWrapper.java    From StatsAgg with Apache License 2.0 5 votes vote down vote up
public static String saveHierarchicalIniConfigurationToString(HierarchicalINIConfiguration hierarchicalIniConfiguration) {
    try {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        hierarchicalIniConfiguration.save(byteArrayOutputStream);
        return byteArrayOutputStream.toString();
    }
    catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
        return null;
    }
}
 
Example 8
Source File: OAuthNotifier.java    From yfiton with Apache License 2.0 5 votes vote down vote up
protected void storeAccessTokenData(AccessTokenData accessTokenData, HierarchicalINIConfiguration configuration) throws NotificationException {
    configuration.setProperty(KEY_ACCESS_TOKEN, accessTokenData.getAccessToken());

    for (Map.Entry<String, String> entry : accessTokenData.getData()) {
        configuration.setProperty(entry.getKey(), entry.getValue());
    }

    try {
        configuration.save();
    } catch (ConfigurationException e) {
        throw new NotificationException(e);
    }
}