org.ini4j.Ini - java examples

Here are the examples of the java api org.ini4j.Ini taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

95 Examples 7

19 View Complete Implementation : DescriptorParser.java
Copyright Eclipse Public License 1.0
Author : excelsior-oss
private static String getUpdateDescrpitorURI(File updatePropertiesFile) throws InvalidFileFormatException, IOException {
    final Ini ini = new Ini(updatePropertiesFile);
    return ini.get(GENERAL_INI_SECTION, UPDATE_DIR_PROPERTY_NAME);
}

19 View Complete Implementation : MetaConfig.java
Copyright Apache License 2.0
Author : killme2008
public void loadFromString(final String str) {
    try {
        StringReader reader = new StringReader(str);
        final Ini conf = new Ini(reader);
        this.populateAttributes(conf);
    } catch (final IOException e) {
        throw new MetamorphosisServerStartupException("Parse configuration failed,path=" + this.path, e);
    }
}

19 View Complete Implementation : HgConfigFiles.java
Copyright Apache License 2.0
Author : apache
private Ini.Section getSection(Ini ini, String key, boolean create) {
    Ini.Section section = ini.get(key);
    if (section == null && create) {
        return ini.add(key);
    }
    return section;
}

19 View Complete Implementation : IniConfigIni4j.java
Copyright GNU General Public License v3.0
Author : jub77
clreplaced IniConfigIni4j implements IniConfig {

    private Ini ini;

    public IniConfigIni4j(Ini ini) {
        this.ini = ini;
    }

    @Override
    public IniConfigSection getSection(String name) {
        if (!ini.containsKey(name)) {
            ini.add(name);
        }
        return new IniConfigSectionIni4j(ini, ini.get(name));
    }

    @Override
    public void removeSection(String name) {
        ini.remove(name);
    }
}

19 View Complete Implementation : MonitorConfig.java
Copyright Apache License 2.0
Author : killme2008
private void populateConfig(Ini iniConfig) {
    this.populateSystemConfig(iniConfig);
    this.populateServerConfig(iniConfig);
    this.populateGroupConfig(iniConfig);
    this.populateFilterTopicConfig(iniConfig);
}

19 View Complete Implementation : IniEntity.java
Copyright MIT License
Author : nuls-io
/**
 * @author Niels
 */
public clreplaced IniEnreplacedy {

    private final Ini ini;

    public IniEnreplacedy(Ini ini) {
        this.ini = ini;
    }

    /**
     * 获取指定部分指定键的值
     *
     * @param section 所属部分
     * @param key     属性(键)
     * @return String 键对应的值
     */
    public String getCfgValue(String section, String key) throws Exception {
        Profile.Section ps = ini.get(section);
        if (null == ps) {
            throw new Exception("CONFIGURATION_ITEM_DOES_NOT_EXIST");
        }
        String value = ps.get(key);
        if (StringUtils.isBlank(value)) {
            throw new Exception("CONFIGURATION_ITEM_DOES_NOT_EXIST");
        }
        return value;
    }

    /**
     * 获取指定部分指定键指定值类型的值
     *
     * @param section      所属部分
     * @param key          属性(键)
     * @param defaultValue 值的类型
     * @return T 键对应的值
     */
    public <T> T getCfgValue(String section, String key, T defaultValue) {
        Profile.Section ps = ini.get(section);
        if (null == ps) {
            return defaultValue;
        }
        String value = ps.get(key);
        if (StringUtils.isBlank(value)) {
            return defaultValue;
        }
        return getValueByType(value, defaultValue);
    }

    /**
     * 将String转为指定类型
     *
     * @param value        String
     * @param defaultValue 值类型
     * @return T 值类型
     */
    protected static <T> T getValueByType(String value, T defaultValue) {
        if (defaultValue instanceof Integer) {
            return (T) ((Integer) Integer.parseInt(value));
        } else if (defaultValue instanceof Long) {
            return (T) ((Long) Long.parseLong(value));
        } else if (defaultValue instanceof Float) {
            return (T) ((Float) Float.parseFloat(value));
        } else if (defaultValue instanceof Double) {
            return (T) ((Double) Double.parseDouble(value));
        } else if (defaultValue instanceof Boolean) {
            return (T) ((Boolean) Boolean.parseBoolean(value));
        }
        return (T) value;
    }

    /**
     * 获取Section对象
     *
     * @param section Section 键
     * @return Section
     */
    public Profile.Section getSection(String section) throws Exception {
        Profile.Section ps = ini.get(section);
        if (null == ps) {
            throw new Exception("CONFIGURATION_ITEM_DOES_NOT_EXIST");
        }
        return ps;
    }

    /**
     * 获取所有的Section键
     *
     * @return List<String>
     */
    public List<String> getSectionList() {
        Set<Map.Entry<String, Profile.Section>> entrySet = ini.entrySet();
        List<String> list = new ArrayList<>();
        for (Map.Entry<String, Profile.Section> entry : entrySet) {
            list.add(entry.getKey());
        }
        return list;
    }

    /**
     * 当前对象转String
     *
     * @return String
     */
    @Override
    public String toString() {
        return ini.toString();
    }
}

19 View Complete Implementation : MetaConfig.java
Copyright Apache License 2.0
Author : killme2008
public void loadFromFile(final String path) {
    try {
        this.path = path;
        final File file = new File(path);
        File appClreplacedDir = new File(file.getParentFile().getParentFile(), "provided");
        if (appClreplacedDir.exists() && appClreplacedDir.isDirectory()) {
            // It's a directory,it must be ends with "/"
            this.appClreplacedPath = appClreplacedDir.getAbsolutePath() + "/";
        }
        if (!file.exists()) {
            throw new MetamorphosisServerStartupException("File " + path + " is not exists");
        }
        final Ini conf = this.createIni(file);
        this.populateAttributes(conf);
    } catch (final IOException e) {
        throw new MetamorphosisServerStartupException("Parse configuration failed,path=" + path, e);
    }
}

19 View Complete Implementation : PhotatoConfig.java
Copyright GNU Affero General Public License v3.0
Author : trebonius0
public static void init(String configFile) {
    try {
        Ini ini = new Ini(new File(configFile));
        serverPort = Integer.parseInt(ini.get("global", "serverPort"));
        prefixModeOnly = Boolean.parseBoolean(ini.get("index", "prefixModeOnly"));
        indexFolderName = Boolean.parseBoolean(ini.get("index", "indexFolderName"));
        useParallelPicturesGeneration = Boolean.parseBoolean(ini.get("thumbnail", "useParallelPicturesGeneration"));
        forceExifToolsDownload = Boolean.parseBoolean(ini.get("global", "forceExifToolsDownload"));
        forceExifToolsDownload = Boolean.parseBoolean(ini.get("global", "forceExifToolsDownload"));
        addressElementsCount = Integer.parseInt(ini.get("global", "addressElementsCount"));
        fullScreenPictureQuality = Integer.parseInt(ini.get("fullscreen", "fullScreenPictureQuality"));
        maxFullScreenPictureWitdh = Integer.parseInt(ini.get("fullscreen", "maxFullScreenPictureWitdh"));
        maxFullScreenPictureHeight = Integer.parseInt(ini.get("fullscreen", "maxFullScreenPictureHeight"));
        thumbnailHeight = Integer.parseInt(ini.get("thumbnail", "thumbnailHeight"));
        thumbnailQuality = Integer.parseInt(ini.get("thumbnail", "thumbnailQuality"));
    } catch (Exception ex) {
        throw new IllegalArgumentException("Incorrect config file : " + configFile + " - " + ex);
    }
}

19 View Complete Implementation : MetaConfig.java
Copyright Apache License 2.0
Author : killme2008
private Ini createIni(final File file) throws IOException, InvalidFileFormatException {
    final Ini conf = new Ini(file);
    this.lastModified = file.lastModified();
    this.configFileChecksum = org.apache.commons.io.FileUtils.checksumCRC32(file);
    this.propertyChangeSupport.firePropertyChange("configFileChecksum", null, null);
    return conf;
}

19 View Complete Implementation : FileBackedStateStorage.java
Copyright Apache License 2.0
Author : RoboZonky
@Override
public Stream<String> getKeys(final String section) {
    final Ini internalState = getState();
    if (internalState.containsKey(section)) {
        return internalState.get(section).keySet().stream();
    } else {
        return Stream.empty();
    }
}

19 View Complete Implementation : AppPreferences.java
Copyright GNU General Public License v3.0
Author : jub77
private static void save(Ini ini) throws IOException {
    String homeDir = getSaveDirectory();
    if (homeDir != null) {
        File propsFile = new File(homeDir, PREFERENCES_NAME);
        ini.store(propsFile);
    }
}

19 View Complete Implementation : Config.java
Copyright MIT License
Author : malikzh
public clreplaced Config {

    protected Ini ini = null;

    public Config(String fileName) throws IOException {
        ini = new Ini(new File(fileName));
    }

    public Config() {
    }

    public String get(String sectionName, String optionName, String defaultValue) {
        if (ini == null) {
            return defaultValue;
        }
        String value = ini.get(sectionName, optionName);
        if (value == null) {
            value = defaultValue;
        }
        return value;
    }
}

19 View Complete Implementation : EntitiesDataReader.java
Copyright MIT License
Author : Fundynamic
public EnreplacediesData fromResource(InputStream inputStream) {
    try {
        if (inputStream == null)
            throw new IllegalArgumentException("Unable to read from null stream");
        EnreplacediesData enreplacediesData = createNewEnreplacediesData();
        Ini ini = new Ini(inputStream);
        readSounds(enreplacediesData, ini);
        readWeapons(enreplacediesData, ini);
        readExplosions(enreplacediesData, ini);
        readSuperPowers(enreplacediesData, ini);
        readUnits(enreplacediesData, ini);
        readStructures(enreplacediesData, ini);
        return enreplacediesData;
    } catch (IOException | SlickException e) {
        throw new IllegalStateException("Unable to read rules.ini", e);
    }
}

19 View Complete Implementation : HgConfigFiles.java
Copyright Apache License 2.0
Author : apache
/**
 * Loads Repository configuration file  <repo>/.hg/hgrc on all platforms
 */
