Search in sources :

Example 6 with Ini

use of org.ini4j.Ini in project asterixdb by apache.

the class ConfigUtils method loadINIFile.

public static Ini loadINIFile(URL configURL) throws IOException {
    Ini ini = new Ini();
    ini.load(configURL);
    return ini;
}
Also used : Ini(org.ini4j.Ini)

Example 7 with Ini

use of org.ini4j.Ini in project buck by facebook.

the class Inis method read.

public static ImmutableMap<String, ImmutableMap<String, String>> read(Reader reader) throws IOException {
    Ini ini = new Ini();
    Config config = ini.getConfig();
    config.setEscape(false);
    config.setEscapeNewline(true);
    ini.load(reader);
    validateIni(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();
}
Also used : Ini(org.ini4j.Ini) Config(org.ini4j.Config) ImmutableMap(com.google.common.collect.ImmutableMap) Profile(org.ini4j.Profile)

Example 8 with Ini

use of org.ini4j.Ini in project MSEC by Tencent.

the class AddSecondLevelServiceConfigTag method addPortConfig.

public void addPortConfig(String filename, int port) throws Exception {
    final String SECTION_NAME = "SRPC";
    final String KEY = "listen";
    //listen=e123/udp 234/tcp
    final String VALUE = String.format("%d/udp %d/tcp", port, port);
    Ini ini = new Ini();
    ini.load(new File(filename));
    Ini.Section section = ini.get(SECTION_NAME);
    boolean bChanged = false;
    if (section == null) {
        section = ini.add(SECTION_NAME);
        section.add(KEY, VALUE);
        bChanged = true;
    } else {
        String valueStr = section.get(KEY);
        if (valueStr == null) {
            section.add(KEY, VALUE);
            bChanged = true;
        } else {
            if (!valueStr.equalsIgnoreCase(VALUE)) {
                //logger.error("port config exists,but value mismatch!"+valueStr+"!="+VALUE);
                section.put(KEY, VALUE);
                bChanged = true;
            }
        }
    }
    if (bChanged) {
        ini.store(new File(filename));
    }
}
Also used : Ini(org.ini4j.Ini) File(java.io.File)

Example 9 with Ini

use of org.ini4j.Ini in project MSEC by Tencent.

the class ServiceFactory method getConfig.

public static String getConfig(String section, String key) {
    Ini ini = new Ini();
    try {
        ini.load(new File(SRPC_CONF_PATH));
        Profile.Section sec = ini.get(section);
        if (sec != null) {
            return sec.get(key);
        }
    } catch (IOException e) {
        log.error("get config " + section + ":" + key + " failed.", e);
    }
    return null;
}
Also used : Ini(org.ini4j.Ini) IOException(java.io.IOException) File(java.io.File) Profile(org.ini4j.Profile)

Example 10 with Ini

use of org.ini4j.Ini in project asterixdb by apache.

the class NCService method acceptConnection.

private static boolean acceptConnection(InputStream is) {
    // If we see anything else or have any error, crap out and await a different connection.
    try {
        ObjectInputStream ois = new ObjectInputStream(is);
        String magic = ois.readUTF();
        if (!ServiceConstants.NC_SERVICE_MAGIC_COOKIE.equals(magic)) {
            LOGGER.severe("Connection used incorrect magic cookie");
            return false;
        }
        switch(ServiceCommand.valueOf(ois.readUTF())) {
            case START_NC:
                String iniString = ois.readUTF();
                ini = new Ini(new StringReader(iniString));
                ncId = ConfigUtils.getString(ini, Section.LOCALNC, NCConfig.Option.NODE_ID, "");
                nodeSection = "nc/" + ncId;
                return launchNCProcess();
            case TERMINATE:
                LOGGER.info("Terminating NCService based on command from CC");
                exit(0);
                break;
        }
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Error decoding connection from server", e);
    }
    return false;
}
Also used : Ini(org.ini4j.Ini) StringReader(java.io.StringReader) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Ini (org.ini4j.Ini)12 File (java.io.File)3 IOException (java.io.IOException)3 StringReader (java.io.StringReader)3 Map (java.util.Map)3 Profile (org.ini4j.Profile)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 URL (java.net.URL)2 EnumMap (java.util.EnumMap)2 HashMap (java.util.HashMap)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 CompositeMap (org.apache.commons.collections4.map.CompositeMap)2 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)2 IOption (org.apache.hyracks.api.config.IOption)2 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 FileNotFoundException (java.io.FileNotFoundException)1 ObjectInputStream (java.io.ObjectInputStream)1 Reader (java.io.Reader)1 StringWriter (java.io.StringWriter)1