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;
}
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();
}
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));
}
}
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;
}
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;
}
Aggregations