private Ini loadRepoHgrcFile(File dir) {
    // NOI18N
    String filePath = dir.getAbsolutePath() + File.separator + HG_REPO_DIR + File.separator + HG_RC_FILE;
    configFileName = HG_RC_FILE;
    File file = FileUtil.normalizeFile(new File(filePath));
    Ini system = null;
    system = createIni(file);
    if (system == null) {
        system = createIni();
        // NOI18N
        Mercurial.LOG.log(Level.FINE, "Could not load the file " + filePath + ". Falling back on hg defaults.");
    }
    return system;
}

19 View Complete Implementation : MetaConfig.java
Copyright Apache License 2.0
Author : killme2008
protected void populateAttributes(final Ini conf) {
    this.populateSystemConf(conf);
    this.populateZookeeperConfig(conf);
    this.populateTopicsConfig(conf);
}

19 View Complete Implementation : AppPreferences.java
Copyright GNU General Public License v3.0
Author : jub77
/**
 * Application preferences.
 *
 * @author jub
 */
public final clreplaced AppPreferences {

    private static final String PREFERENCES_NAME = ".grafikonrc";

    private static Ini instance = null;

    private static IniConfig configInstance = null;

    private AppPreferences() {
    }

    public static synchronized IniConfig getPreferences() throws IOException {
        if (configInstance == null) {
            instance = new Ini();
            instance.getConfig().setEscape(false);
            instance.getConfig().setEmptySection(true);
            load(instance);
            configInstance = new IniConfigIni4j(instance);
        }
        return configInstance;
    }

    public static synchronized void storePreferences() throws IOException {
        if (instance != null) {
            save(instance);
        }
    }

    private static void load(Ini ini) throws IOException {
        String homeDir = getSaveDirectory();
        if (homeDir != null) {
            File propsFile = new File(homeDir, PREFERENCES_NAME);
            if (propsFile.exists()) {
                ini.load(propsFile);
            }
        }
    }

    private static void save(Ini ini) throws IOException {
        String homeDir = getSaveDirectory();
        if (homeDir != null) {
            File propsFile = new File(homeDir, PREFERENCES_NAME);
            ini.store(propsFile);
        }
    }

    private static String getSaveDirectory() {
        return System.getProperty("user.home");
    }
}

19 View Complete Implementation : SvnConfigFiles.java
Copyright Apache License 2.0
Author : apache
private Ini.Section getSection(Ini ini, String key, boolean create) {
    Ini.Section section = ini.get(key);
    if (section == null) {
        return ini.add(key);
    }
    return section;
}

19 View Complete Implementation : IniEntity.java
Copyright MIT License
Author : nuls-io
/**
 * @author Niels
 */
public clreplaced IniEnreplacedy {

    private final Ini ini;

    public IniEnreplacedy(Ini ini) {
        this.ini = ini;
    }

    public String getCfgValue(String section, String key) throws Exception {
        Profile.Section ps = ini.get(section);
        if (null == ps) {
            throw new Exception("CONFIGURATION_ITEM_DOES_NOT_EXIST");
        }
        String value = ps.get(key);
        if (StringUtils.isBlank(value)) {
            throw new Exception("CONFIGURATION_ITEM_DOES_NOT_EXIST");
        }
        return value;
    }

    public <T> T getCfgValue(String section, String key, T defaultValue) {
        Profile.Section ps = ini.get(section);
        if (null == ps) {
            return defaultValue;
        }
        String value = ps.get(key);
        if (StringUtils.isBlank(value)) {
            return defaultValue;
        }
        return getValueByType(value, defaultValue);
    }

    protected static <T> T getValueByType(String value, T defaultValue) {
        if (defaultValue instanceof Integer) {
            return (T) ((Integer) Integer.parseInt(value));
        } else if (defaultValue instanceof Long) {
            return (T) ((Long) Long.parseLong(value));
        } else if (defaultValue instanceof Float) {
            return (T) ((Float) Float.parseFloat(value));
        } else if (defaultValue instanceof Double) {
            return (T) ((Double) Double.parseDouble(value));
        } else if (defaultValue instanceof Boolean) {
            return (T) ((Boolean) Boolean.parseBoolean(value));
        }
        return (T) value;
    }

    public Profile.Section getSection(String section) throws Exception {
        Profile.Section ps = ini.get(section);
        if (null == ps) {
            throw new Exception("CONFIGURATION_ITEM_DOES_NOT_EXIST");
        }
        return ps;
    }

    public List<String> getSectionList() {
        Set<Map.Entry<String, Profile.Section>> entrySet = ini.entrySet();
        List<String> list = new ArrayList<>();
        for (Map.Entry<String, Profile.Section> entry : entrySet) {
            list.add(entry.getKey());
        }
        return list;
    }

    @Override
    public String toString() {
        return ini.toString();
    }
}

18 View Complete Implementation : EntitiesDataReader.java
Copyright MIT License
Author : Fundynamic
private void readSounds(EnreplacediesData enreplacediesData, Ini ini) throws SlickException {
    Profile.Section sounds = ini.get("SOUNDS");
    if (sounds == null)
        return;
    String[] strings = sounds.childrenNames();
    for (String id : strings) {
        Profile.Section struct = sounds.getChild(id);
        enreplacediesData.addSound(id, struct.get(INI_KEYWORD_FILE, String.clreplaced));
    }
}

18 View Complete Implementation : IniScenarioFactory.java
Copyright MIT License
Author : Fundynamic
public Player getCpuPlayer(Ini ini) {
    Player cpu = new Player("CPU", Faction.RED);
    Profile.Section iniHuman = ini.get("CPU");
    int startingCredits = iniHuman.get("Credits", Integer.clreplaced, 2000);
    cpu.setCredits(startingCredits);
    return cpu;
}

18 View Complete Implementation : IniUtil.java
Copyright Apache License 2.0
Author : geekidea
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;
}

18 View Complete Implementation : AppPreferences.java
Copyright GNU General Public License v3.0
Author : jub77
private static void load(Ini ini) throws IOException {
    String homeDir = getSaveDirectory();
    if (homeDir != null) {
        File propsFile = new File(homeDir, PREFERENCES_NAME);
        if (propsFile.exists()) {
            ini.load(propsFile);
        }
    }
}

18 View Complete Implementation : IniConfigSectionIni4j.java
Copyright GNU General Public License v3.0
Author : jub77
public clreplaced IniConfigSectionIni4j implements IniConfigSection {

    private final Ini ini;

    private final Section section;

    public IniConfigSectionIni4j(Ini ini, Section section) {
        this.ini = ini;
        this.section = section;
    }

    @Override
    public void put(String key, String value) {
        section.put(key, value);
    }

    @Override
    public String get(String key) {
        return section.get(key);
    }

    @Override
    public <T> T get(String key, Clreplaced<T> clazz, T defaultValue) {
        return section.get(key, clazz, defaultValue);
    }

    @Override
    public void removeSection() {
        ini.remove(section);
    }

    @Override
    public void clear() {
        section.clear();
    }

    @Override
    public void putAll(Map<String, String> value) {
        section.putAll(value);
    }

    @Override
    public Collection<Entry<String, String>> entrySet() {
        return section.entrySet();
    }

    @Override
    public void copyToMap(Map<String, String> map) {
        map.putAll(section);
    }

    @Override
    public void add(String key, String value) {
        section.add(key, value);
    }

    @Override
    public String get(String key, String defaultValue) {
        return section.get(key, defaultValue);
    }

    @Override
    public List<String> getAll(String key) {
        return section.getAll(key);
    }

    @Override
    public void put(String key, Object value) {
        section.put(key, value);
    }

    @Override
    public void remove(String key) {
        section.remove(key);
    }

    @Override
    public boolean containsKey(String key) {
        return section.containsKey(key);
    }
}

18 View Complete Implementation : HgConfigFiles.java
Copyright Apache License 2.0
Author : apache
/**
 * Loads user and system configuration files
 * The settings are loaded and merged together in the folowing order:
 * <ol>
 *  <li> The per-user configuration file, Unix: ~/.hgrc, Windows: %USERPROFILE%\Mercurial.ini
 *  <li> The system-wide file, Unix: /etc/mercurial/hgrc, Windows: Mercurial_Install\Mercurial.ini
 * </ol>
 *
 * @param fileName the file name
 * @return an Ini instance holding the configuration file.
 */
private Ini loadSystemAndGlobalFile(String[] fileNames) {
    // config files from userdir
    Ini system = null;
    for (String userConfigFileName : fileNames) {
        String filePath = getUserConfigPath() + userConfigFileName;
        File file = FileUtil.normalizeFile(new File(filePath));
        system = createIni(file);
        if (system != null) {
            configFileName = userConfigFileName;
            break;
        }
        // NOI18N
        Mercurial.LOG.log(Level.INFO, "Could not load the file {0}.", filePath);
    }
    if (system == null) {
        configFileName = fileNames[0];
        system = createIni();
        // NOI18N
        Mercurial.LOG.log(Level.INFO, "Could not load the user config file. Falling back on hg defaults.");
    }
    Ini global = null;
    File gFile = FileUtil.normalizeFile(new File(getGlobalConfigPath() + File.separator + fileNames[0]));
    // NOI18N
    global = createIni(gFile);
    if (global != null) {
        merge(global, system);
    }
    return system;
}

18 View Complete Implementation : HgConfigFiles.java
Copyright Apache License 2.0
Author : apache
/**
 * Handles the Mercurial <b>hgrc</b> configuration file.</br>
 *
 * @author Padraig O'Briain
 */
public clreplaced HgConfigFiles {

    // NOI18N
    public static final String HG_EXTENSIONS = "extensions";

    // NOI18N
    public static final String HG_EXTENSIONS_HGK = "hgext.hgk";

    // NOI18N
    public static final String HG_EXTENSIONS_FETCH = "fetch";

    // NOI18N
    public static final String HG_UI_SECTION = "ui";

    // NOI18N
    public static final String HG_USERNAME = "username";

    // NOI18N
    public static final String HG_PATHS_SECTION = "paths";

    // NOI18N
    public static final String HG_DEFAULT_PUSH = "default-push";

    // NOI18N
    public static final String HG_DEFAULT_PUSH_VALUE = "default-push";

    // NOI18N
    public static final String HG_DEFAULT_PULL = "default-pull";

    // NOI18N
    public static final String HG_DEFAULT_PULL_VALUE = "default";

    /**
     * The HgConfigFiles instance for user and system defaults
     */
    private static HgConfigFiles instance;

    /**
     * the Ini instance holding the configuration values stored in the <b>hgrc</b>
     * file used by the Mercurial module
     */
    private Ini hgrc = null;

    /**
     * The repository directory if this instance is for a repository
     */
    private File dir;

    // NOI18N
    public static final String HG_RC_FILE = "hgrc";

    // NOI18N
    public static final String HG_REPO_DIR = ".hg";

    // NOI18N
    private static final String WINDOWS_HG_RC_FILE = "Mercurial.ini";

    // NOI18N
    private static final String WINDOWS_DEFAULT_MECURIAL_INI_PATH = "C:\\Mercurial\\Mercurial.ini";

    private boolean bIsProjectConfig;

    private IOException initException;

    /**
     * fileName of the configuration file
     */
    private String configFileName;

    /**
     * Creates a new instance
     */
    private HgConfigFiles() {
        bIsProjectConfig = false;
        // get the system hgrc file
        // escaping characters disabled
        Config.getGlobal().setEscape(false);
        if (Utilities.isWindows()) {
            // on windows both Mercurial.ini and .hgrc are allowed
            // NOI18N
            hgrc = loadSystemAndGlobalFile(new String[] { WINDOWS_HG_RC_FILE, "." + HG_RC_FILE });
        } else {
            hgrc = loadSystemAndGlobalFile(new String[] { HG_RC_FILE });
        }
    }

    /**
     * Returns a singleton instance
     *
     * @return the HgConfiles instance
     */
    public static HgConfigFiles getSysInstance() {
        if (instance == null) {
            instance = new HgConfigFiles();
        }
        return instance;
    }

    public HgConfigFiles(File file) {
        // escaping characters disabled
        Config.getGlobal().setEscape(false);
        bIsProjectConfig = true;
        dir = file;
        // <repository>/.hg/hgrc on all platforms
        hgrc = loadRepoHgrcFile(file);
    }

    public IOException getException() {
        return initException;
    }

    public void setProperty(String name, String value) {
        if (name.equals(HG_USERNAME)) {
            setProperty(HG_UI_SECTION, HG_USERNAME, value);
        } else if (name.equals(HG_DEFAULT_PUSH)) {
            setProperty(HG_PATHS_SECTION, HG_DEFAULT_PUSH_VALUE, removeTrailingBackslahes(value));
            HgRepositoryContextCache.getInstance().reset();
        } else if (name.equals(HG_DEFAULT_PULL)) {
            setProperty(HG_PATHS_SECTION, HG_DEFAULT_PULL_VALUE, removeTrailingBackslahes(value));
            HgRepositoryContextCache.getInstance().reset();
        } else if (name.equals(HG_EXTENSIONS_HGK)) {
            // Allow hgext.hgk to be set to some other user defined value if required
            if (getProperty(HG_EXTENSIONS, HG_EXTENSIONS_HGK).equals("")) {
                setProperty(HG_EXTENSIONS, HG_EXTENSIONS_HGK, value, true);
            }
        } else if (name.equals(HG_EXTENSIONS_FETCH)) {
            // Allow fetch to be set to some other user defined value if required
            if (getProperty(HG_EXTENSIONS, HG_EXTENSIONS_FETCH).equals("")) {
                setProperty(HG_EXTENSIONS, HG_EXTENSIONS_FETCH, value, true);
            }
        }
    }

    public void setProperty(String section, String name, String value, boolean allowEmpty) {
        if (!allowEmpty) {
            if (value.length() == 0) {
                removeProperty(section, name);
            } else {
                Ini.Section inisection = getSection(hgrc, section, true);
                inisection.put(name, value);
            }
        } else {
            Ini.Section inisection = getSection(hgrc, section, true);
            inisection.put(name, value);
        }
        if (!bIsProjectConfig && Utilities.isWindows()) {
            storeIni(hgrc, configFileName);
        } else {
            storeIni(hgrc, configFileName);
        }
    }

    public void setProperty(String section, String name, String value) {
        setProperty(section, name, value, false);
    }

    public void setUserName(String value) {
        setProperty(HG_UI_SECTION, HG_USERNAME, value);
    }

    public String getSysUserName() {
        return getUserName(true);
    }

    public String getSysPushPath() {
        return getDefaultPush(true);
    }

    public String getSysPullPath() {
        return getDefaultPull(true);
    }

    public Properties getProperties(String section) {
        Ini.Section inisection = getSection(hgrc, section, false);
        Properties props = new Properties();
        if (inisection != null) {
            Set<String> keys = inisection.keySet();
            for (String key : keys) {
                props.setProperty(key, inisection.get(key));
            }
        }
        return props;
    }

    public void clearProperties(String section) {
        Ini.Section inisection = getSection(hgrc, section, false);
        if (inisection != null) {
            inisection.clear();
            if (!bIsProjectConfig && Utilities.isWindows()) {
                storeIni(hgrc, configFileName);
            } else {
                storeIni(hgrc, configFileName);
            }
        }
    }

    public void removeProperty(String section, String name) {
        Ini.Section inisection = getSection(hgrc, section, false);
        if (inisection != null) {
            inisection.remove(name);
            if (!bIsProjectConfig && Utilities.isWindows()) {
                storeIni(hgrc, configFileName);
            } else {
                storeIni(hgrc, configFileName);
            }
        }
    }

    public String getDefaultPull(Boolean reload) {
        if (reload) {
            doReload();
        }
        return getProperty(HG_PATHS_SECTION, HG_DEFAULT_PULL_VALUE);
    }

    public String getDefaultPush(Boolean reload) {
        if (reload) {
            doReload();
        }
        String value = getProperty(HG_PATHS_SECTION, HG_DEFAULT_PUSH);
        if (value.length() == 0) {
            value = getProperty(HG_PATHS_SECTION, HG_DEFAULT_PULL_VALUE);
        }
        return value;
    }

    public String getUserName(Boolean reload) {
        if (reload) {
            doReload();
        }
        return getProperty(HG_UI_SECTION, HG_USERNAME);
    }

    public String getProperty(String section, String name) {
        Ini.Section inisection = getSection(hgrc, section, true);
        String value = inisection.get(name);
        // NOI18N
        return value != null ? value : "";
    }

    public boolean containsProperty(String section, String name) {
        Ini.Section inisection = getSection(hgrc, section, true);
        return inisection.containsKey(name);
    }

    public void doReload() {
        if (dir == null) {
            if (!bIsProjectConfig && Utilities.isWindows()) {
                // on windows both Mercurial.ini and .hgrc are allowed
                // NOI18N
                hgrc = loadSystemAndGlobalFile(new String[] { WINDOWS_HG_RC_FILE, "." + HG_RC_FILE });
            } else {
                hgrc = loadSystemAndGlobalFile(new String[] { HG_RC_FILE });
            }
        } else {
            hgrc = loadRepoHgrcFile(dir);
        }
    }

    private Ini.Section getSection(Ini ini, String key, boolean create) {
        Ini.Section section = ini.get(key);
        if (section == null && create) {
            return ini.add(key);
        }
        return section;
    }

    private void storeIni(Ini ini, String iniFile) {
        replacedert initException == null;
        BufferedOutputStream bos = null;
        try {
            String filePath;
            if (dir != null) {
                // NOI18N
                filePath = dir.getAbsolutePath() + File.separator + HG_REPO_DIR + File.separator + iniFile;
            } else {
                filePath = getUserConfigPath() + iniFile;
            }
            File file = FileUtil.normalizeFile(new File(filePath));
            file.getParentFile().mkdirs();
            ini.store(bos = new BufferedOutputStream(new FileOutputStream(file)));
        } catch (IOException ex) {
            Mercurial.LOG.log(Level.INFO, null, ex);
        } finally {
            if (bos != null) {
                try {
                    bos.close();
                } catch (IOException ex) {
                    Mercurial.LOG.log(Level.INFO, null, ex);
                }
            }
        }
    }

    /**
     * Returns a default ini instance, with clreplacedloader issue workaround (#141364)
     * @return ini instance
     */
    private Ini createIni() {
        return createIni(null);
    }

    /**
     * Returns an ini instance for given file, with clreplacedloader issue workaround (#141364)
     * @param file ini file being parsed. If null then a default ini will be created.
     * @return ini instance for the given file
     */
    private Ini createIni(File file) {
        ClreplacedLoader cl = Thread.currentThread().getContextClreplacedLoader();
        Thread.currentThread().setContextClreplacedLoader(Mercurial.clreplaced.getClreplacedLoader());
        try {
            if (file == null) {
                return new Ini();
            } else {
                return new Ini(new FileReader(file));
            }
        } catch (FileNotFoundException ex) {
        // ignore
        } catch (InvalidFileFormatException ex) {
            // NOI18N
            Mercurial.LOG.log(Level.INFO, "Cannot parse configuration file", ex);
            initException = ex;
        } catch (IOException ex) {
            Mercurial.LOG.log(Level.INFO, null, ex);
        } catch (Exception ex) {
            // NOI18N
            Mercurial.LOG.log(Level.INFO, "Cannot parse configuration file", ex);
            initException = new IOException(ex);
        } finally {
            Thread.currentThread().setContextClreplacedLoader(cl);
        }
        return null;
    }

    /**
     * Loads Repository configuration file  <repo>/.hg/hgrc on all platforms
     */
    private Ini loadRepoHgrcFile(File dir) {
        // NOI18N
        String filePath = dir.getAbsolutePath() + File.separator + HG_REPO_DIR + File.separator + HG_RC_FILE;
        configFileName = HG_RC_FILE;
        File file = FileUtil.normalizeFile(new File(filePath));
        Ini system = null;
        system = createIni(file);
        if (system == null) {
            system = createIni();
            // NOI18N
            Mercurial.LOG.log(Level.FINE, "Could not load the file " + filePath + ". Falling back on hg defaults.");
        }
        return system;
    }

    /**
     * Loads user and system configuration files
     * The settings are loaded and merged together in the folowing order:
     * <ol>
     *  <li> The per-user configuration file, Unix: ~/.hgrc, Windows: %USERPROFILE%\Mercurial.ini
     *  <li> The system-wide file, Unix: /etc/mercurial/hgrc, Windows: Mercurial_Install\Mercurial.ini
     * </ol>
     *
     * @param fileName the file name
     * @return an Ini instance holding the configuration file.
     */
    private Ini loadSystemAndGlobalFile(String[] fileNames) {
        // config files from userdir
        Ini system = null;
        for (String userConfigFileName : fileNames) {
            String filePath = getUserConfigPath() + userConfigFileName;
            File file = FileUtil.normalizeFile(new File(filePath));
            system = createIni(file);
            if (system != null) {
                configFileName = userConfigFileName;
                break;
            }
            // NOI18N
            Mercurial.LOG.log(Level.INFO, "Could not load the file {0}.", filePath);
        }
        if (system == null) {
            configFileName = fileNames[0];
            system = createIni();
            // NOI18N
            Mercurial.LOG.log(Level.INFO, "Could not load the user config file. Falling back on hg defaults.");
        }
        Ini global = null;
        File gFile = FileUtil.normalizeFile(new File(getGlobalConfigPath() + File.separator + fileNames[0]));
        // NOI18N
        global = createIni(gFile);
        if (global != null) {
            merge(global, system);
        }
        return system;
    }

    /**
     * Merges only sections/keys/values into target which are not already present in source
     *
     * @param source the source ini file
     * @param target the target ini file in which the values from the source file are going to be merged
     */
    private void merge(Ini source, Ini target) {
        for (Iterator<String> itSections = source.keySet().iterator(); itSections.hasNext(); ) {
            String sectionName = itSections.next();
            Ini.Section sourceSection = source.get(sectionName);
            Ini.Section targetSection = target.get(sectionName);
            if (targetSection == null) {
                targetSection = target.add(sectionName);
            }
            for (Iterator<String> itVariables = sourceSection.keySet().iterator(); itVariables.hasNext(); ) {
                String key = itVariables.next();
                if (!targetSection.containsKey(key)) {
                    targetSection.put(key, sourceSection.get(key));
                }
            }
        }
    }

    /**
     * Return the path for the user command lines configuration directory
     */
    private static String getUserConfigPath() {
        if (Utilities.isUnix()) {
            // NOI18N
            String path = System.getProperty("user.home");
            // NOI18N
            return path + "/.";
        } else if (Utilities.isWindows()) {
            String userConfigPath = getUSERPROFILE();
            // NOI18N
            return userConfigPath.equals("") ? "" : userConfigPath + File.separator;
        }
        // NOI18N
        return "";
    }

    /**
     * Return the path for the systemwide command lines configuration directory
     */
    private static String getGlobalConfigPath() {
        if (Utilities.isUnix()) {
            // NOI18N
            return "/etc/mercurial";
        } else if (Utilities.isWindows()) {
            // <Mercurial Install>\Mercurial.ini
            String mercurialPath = HgModuleConfig.getDefault().getExecutableBinaryPath();
            if (mercurialPath != null && !mercurialPath.equals("")) {
                File ini = new File(mercurialPath, WINDOWS_HG_RC_FILE);
                if (ini != null && ini.exists() && ini.canRead()) {
                    return ini.getParentFile().getAbsolutePath();
                }
            }
            // C:\Mercurial\Mercurial.ini
            // NOI18N
            File ini = new File(WINDOWS_DEFAULT_MECURIAL_INI_PATH);
            if (ini != null && ini.exists() && ini.canRead()) {
                return ini.getParentFile().getAbsolutePath();
            }
        }
        // NOI18N
        return "";
    }

    private static String getUSERPROFILE() {
        if (!Utilities.isWindows())
            return null;
        // NOI18N
        String userprofile = "";
        // NOI18N
        userprofile = System.getenv("USERPROFILE");
        // NOI18N
        return userprofile != null ? userprofile : "";
    }

    private static String removeTrailingBackslahes(String value) {
        while (value.endsWith("\\")) {
            value = value.substring(0, value.length() - 1);
        }
        return value;
    }
}

18 View Complete Implementation : SvnConfigFiles.java
Copyright Apache License 2.0
Author : apache
/**
 * Handles the Subversions <b>servers</b> and <b>config</b> configuration files.</br>
 * Everytime the singleton instance is created are the values from the commandline clients
 * configuration directory merged into the Subversion modules configuration files.
 * (registry on windows are ignored).
 * Already present proxy setting values wan't be changed,
 * the remaining values are always taken from the commandline clients configuration files.
 * The only exception is the 'store-auth-creds' key, which is always set to 'no'.
 *
 * @author Tomas Stupka
 */
public clreplaced SvnConfigFiles {

    /**
     * the only SvnConfigFiles instance
     */
    private static SvnConfigFiles instance;

    /**
     * the Ini instance holding the configuration values stored in the <b>servers</b>
     * file used by the Subversion module
     */
    private Ini svnServers = null;

    /**
     * the Ini instance holding the configuration values stored in the <b>config</b>
     * file used by the Subversion module
     */
    private Ini config = null;

    // NOI18N
    private static final String UNIX_CONFIG_DIR = ".subversion/";

    // NOI18N
    private static final String GROUPS_SECTION = "groups";

    // NOI18N
    private static final String GLOBAL_SECTION = "global";

    private static final String WINDOWS_USER_APPDATA = getAPPDATA();

    // NOI18N
    private static final String WINDOWS_CONFIG_DIR = WINDOWS_USER_APPDATA + "\\Subversion";

    // NOI18N
    private static final String WINDOWS_GLOBAL_CONFIG_DIR = getGlobalAPPDATA() + "\\Subversion";

    private static final List<String> DEFAULT_GLOBAL_IGNORES = // NOI18N
    parseGlobalIgnores("*.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store");

    // NOI18N
    private static final boolean DO_NOT_SAVE_PreplacedPHRASE = Boolean.getBoolean("versioning.subversion.noPreplacedphraseInConfig");

    private String recentUrl;

    private interface IniFilePatcher {

        void patch(Ini file);
    }

    /**
     * The value for the 'store-auth-creds' key in the config cofiguration file is alway set to 'no'
     * so the commandline client wan't create a file holding the authentication credentials when
     * a svn command is called. The reason for this is that the Subverion module holds the credentials
     * in files with the same format as the commandline client but with a different name.
     *
     * Also sets preplacedword-stores to empty value. We currently handle preplacedword stores poorly and occasionally non-empty values cause a deadlock (see #178122).
     */
    private clreplaced ConfigIniFilePatcher implements IniFilePatcher {

        @Override
        public void patch(Ini file) {
            // patch store-auth-creds to "no"
            // NOI18N
            Ini.Section auth = (Ini.Section) file.get("auth");
            if (auth == null) {
                // NOI18N
                auth = file.add("auth");
            }
            // NOI18N
            auth.put("store-auth-creds", "yes");
            // NOI18N
            auth.put("store-preplacedwords", "no");
            // NOI18N
            auth.put("preplacedword-stores", "");
        }
    }

    /**
     * Creates a new instance
     */
    private SvnConfigFiles() {
        ClreplacedLoader cl = Thread.currentThread().getContextClreplacedLoader();
        Thread.currentThread().setContextClreplacedLoader(Subversion.clreplaced.getClreplacedLoader());
        try {
            // do not escape characters
            Config.getGlobal().setEscape(false);
            // copy config file
            // NOI18N
            config = copyConfigFileToIDEConfigDir("config", new ConfigIniFilePatcher());
            // get the system servers file
            svnServers = loadSystemIniFile("servers");
        } finally {
            Thread.currentThread().setContextClreplacedLoader(cl);
        }
    // SvnModuleConfig.getDefault().getPreferences().addPreferenceChangeListener(this);
    }

    /**
     * Returns a singleton instance.
     *
     * @return the SvnConfigFiles instance
     */
    public static synchronized SvnConfigFiles getInstance() {
        // T9Y - singleton is not required - always create new instance of this clreplaced
        String t9yUserConfigPath = System.getProperty("netbeans.t9y.svn.user.config.path");
        if (t9yUserConfigPath != null && t9yUserConfigPath.length() > 0) {
            // make sure that new instance will be created
            instance = null;
        }
        if (instance == null) {
            instance = new SvnConfigFiles();
        }
        return instance;
    }

    public void reset() {
        // force rewrite
        recentUrl = null;
    }

    /**
     * Stores the cert file and preplacedword, proxy host, port, username and preplacedword for the given
     * {@link SVNUrl} in the
     * <b>servers</b> file used by the Subversion module.
     *
     * It returns an instance of config file that should be deleted as soon as possible
     * because it contains sensitive private data such as preplacedwords or preplacedphrases.
     *
     * @param host the host
     */
    public File storeSvnServersSettings(SVNUrl url, ConnectionType connType) {
        // NOI18N
        replacedert url != null : "can\'t do anything for a null host";
        File sensitiveConfigFile = null;
        if (!(// NOI18N
        url.getProtocol().startsWith("http") || // NOI18N
        url.getProtocol().startsWith("https") || // NOI18N
        url.getProtocol().startsWith("svn+"))) {
            // we need the settings only for remote http and https repositories
            return sensitiveConfigFile;
        }
        boolean changes = false;
        Ini nbServers = new Ini();
        Ini.Section nbGlobalSection = nbServers.add(GLOBAL_SECTION);
        String repositoryUrl = url.toString();
        changes = !repositoryUrl.equals(recentUrl);
        if (changes) {
            RepositoryConnection rc = SvnModuleConfig.getDefault().getRepositoryConnection(repositoryUrl);
            if (rc != null && url.getProtocol().startsWith("svn+")) {
                // NOI18N
                // must set tunnel info for the repository url
                if (connType == ConnectionType.svnkit) {
                    // hack for svnkit and ssh
                    // ssh port is read only from ssh tunnel info and considered valid only when usernam and preplacedword are not empty
                    // see implementation in SvnKit: org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager.getDefaultSSHAuthentication()
                    // weird and ugly
                    setExternalCommand("ssh", rc.getSshPortNumber() > 0 ? "ssh -p " + rc.getSshPortNumber() + " -P " + rc.getSshPortNumber() + " -l user -pw preplacedword" : "");
                    // NOI18N
                    nbGlobalSection.put("store-auth-creds", "yes");
                    // NOI18N
                    nbGlobalSection.put("store-preplacedwords", "no");
                } else {
                    setExternalCommand(SvnUtils.getTunnelName(url.getProtocol()), rc.getExternalCommand());
                }
            }
            boolean hasPreplacedphrase = false;
            if (url.getProtocol().startsWith("https")) {
                hasPreplacedphrase = setSSLCert(rc, nbGlobalSection);
            }
            hasPreplacedphrase = setProxy(url, nbGlobalSection) | hasPreplacedphrase;
            // NOI18N
            File configFile = storeIni(nbServers, "servers");
            recentUrl = url.toString();
            if (hasPreplacedphrase) {
                sensitiveConfigFile = configFile;
                // must be regenerated on next run
                recentUrl = null;
            }
        }
        return sensitiveConfigFile;
    }

    private boolean setSSLCert(RepositoryConnection rc, Ini.Section nbGlobalSection) {
        if (rc == null) {
            return false;
        }
        String certFile = rc.getCertFile();
        if (certFile == null || certFile.equals("")) {
            return false;
        }
        char[] certPreplacedwordChars = rc.getCertPreplacedword();
        // NOI18N
        String certPreplacedword = certPreplacedwordChars == null ? "" : new String(certPreplacedwordChars);
        if (certPreplacedword.equals("")) {
            // NOI18N
            return false;
        }
        nbGlobalSection.put("ssl-client-cert-file", certFile);
        if (!DO_NOT_SAVE_PreplacedPHRASE) {
            nbGlobalSection.put("ssl-client-cert-preplacedword", certPreplacedword);
            return true;
        }
        return false;
    }

    private boolean setProxy(SVNUrl url, Ini.Section nbGlobalSection) {
        String host = SvnUtils.ripUserFromHost(url.getHost());
        Ini.Section svnGlobalSection = svnServers.get(GLOBAL_SECTION);
        URI uri = null;
        boolean preplacedwordAdded = false;
        try {
            uri = new URI(url.toString());
        } catch (URISyntaxException ex) {
            Subversion.LOG.log(Level.INFO, null, ex);
            return preplacedwordAdded;
        }
        String proxyHost = NetworkSettings.getProxyHost(uri);
        // check DIRECT connection
        if (proxyHost != null && proxyHost.length() > 0) {
            String proxyPort = NetworkSettings.getProxyPort(uri);
            replacedert proxyPort != null;
            // NOI18N
            nbGlobalSection.put("http-proxy-host", proxyHost);
            // NOI18N
            nbGlobalSection.put("http-proxy-port", proxyPort);
            // and the authentication
            String username = NetworkSettings.getAuthenticationUsername(uri);
            if (username != null) {
                String preplacedword = getProxyPreplacedword(NetworkSettings.getKeyForAuthenticationPreplacedword(uri));
                // NOI18N
                nbGlobalSection.put("http-proxy-username", username);
                // NOI18N
                nbGlobalSection.put("http-proxy-preplacedword", preplacedword);
                preplacedwordAdded = true;
            }
        }
        // check if there are also some no proxy settings
        // we should get from the original svn servers file
        mergeNonProxyKeys(host, svnGlobalSection, nbGlobalSection);
        return preplacedwordAdded;
    }

    private void mergeNonProxyKeys(String host, Ini.Section svnGlobalSection, Ini.Section nbGlobalSection) {
        if (svnGlobalSection != null) {
            // if there is a global section, than get the no proxy settings
            mergeNonProxyKeys(svnGlobalSection, nbGlobalSection);
        }
        Ini.Section svnHostGroup = getServerGroup(host);
        if (svnHostGroup != null) {
            // if there is a section for the given host, than get the no proxy settings
            mergeNonProxyKeys(svnHostGroup, nbGlobalSection);
        }
    }

    private void mergeNonProxyKeys(Ini.Section source, Ini.Section target) {
        for (String key : source.keySet()) {
            if (!isProxyConfigurationKey(key)) {
                target.put(key, source.get(key));
            }
        }
    }

    public void setExternalCommand(String tunnelName, String command) {
        if (command == null) {
            return;
        }
        if (Utilities.isWindows()) {
            // tunnel command should contain forward slashes even on windows
            // NOI18N
            command = command.replace("\\", "/");
        }
        Ini.Section tunnels = getSection(config, "tunnels", true);
        tunnels.put(tunnelName, command);
        // NOI18N
        storeIni(config, "config");
    }

    public String getExternalCommand(String tunnelName) {
        Ini.Section tunnels = getSection(config, "tunnels", true);
        String cmd = tunnels.get(tunnelName);
        return cmd != null ? cmd : "";
    }

    private Ini.Section getSection(Ini ini, String key, boolean create) {
        Ini.Section section = ini.get(key);
        if (section == null) {
            return ini.add(key);
        }
        return section;
    }

    private File storeIni(Ini ini, String iniFile) {
        BufferedOutputStream bos = null;
        // NOI18N
        File file = FileUtil.normalizeFile(new File(getNBConfigPath() + "/" + iniFile));
        try {
            file.getParentFile().mkdirs();
            ini.store(bos = FileUtils.createOutputStream(file));
        } catch (IOException ex) {
            Subversion.LOG.log(Level.INFO, null, ex);
        } finally {
            if (bos != null) {
                try {
                    bos.close();
                } catch (IOException ex) {
                    Subversion.LOG.log(Level.INFO, null, ex);
                }
            }
        }
        return file;
    }

    /**
     * Returns the miscellany/global-ignores setting from the config file.
     *
     * @return a list with the inore patterns
     */
    public List<String> getGlobalIgnores() {
        // NOI18N
        Ini.Section miscellany = config.get("miscellany");
        if (miscellany != null) {
            // NOI18N
            String ignores = miscellany.get("global-ignores");
            if (ignores != null && ignores.trim().length() > 0) {
                return parseGlobalIgnores(ignores);
            }
        }
        return DEFAULT_GLOBAL_IGNORES;
    }

    public String getClientCertFile(String host) {
        // NOI18N
        return getMergeValue("ssl-client-cert-file", host);
    }

    public String getClientCertPreplacedword(String host) {
        // NOI18N
        return getMergeValue("ssl-client-cert-preplacedword", host);
    }

    private String getMergeValue(String key, String host) {
        Ini.Section group = getServerGroup(host);
        if (group != null) {
            return group.get(key);
        }
        group = svnServers.get(GLOBAL_SECTION);
        if (group != null) {
            return group.get(key);
        }
        return null;
    }

    private static List<String> parseGlobalIgnores(String ignores) {
        // NOI18N
        StringTokenizer st = new StringTokenizer(ignores, " ");
        List<String> ret = new ArrayList<String>(10);
        while (st.hasMoreTokens()) {
            String entry = st.nextToken();
            if (// NOI18N
            !entry.equals(""))
                ret.add(entry);
        }
        return ret;
    }

    /**
     * Returns the path for the Sunbversion configuration dicectory used
     * by the systems Subversion commandline client.
     *
     * @return the path
     */
    public static String getUserConfigPath() {
        // T9Y - user svn config files should be changable
        String t9yUserConfigPath = System.getProperty("netbeans.t9y.svn.user.config.path");
        if (t9yUserConfigPath != null && t9yUserConfigPath.length() > 0) {
            return t9yUserConfigPath;
        }
        if (Utilities.isUnix()) {
            // NOI18N
            String path = System.getProperty("user.home");
            // NOI18N
            return path + "/" + UNIX_CONFIG_DIR;
        } else if (Utilities.isWindows()) {
            return WINDOWS_CONFIG_DIR;
        }
        // NOI18N
        return "";
    }

    /**
     * Returns the path for the Sunbversion configuration directory used
     * by the Netbeans Subversion module.
     *
     * @return the path
     */
    public static String getNBConfigPath() {
        // T9Y - nb svn confing should be changable
        String t9yNbConfigPath = System.getProperty("netbeans.t9y.svn.nb.config.path");
        if (t9yNbConfigPath != null && t9yNbConfigPath.length() > 0) {
            return t9yNbConfigPath;
        }
        String nbHome = Places.getUserDirectory().getAbsolutePath();
        // NOI18N
        return nbHome + "/config/svn/config/";
    }

    /**
     * Returns the section from the <b>servers</b> config file used by the Subversion module which
     * is holding the proxy settings for the given host
     *
     * @param host the host
     * @return the section holding the proxy settings for the given host
     */
    private Ini.Section getServerGroup(String host) {
        if (host == null || host.equals("")) {
            // NOI18N
            return null;
        }
        Ini.Section groups = svnServers.get(GROUPS_SECTION);
        if (groups != null) {
            for (Iterator<String> it = groups.keySet().iterator(); it.hasNext(); ) {
                String key = it.next();
                String value = groups.get(key);
                if (value != null) {
                    value = value.trim();
                    if (value != null && match(value, host)) {
                        return svnServers.get(key);
                    }
                }
            }
        }
        return null;
    }

    /**
     * Evaluates if the given hostaname or IP address is in the given value String.
     *
     * @param value the value String. A list of host names or IP addresses delimited by ",".
     *                          (e.g 192.168.0.1,*.168.0.1, some.domain.com, *.anything.com, ...)
     * @param host the hostname or IP address
     * @return true if the host name or IP address was found in the values String, otherwise false.
     */
    private boolean match(String value, String host) {
        // NOI18N
        String[] values = value.split(",");
        for (int i = 0; i < values.length; i++) {
            value = values[i].trim();
            if (value.equals("*") || value.equals(host)) {
                // NOI18N
                return true;
            }
            // NOI18N
            int idx = value.indexOf("*");
            if (idx > -1 && matchSegments(value, host)) {
                return true;
            }
        }
        return false;
    }

    /**
     * Evaluates if the given hostaname or IP address matches with the given value String representing
     * a hostaname or IP adress with one or more "*" wildcards in it.
     *
     * @param value the value String. A host name or IP addresse with a "*" wildcard. (e.g *.168.0.1 or *.anything.com)
     * @param host the hostname or IP address
     * @return true if the host name or IP address matches with the values String, otherwise false.
     */
    private boolean matchSegments(String value, String host) {
        value = value.replace(".", "\\.");
        value = value.replace("*", ".*");
        Matcher m = Pattern.compile(value).matcher(host);
        return m.matches();
    }

    /**
     * Copies the given configuration file from the Subversion commandline client
     * configuration directory into the configuration directory used by the Netbeans Subversion module. </br>
     */
    private Ini copyConfigFileToIDEConfigDir(String fileName, IniFilePatcher patcher) {
        Ini systemIniFile = loadSystemIniFile(fileName);
        patcher.patch(systemIniFile);
        // NOI18N
        File file = FileUtil.normalizeFile(new File(getNBConfigPath() + File.separatorChar + fileName));
        BufferedOutputStream bos = null;
        try {
            file.getParentFile().mkdirs();
            systemIniFile.store(bos = FileUtils.createOutputStream(file));
        } catch (IOException ex) {
            // should not happen
            Subversion.LOG.log(Level.INFO, null, ex);
        } finally {
            if (bos != null) {
                try {
                    bos.close();
                } catch (IOException ex) {
                    Subversion.LOG.log(Level.INFO, null, ex);
                }
            }
        }
        return systemIniFile;
    }

    /**
     * Loads the ini configuration file from the directory used by
     * the Subversion commandline client. The settings are loaded and merged together in
     * in the folowing order:
     * <ol>
     *  <li> The per-user INI files
     *  <li> The system-wide INI files
     * </ol>
     *
     * @param fileName the file name
     * @return an Ini instance holding the cofiguration file.
     */
    private Ini loadSystemIniFile(String fileName) {
        // config files from userdir
        // NOI18N
        String filePath = getUserConfigPath() + "/" + fileName;
        File file = FileUtil.normalizeFile(new File(filePath));
        Ini system = null;
        try {
            system = new Ini(new FileReader(file));
        } catch (FileNotFoundException ex) {
        // ignore
        } catch (IOException ex) {
            Subversion.LOG.log(Level.INFO, null, ex);
        } catch (Exception ex) {
            Subversion.LOG.log(Level.INFO, "exception in Ini4j, system file not loaded: " + filePath, ex);
        }
        if (system == null) {
            system = new Ini();
            // NOI18N
            Subversion.LOG.warning("Could not load the file " + filePath + ". Falling back on svn defaults.");
        }
        Ini global = null;
        try {
            // NOI18N
            global = new Ini(new FileReader(getGlobalConfigPath() + "/" + fileName));
        } catch (FileNotFoundException ex) {
        // just doesn't exist - ignore
        } catch (IOException ex) {
            Subversion.LOG.log(Level.INFO, null, ex);
        } catch (Exception ex) {
            Subversion.LOG.log(Level.INFO, "exception in Ini4j, global file not loaded: " + getGlobalConfigPath() + "/" + fileName, ex);
        }
        if (global != null) {
            merge(global, system);
        }
        return system;
    }

    /**
     * Merges only sections/keys/values into target which are not already present in source
     *
     * @param source the source ini file
     * @param target the target ini file in which the values from the source file are going to be merged
     */
    private void merge(Ini source, Ini target) {
        for (Iterator<String> itSections = source.keySet().iterator(); itSections.hasNext(); ) {
            String sectionName = itSections.next();
            Ini.Section sourceSection = source.get(sectionName);
            Ini.Section targetSection = target.get(sectionName);
            if (targetSection == null) {
                targetSection = target.add(sectionName);
            }
            for (Iterator<String> itVariables = sourceSection.keySet().iterator(); itVariables.hasNext(); ) {
                String key = itVariables.next();
                if (!targetSection.containsKey(key)) {
                    targetSection.put(key, sourceSection.get(key));
                }
            }
        }
    }

    /**
     * Evaluates if the value stored under the key is a proxy setting value.
     *
     * @param key the key
     * @return true if the value stored under the key is a proxy setting value. Otherwise false
     */
    private boolean isProxyConfigurationKey(String key) {
        return // NOI18N
        key.equals("http-proxy-host") || // NOI18N
        key.equals("http-proxy-port") || // NOI18N
        key.equals("http-proxy-username") || // NOI18N
        key.equals("http-proxy-preplacedword") || // NOI18N
        key.equals("http-proxy-exceptions");
    }

    /**
     * Return the path for the systemwide command lines configuration directory
     */
    private static String getGlobalConfigPath() {
        if (Utilities.isUnix()) {
            // NOI18N
            return "/etc/subversion";
        } else if (Utilities.isWindows()) {
            return WINDOWS_GLOBAL_CONFIG_DIR;
        }
        // NOI18N
        return "";
    }

    /**
     * Returns the value for the %APPDATA% env variable on windows
     */
    private static String getAPPDATA() {
        String appdata = "";
        if (Utilities.isWindows()) {
            // NOI18N
            appdata = System.getenv("APPDATA");
        }
        return appdata != null ? appdata : "";
    }

    /**
     * Returns the value for the %ALLUSERSPROFILE% + the last foder segment from %APPDATA% env variables on windows
     */
    private static String getGlobalAPPDATA() {
        if (Utilities.isWindows()) {
            // NOI18N
            String globalProfile = System.getenv("ALLUSERSPROFILE");
            if (globalProfile == null || globalProfile.trim().equals("")) {
                // NOI18N
                globalProfile = "";
            }
            String appdataPath = WINDOWS_USER_APPDATA;
            if (appdataPath == null || appdataPath.equals("")) {
                // NOI18N
                // NOI18N
                return "";
            }
            // NOI18N
            // NOI18N
            return getWinUserAppdata(appdataPath, globalProfile);
        }
        // NOI18N
        return "";
    }

    private static String getWinUserAppdata(String appdataPath, String globalProfile) {
        appdataPath = trimBackslash(appdataPath);
        globalProfile = trimBackslash(globalProfile);
        // NOI18N
        String appdata = "";
        // NOI18N
        int idx = appdataPath.lastIndexOf("\\");
        if (idx > -1) {
            appdata = appdataPath.substring(idx + 1);
            if (appdata.trim().equals("")) {
                // NOI18N
                // NOI18N
                int previdx = appdataPath.lastIndexOf("\\", idx);
                if (idx > -1) {
                    appdata = appdataPath.substring(previdx + 1, idx);
                }
            }
        } else {
            // NOI18N
            return "";
        }
        if (globalProfile.endsWith("\\")) {
            // NOI18N
            globalProfile = globalProfile.substring(0, globalProfile.length() - 1);
        }
        // NOI18N
        return globalProfile + "/" + appdata;
    }

    private static String trimBackslash(String appdataPath) {
        if (appdataPath.endsWith("\\")) {
            // NOI18N
            appdataPath = appdataPath.substring(0, appdataPath.length() - 1);
        }
        return appdataPath;
    }

    private String getProxyPreplacedword(String key) {
        char[] pwd = KeyringSupport.read("", key);
        // NOI18N
        return pwd == null ? "" : new String(pwd);
    }
}

18 View Complete Implementation : SvnConfigFilesTest.java
Copyright Apache License 2.0
Author : apache
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");
}

18 View Complete Implementation : SvnConfigFilesTest.java
Copyright Apache License 2.0
Author : apache
private void isSubsetOf(String sourceIniPath, String expectedIniPath) throws IOException {
    Ini goldenIni = new Ini(new FileInputStream(expectedIniPath));
    Ini sourceIni = new Ini(new FileInputStream(sourceIniPath));
    for (String key : goldenIni.keySet()) {
        if (!sourceIni.containsKey(key) && goldenIni.get(key).size() > 0) {
            fail("missing section " + key + " in file " + sourceIniPath);
        }
        Section goldenSection = goldenIni.get(key);
        Section sourceSection = sourceIni.get(key);
        for (String name : goldenSection.childrenNames()) {
            if (!sourceSection.containsKey(name)) {
                fail("missing name " + name + " in file " + sourceIniPath + " section [" + name + "]");
            }
            replacedertEquals(goldenSection.get(name), sourceSection.get(name));
        }
    }
}

18 View Complete Implementation : EntitiesDataReader.java
Copyright MIT License
Author : Fundynamic
private void readWeapons(EnreplacediesData enreplacediesData, Ini ini) throws SlickException {
    Profile.Section weapons = ini.get("WEAPONS");
    String[] strings = weapons.childrenNames();
    for (String id : strings) {
        Profile.Section struct = weapons.getChild(id);
        enreplacediesData.addProjectile(id, new IniDataWeapon(struct));
    }
}

18 View Complete Implementation : CreateClustersSample.java
Copyright Apache License 2.0
Author : cloudera
/**
 * Create a new virtual instance object with a random ID and a template from the configuration file.
 */
private VirtualInstance createVirtualInstanceWithRandomId(Ini config, String templateName) {
    return VirtualInstance.builder().id(UUID.randomUUID().toString()).template(createInstanceTemplate(config, templateName)).build();
}

18 View Complete Implementation : WifExporter.java
Copyright Apache License 2.0
Author : Dissem
/**
 * @author Christian Basler
 */
public clreplaced WifExporter {

    private final BitmessageContext ctx;

    private final Ini ini;

    public WifExporter(BitmessageContext ctx) {
        this.ctx = ctx;
        this.ini = new Ini();
    }

    public WifExporter addAll() {
        for (BitmessageAddress idenreplacedy : ctx.addresses().getIdenreplacedies()) {
            addIdenreplacedy(idenreplacedy);
        }
        return this;
    }

    public WifExporter addAll(Collection<BitmessageAddress> idenreplacedies) {
        for (BitmessageAddress idenreplacedy : idenreplacedies) {
            addIdenreplacedy(idenreplacedy);
        }
        return this;
    }

    public WifExporter addIdenreplacedy(BitmessageAddress idenreplacedy) {
        Profile.Section section = ini.add(idenreplacedy.getAddress());
        section.add("label", idenreplacedy.getAlias());
        section.add("enabled", true);
        section.add("decoy", false);
        if (idenreplacedy.isChan()) {
            section.add("chan", idenreplacedy.isChan());
        }
        section.add("noncetrialsperbyte", idenreplacedy.getPubkey().getNonceTrialsPerByte());
        section.add("payloadlengthextrabytes", idenreplacedy.getPubkey().getExtraBytes());
        section.add("privsigningkey", exportSecret(idenreplacedy.getPrivateKey().getPrivateSigningKey()));
        section.add("privencryptionkey", exportSecret(idenreplacedy.getPrivateKey().getPrivateEncryptionKey()));
        return this;
    }

    private String exportSecret(byte[] privateKey) {
        if (privateKey.length != PRIVATE_KEY_SIZE) {
            throw new IllegalArgumentException("Private key of length 32 expected, but was " + privateKey.length);
        }
        byte[] result = new byte[37];
        result[0] = (byte) 0x80;
        System.arraycopy(privateKey, 0, result, 1, PRIVATE_KEY_SIZE);
        byte[] hash = cryptography().doubleSha256(result, PRIVATE_KEY_SIZE + 1);
        System.arraycopy(hash, 0, result, PRIVATE_KEY_SIZE + 1, 4);
        return Base58.encode(result);
    }

    public void write(File file) throws IOException {
        file.createNewFile();
        try (FileOutputStream out = new FileOutputStream(file)) {
            write(out);
        }
    }

    public void write(OutputStream out) throws IOException {
        ini.store(out);
    }

    @Override
    public String toString() {
        StringWriter writer = new StringWriter();
        try {
            ini.store(writer);
        } catch (IOException e) {
            throw new ApplicationException(e);
        }
        return writer.toString();
    }
}

18 View Complete Implementation : Inis.java
Copyright Apache License 2.0
Author : facebook
// The input to this method is preplaceded in as a URL object in order to make
// include handling in the ini files sane.  Ini4j uses URL's base path
// in order to construct the path for the included files.
// So, if the ini file includes e.g. <file:../relative_file_path>, then the full
// path will be constructed based on the base (directory) path of the preplaceded in
// config; and if the include is an absolute path, it will also be handled correctly.
public static ImmutableMap<String, ImmutableMap<String, String>> read(URL config) throws IOException {
    try {
        Ini ini = makeIniParser(/*enable_includes=*/
        true);
        ini.load(config);
        return toMap(ini);
    } catch (InvalidFileFormatException e) {
        throw new HumanReadableException(e, e.getMessage());
    } catch (FileNotFoundException e) {
        try {
            // Handle windows paths, without this conversion, they look like /C:/foo/bar
            throw new HumanReadableException("Error while reading %s: %s", Paths.get(config.toURI()), e.getMessage());
        } catch (URISyntaxException uriEx) {
            throw e;
        }
    }
}

18 View Complete Implementation : Inis.java
Copyright Apache License 2.0
Author : facebook
// This method should be used by tests only in order to construct an in-memory
// buck config.  The includes are not enabled in this case (since include
// location, particularly relative includes, is not well defined).
@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);
}

18 View Complete Implementation : EntitiesDataReader.java
Copyright MIT License
Author : Fundynamic
public void readStructures(EnreplacediesData enreplacediesData, Ini ini) throws SlickException {
    Profile.Section structures = ini.get("STRUCTURES");
    String[] strings = structures.childrenNames();
    for (String id : strings) {
        Profile.Section struct = structures.getChild(id);
        enreplacediesData.addStructure(id, new IniDataStructure(struct));
    }
}

18 View Complete Implementation : EntitiesDataReader.java
Copyright MIT License
Author : Fundynamic
public void readUnits(EnreplacediesData enreplacediesData, Ini ini) throws SlickException {
    Profile.Section units = ini.get("UNITS");
    String[] strings = units.childrenNames();
    for (String id : strings) {
        Profile.Section struct = units.getChild(id);
        enreplacediesData.addUnit(id, new IniDataUnit(struct));
    }
}

18 View Complete Implementation : EntitiesDataReader.java
Copyright MIT License
Author : Fundynamic
private void readSuperPowers(EnreplacediesData enreplacediesData, Ini ini) throws SlickException {
    Profile.Section superpowers = ini.get("SUPERPOWERS");
    if (superpowers == null)
        return;
    String[] strings = superpowers.childrenNames();
    for (String id : strings) {
        Profile.Section struct = superpowers.getChild(id);
        enreplacediesData.addSuperPower(id, new IniDataSuperPower(struct));
    }
}

18 View Complete Implementation : EntitiesDataReader.java
Copyright MIT License
Author : Fundynamic
public void readExplosions(EnreplacediesData enreplacediesData, Ini ini) throws SlickException {
    Profile.Section explosions = ini.get("EXPLOSIONS");
    String[] strings = explosions.childrenNames();
    for (String id : strings) {
        Profile.Section struct = explosions.getChild(id);
        enreplacediesData.addParticle(id, new IniDataExplosion(struct));
    }
}

17 View Complete Implementation : Manager.java
Copyright GNU General Public License v3.0
Author : AskNowQA
private void loadSettings() {
    InputStream is;
    try {
        is = this.getClreplaced().getClreplacedLoader().getResourcereplacedtream("settings.ini");
        Ini ini = new Ini(is);
        // base section
        Section baseSection = ini.get("base");
        // cacheDir = baseSection.get("cacheDir", String.clreplaced);
        cacheDir = System.getProperty("java.io.tmpdir");
        wordnetDir = baseSection.get("wordnetDir", String.clreplaced);
        oxfordFallbackIndexDir = baseSection.get("oxfordFallbackIndexDir", String.clreplaced);
        semMapURL = baseSection.get("SemMapURL", String.clreplaced);
    } catch (InvalidFileFormatException e2) {
        e2.printStackTrace();
    } catch (IOException e2) {
        e2.printStackTrace();
    }
}

17 View Complete Implementation : SdkIniFileReader.java
Copyright Eclipse Public License 1.0
Author : excelsior-oss
private void processToolSections(Sdk sdk, Ini ini) {
    List<Section> tools = ini.getAll(TOOL_SECTION_NAME);
    if (tools != null) {
        for (Section toolSection : tools) {
            SdkTool tool = parseTool(sdk, toolSection);
            if (tool.isValid()) {
                sdk.addTool(tool);
            } else {
                LogHelper.logError(tool.getErrorMessage());
            }
        }
    }
}

17 View Complete Implementation : Inis.java
Copyright Apache License 2.0
Author : facebook
// Converts specified (loaded) ini config to an immutable map.
private static ImmutableMap<String, ImmutableMap<String, String>> toMap(Ini ini) {
    ImmutableMap.Builder<String, ImmutableMap<String, String>> sectionsToEntries = ImmutableMap.builder();
    for (String sectionName : ini.keySet()) {
        ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
        Profile.Section section = ini.get(sectionName);
        for (String propertyName : section.keySet()) {
            String propertyValue = section.get(propertyName);
            builder.put(propertyName, propertyValue);
        }
        ImmutableMap<String, String> sectionToEntries = builder.build();
        sectionsToEntries.put(sectionName, sectionToEntries);
    }
    return sectionsToEntries.build();
}

17 View Complete Implementation : IniScenarioFactory.java
Copyright MIT License
Author : Fundynamic
public void readStructures(Ini ini, Player human, Player cpu, EnreplacedyRepository enreplacedyRepository) {
    Profile.Section sounds = ini.get("STRUCTURES");
    String[] strings = sounds.childrenNames();
    for (String id : strings) {
        Profile.Section struct = sounds.getChild(id);
        Player playerToUse = getPlayer(human, cpu, struct);
        MapCoordinate mapCoordinate = getMapCoordinate(struct);
        String type = getType(struct);
        enreplacedyRepository.placeStructureOnMap(mapCoordinate, type, playerToUse);
    }
}

17 View Complete Implementation : IniScenarioFactory.java
Copyright MIT License
Author : Fundynamic
public Player readHumanPlayer(Ini ini) {
    Player human = new Player("Human", Faction.GREEN);
    Profile.Section iniHuman = ini.get("HUMAN");
    int startingCredits = iniHuman.get("Credits", Integer.clreplaced, 2000);
    MapCoordinate mapCoordinate = getMapCoordinate(iniHuman, "Focus");
    human.setFocusMapCoordinate(mapCoordinate);
    human.setCredits(startingCredits);
    return human;
}

17 View Complete Implementation : MetaConfig.java
Copyright Apache License 2.0
Author : killme2008
/**
 * Reload topics configuration
 */
@Override
public void reload() {
    final File file = new File(this.path);
    if (file.lastModified() != this.lastModified) {
        try {
            log.info("Reloading topics......");
            final Ini conf = this.createIni(file);
            MetaConfig.this.populateTopicsConfig(conf);
            log.info("Reload topics successfully");
        } catch (final Exception e) {
            log.error("Reload config failed", e);
        }
    }
}

17 View Complete Implementation : MetaConfig.java
Copyright Apache License 2.0
Author : killme2008
private void populateSystemConf(final Ini conf) {
    final Section sysConf = conf.get("system");
    Set<String> configKeySet = sysConf.keySet();
    Set<String> validKeySet = this.getFieldSet();
    this.checkConfigKeys(configKeySet, validKeySet);
    this.brokerId = this.getInt(sysConf, "brokerId");
    this.serverPort = this.getInt(sysConf, "serverPort", 8123);
    this.dashboardHttpPort = this.getInt(sysConf, "dashboardHttpPort", 8120);
    if (!StringUtils.isBlank(sysConf.get("dataPath"))) {
        this.setDataPath(sysConf.get("dataPath"));
    }
    if (!StringUtils.isBlank(sysConf.get("appClreplacedPath"))) {
        this.appClreplacedPath = sysConf.get("appClreplacedPath");
    }
    if (!StringUtils.isBlank(sysConf.get("dataLogPath"))) {
        this.dataLogPath = sysConf.get("dataLogPath");
    }
    if (!StringUtils.isBlank(sysConf.get("hostName"))) {
        this.hostName = sysConf.get("hostName");
    }
    this.numParreplacedions = this.getInt(sysConf, "numParreplacedions");
    this.unflushThreshold = this.getInt(sysConf, "unflushThreshold");
    this.unflushInterval = this.getInt(sysConf, "unflushInterval");
    this.maxSegmentSize = this.getInt(sysConf, "maxSegmentSize");
    this.maxTransferSize = this.getInt(sysConf, "maxTransferSize");
    if (!StringUtils.isBlank(sysConf.get("getProcessThreadCount"))) {
        this.getProcessThreadCount = this.getInt(sysConf, "getProcessThreadCount");
    }
    if (!StringUtils.isBlank(sysConf.get("putProcessThreadCount"))) {
        this.putProcessThreadCount = this.getInt(sysConf, "putProcessThreadCount");
    }
    if (!StringUtils.isBlank(sysConf.get("deletePolicy"))) {
        this.deletePolicy = sysConf.get("deletePolicy");
    }
    if (!StringUtils.isBlank(sysConf.get("deleteWhen"))) {
        this.deleteWhen = sysConf.get("deleteWhen");
    }
    if (!StringUtils.isBlank(sysConf.get("quartzThreadCount"))) {
        this.quartzThreadCount = this.getInt(sysConf, "quartzThreadCount");
    }
    if (!StringUtils.isBlank(sysConf.get("maxCheckpoints"))) {
        this.maxCheckpoints = this.getInt(sysConf, "maxCheckpoints");
    }
    if (!StringUtils.isBlank(sysConf.get("checkpointInterval"))) {
        this.checkpointInterval = this.getLong(sysConf, "checkpointInterval");
    }
    if (!StringUtils.isBlank(sysConf.get("maxTxTimeoutTimerCapacity"))) {
        this.maxTxTimeoutTimerCapacity = this.getInt(sysConf, "maxTxTimeoutTimerCapacity");
    }
    if (!StringUtils.isBlank(sysConf.get("flushTxLogAtCommit"))) {
        this.flushTxLogAtCommit = this.getInt(sysConf, "flushTxLogAtCommit");
    }
    if (!StringUtils.isBlank(sysConf.get("maxTxTimeoutInSeconds"))) {
        this.maxTxTimeoutInSeconds = this.getInt(sysConf, "maxTxTimeoutInSeconds");
    }
    // added by dennis,2012-05-19
    if (!StringUtils.isBlank(sysConf.get("acceptSubscribe"))) {
        this.acceptSubscribe = this.getBoolean(sysConf, "acceptSubscribe");
    }
    if (!StringUtils.isBlank(sysConf.get("acceptPublish"))) {
        this.acceptPublish = this.getBoolean(sysConf, "acceptPublish");
    }
    // added by dennis,2012-06-21
    if (!StringUtils.isBlank(sysConf.get("stat"))) {
        this.stat = this.getBoolean(sysConf, "stat");
    }
    if (!StringUtils.isBlank(sysConf.get("updateConsumerOffsets"))) {
        this.updateConsumerOffsets = this.getBoolean(sysConf, "updateConsumerOffsets");
    }
    if (!StringUtils.isBlank(sysConf.get("loadMessageStoresInParallel"))) {
        this.loadMessageStoresInParallel = this.getBoolean(sysConf, "loadMessageStoresInParallel");
    }
}

17 View Complete Implementation : MonitorConfig.java
Copyright Apache License 2.0
Author : killme2008
private void populateFilterTopicConfig(Ini iniConfig) {
    final Section filterTopicConf = iniConfig.get("filterTopic");
    if (!StringUtils.isBlank(filterTopicConf.get("topic"))) {
        this.filterTopicList.addAll(Arrays.asList(filterTopicConf.get("topic").split(",")));
    }
}

17 View Complete Implementation : MonitorConfig.java
Copyright Apache License 2.0
Author : killme2008
// add by liuqingjie.pt
public void loadInis(String resource) throws IOException {
    this.configPath = resource;
    this.isConfigFileChanged(true);
    File iniFile = Utils.getResourceAsFile(resource);
    final Ini iniConfig = new Ini();
    // ini4j������/��ʱ�����䵱���ָ��ַ���������ķָ��ַ�
    iniConfig.getConfig().setPathSeparator('+');
    iniConfig.getConfig().setFileEncoding(Charset.forName("GBK"));
    iniConfig.load(iniFile);
    this.populateConfig(iniConfig);
}

17 View Complete Implementation : ConfigServiceProvider.java
Copyright MIT License
Author : malikzh
/**
 * Класс для загрузки и хранения конфигурации
 */
public clreplaced ConfigServiceProvider extends Config implements ServiceProvider {

    public final static String CONFIG_FILENAME = "NCANode.ini";

    Ini defaultIni = null;

    // Dependencies
    private CmdServiceProvider cmd = null;

    private OutLogServiceProvider outLog = null;

    public ConfigServiceProvider(CmdServiceProvider cmd, OutLogServiceProvider outLog) {
        this.cmd = cmd;
        this.outLog = outLog;
        String configFile = this.cmd.get("config");
        if (configFile == null) {
            configFile = CONFIG_FILENAME;
        }
        configFile = Helper.absolutePath(configFile);
        outLog.write("Trying to load config from: " + configFile);
        try {
            this.defaultIni = new Ini();
            setDefaultConfig();
            ini = new Ini(new File(configFile));
        } catch (FileNotFoundException e) {
            outLog.write("WARNING! Cannot load config from file. Using built-in config");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public String get(String sectionName, String optionName) {
        return super.get(sectionName, optionName, defaultIni.get(sectionName, optionName));
    }

    /**
     * Встроенная конфигурация
     */
    private void setDefaultConfig() {
        // [main]
        defaultIni.put("main", "mode", "http");
        // [log]
        defaultIni.put("log", "error_log", "logs/error.log");
        defaultIni.put("log", "request_log", "logs/request.log");
        // [ca]
        defaultIni.put("ca", "root_dir", "ca/root");
        defaultIni.put("ca", "trusted_dir", "ca/trusted");
        // [pki]
        defaultIni.put("pki", "ocsp_url", "http://ocsp.pki.gov.kz");
        defaultIni.put("pki", "tsp_url", "http://tsp.pki.gov.kz");
        defaultIni.put("pki", "crl_urls", "http://crl.pki.gov.kz/nca_rsa.crl http://crl.pki.gov.kz/nca_gost.crl http://crl.pki.gov.kz/nca_d_rsa.crl  http://crl.pki.gov.kz/nca_d_gost.crl http://crl.pki.gov.kz/rsa.crl http://crl.pki.gov.kz/gost.crl http://crl.pki.gov.kz/d_rsa.crl http://crl.pki.gov.kz/d_gost.crl");
        defaultIni.put("pki", "crl_cache_dir", "cache/crl");
        defaultIni.put("pki", "crl_cache_lifetime", "60");
        // [http]
        defaultIni.put("http", "ip", "127.0.0.1");
        defaultIni.put("http", "port", "14579");
        // [rabbitmq]
        defaultIni.put("rabbitmq", "host", "127.0.0.1");
        defaultIni.put("rabbitmq", "port", "5672");
        defaultIni.put("rabbitmq", "queue_name", "ncanode");
    }
}

17 View Complete Implementation : Context.java
Copyright GNU Affero General Public License v3.0
Author : NoraUi
/**
 * @param loader
 *            is clreplaced loader
 * @param version
 *            is version of selector (target application version).
 * @param applicationKey
 *            unic key of application
 */
protected static void initApplicationDom(ClreplacedLoader loader, String version, String applicationKey) {
    try {
        final InputStream data = loader.getResourcereplacedtream("selectors/" + version + "/" + applicationKey + ".ini");
        if (data != null) {
            final Ini ini = new Ini(data);
            iniFiles.put(applicationKey, ini);
        }
    } catch (final InvalidFileFormatException e) {
        log.error("error Context.initApplicationDom()", e);
    } catch (final IOException e) {
        log.error(Messages.getMessage(CONTEXT_APP_INI_FILE_NOT_FOUND), applicationKey, e);
    }
}

17 View Complete Implementation : Utilities.java
Copyright GNU Affero General Public License v3.0
Author : NoraUi
/**
 * @param applicationKey
 *            is key of application
 * @param code
 *            is key of selector (CAUTION: if you use any % char. {@link String#format(String, Object...)})
 * @param args
 *            is list of args ({@link String#format(String, Object...)})
 * @return the selector
 */
public static String getSelectorValue(String applicationKey, String code, Object... args) {
    String selector = "";
    log.debug("getLocator with this application key : {}", applicationKey);
    log.debug("getLocator with this locator file : {}", Context.iniFiles.get(applicationKey));
    final Ini ini = Context.iniFiles.get(applicationKey);
    final Map<String, String> section = ini.get(code);
    if (section != null) {
        final Entry<String, String> entry = section.entrySet().iterator().next();
        selector = String.format(entry.getValue(), args);
    }
    return selector;
}

17 View Complete Implementation : DBUtils.java
Copyright MIT License
Author : nuls-io
private static String getProjectDbPath() throws Exception {
    Config cfg = new Config();
    cfg.setMultiSection(true);
    Ini ini = new Ini();
    ini.setConfig(cfg);
    // 可以读取到nuls_2.0项目根目录下的module.ncf,在生产环境读到jar同目录下的module.ncf
    ini.load(new File("module.ncf"));
    IniEnreplacedy ie = new IniEnreplacedy(ini);
    String filePath = ie.getCfgValue("Module", "DataPath");
    // Log.debug(filePath); //读取配置的data文件夹路径
    return filePath;
}