本文整理汇总了Java中org.apache.commons.configuration.PropertiesConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java PropertiesConfiguration类的具体用法?Java PropertiesConfiguration怎么用?Java PropertiesConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropertiesConfiguration类属于org.apache.commons.configuration包,在下文中一共展示了PropertiesConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadFirst
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
/**
* Load configuration from a list of files until the first successful load
* @param conf the configuration object
* @param files the list of filenames to try
* @return the configuration object
*/
static MetricsConfig loadFirst(String prefix, String... fileNames) {
for (String fname : fileNames) {
try {
Configuration cf = new PropertiesConfiguration(fname)
.interpolatedConfiguration();
LOG.info("loaded properties from "+ fname);
LOG.debug(toString(cf));
MetricsConfig mc = new MetricsConfig(cf, prefix);
LOG.debug(mc);
return mc;
} catch (ConfigurationException e) {
if (e.getMessage().startsWith("Cannot locate configuration")) {
continue;
}
throw new MetricsConfigException(e);
}
}
LOG.warn("Cannot locate configuration: tried "+
Joiner.on(",").join(fileNames));
// default to an empty configuration
return new MetricsConfig(new PropertiesConfiguration(), prefix);
}
示例2: loadData
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
@Override
protected void loadData() {
// 设定文件初期读入
try {
PropertiesConfiguration languageConf = new PropertiesConfiguration(Thread.currentThread()
.getContextClassLoader().getResource("language/package.properties"));
title = languageConf.getString(YiDuConfig.TITLE);
siteKeywords = languageConf.getString(YiDuConfig.SITEKEYWORDS);
siteDescription = languageConf.getString(YiDuConfig.SITEDESCRIPTION);
name = languageConf.getString(YiDuConfig.NAME);
url = languageConf.getString(YiDuConfig.URL);
copyright = languageConf.getString(YiDuConfig.COPYRIGHT);
beianNo = languageConf.getString(YiDuConfig.BEIANNO);
analyticscode = languageConf.getString(YiDuConfig.ANALYTICSCODE);
analyticscode = languageConf.getString(YiDuConfig.ANALYTICSCODE);
category = languageConf.getString(YiDuConfig.CATEGORY);
} catch (ConfigurationException e) {
logger.error(e);
}
}
示例3: saveRecord
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
public void saveRecord() throws Exception {
if (file.exists()) {
// file.renameTo(new File(Configs.recordFileName+".bak"));
file.delete();
}
file.createNewFile();
PropertiesConfiguration record = new PropertiesConfiguration(
Configs.recordFileName);
record.addProperty("verifiedUsers", Records.verifiedUsers.toArray());
// record.addProperty("records", Records.records);
Object[] usrEntries = Records.records.keySet().toArray();
record.addProperty("usrEntries", usrEntries);
for (Object usr : usrEntries) {
record.addProperty((String) usr, Records.records.get(usr).toArray());
}
record.save();
}
示例4: createDefault
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
public void createDefault() throws Exception {
if (file.exists()) {
file.renameTo(new File(Enterence.propFileName + ".bak"));
}
file.createNewFile();
PropertiesConfiguration config = new PropertiesConfiguration(
Enterence.propFileName);
config.setProperty("sudoers", Configs.sudoers);
config.setProperty("sudoPwd", Configs.sudoPwd);
config.setProperty("server", Configs.server);
config.setProperty("name", Configs.name);
config.setProperty("pwd", Configs.pwd);
config.setProperty("channels", Configs.channels);
config.setProperty("preffix", Configs.preffix);
config.setProperty("sudoers", Configs.sudoers);
config.setProperty("recordFileName", Configs.recordFileName);
config.setProperty("useProxy", Configs.useProxy);
config.setProperty("Proxy", Configs.Proxy);
config.save();
}
示例5: upgrade
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
@Override
public void upgrade(final UpgradeResult result, File tleInstallDir) throws Exception
{
new PropertyFileModifier(
new File(new File(tleInstallDir, CONFIG_FOLDER), PropertyFileModifier.MANDATORY_CONFIG))
{
@Override
protected boolean modifyProperties(PropertiesConfiguration props)
{
if( props.containsKey("cluster.group.name") )
{
result.addLogMessage("Removing cluster.group.name property");
props.clearProperty("cluster.group.name");
return true;
}
return false;
}
}.updateProperties();
}
示例6: main
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if(args.length!=2) {
System.out.println("Usage: hdt2gremlin <file.hdt> <Gremlin Graph Config File>");
System.out.println(" The config follows the syntax of gremlins factory Graph.open().");
System.exit(-1);
}
// Create Graph
Configuration p = new PropertiesConfiguration(args[1]);
try(Graph gremlinGraph = GraphFactory.open(p)){
// Open HDT
try(HDT hdt = HDTManager.mapHDT("args[0]")){
// Import HDT into Graph
StopWatch st = new StopWatch();
importGraph(hdt, gremlinGraph);
System.out.println("Took "+st.stopAndShow());
}
// smallTest(gremlinGraph);
}
System.exit(0);
}
示例7: normalizeCommands
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
/**
* Normalize all guild commands
* @param collection All commands
* @throws ConfigurationException If apache config throws an exception
*/
private static void normalizeCommands(Collection<Command> collection) throws ConfigurationException {
Collection<File> found = FileUtils.listFiles(new File("resources/guilds"),
TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
found.add(new File("resources/guilds/template.properties"));
for (File f : found) {
if (f.getName().equals("GuildProperties.properties") || f.getName().equals("template.properties")) {
PropertiesConfiguration config = new PropertiesConfiguration(f);
List<String> enabledCommands = config.getList("EnabledCommands").stream()
.map(object -> Objects.toString(object, null))
.collect(Collectors.toList());
List<String> disabledCommands = config.getList("DisabledCommands").stream()
.map(object -> Objects.toString(object, null))
.collect(Collectors.toList());
for (Command c : collection) {
if (!enabledCommands.contains(c.toString()) && !disabledCommands.contains(c.toString())) {
enabledCommands.add(c.toString());
}
}
config.setProperty("EnabledCommands", enabledCommands);
config.save();
}
}
}
示例8: loadFirst
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
/**
* Load configuration from a list of files until the first successful load
* @param conf the configuration object
* @param files the list of filenames to try
* @return the configuration object
*/
static MetricsConfig loadFirst(String prefix, String... fileNames) {
for (String fname : fileNames) {
try {
Configuration cf = new PropertiesConfiguration(fname)
.interpolatedConfiguration();
LOG.info("loaded properties from "+ fname);
LOG.debug(toString(cf));
MetricsConfig mc = new MetricsConfig(cf, prefix);
LOG.debug(mc);
return mc;
}
catch (ConfigurationException e) {
if (e.getMessage().startsWith("Cannot locate configuration")) {
continue;
}
throw new MetricsConfigException(e);
}
}
LOG.warn("Cannot locate configuration: tried "+
Joiner.on(",").join(fileNames));
// default to an empty configuration
return new MetricsConfig(new PropertiesConfiguration(), prefix);
}
示例9: loadProperties
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
private PropertiesConfiguration loadProperties() throws ConfigurationException {
String deploymentProperties = "src/test/resources/deployment-fakeAdapterTest.properties";
PropertiesConfiguration props = new PropertiesConfiguration(deploymentProperties);
return props;
// try {
// Properties prop = null;
// Resource res = appContext.getResource(deploymentProperties);
// InputStream in = res.getInputStream();
// if (in == null) {
// LOG.warn("Failed to locate properties file on classpath: " + deploymentProperties);
// } else {
// LOG.info("Found '" + deploymentProperties + "' on the classpath");
// prop = new Properties();
// prop.load(in);
// }
// return prop;
// } catch (IOException e) {
// LOG.error("Failed to load properties file '" + deploymentProperties + "'", e);
// throw new RuntimeException("Failed to initialise from properties file " +
// deploymentProperties);
// }
}
示例10: testAllTheGetters
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
/**
* Test all the getters
*/
@Test
public void testAllTheGetters() {
PropertiesConfiguration props = loadProperties();
try {
AdapterConfig config = new AdapterConfig(props);
Assert.assertEquals("adapterClass", config.getAdapterClass());
Assert.assertEquals("adapterDir", config.getAdapterDir());
Assert.assertEquals("authEndpoint", config.getAuthEndpoint());
Assert.assertEquals(1, config.getCollectThreads());
Assert.assertEquals("providerId", config.getProviderId());
Assert.assertEquals("providerName", config.getProviderName());
Assert.assertEquals("providerType", config.getProviderType());
Assert.assertEquals(2, config.getSchedulingInterval());
} catch (AdapterConfigException ex) {
Assert.fail("Expected it to pass");
}
}
示例11: loadProperties
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
/**
* Creates a properties config with all the properties set
*
* @return
*/
private PropertiesConfiguration loadProperties() {
PropertiesConfiguration properties = new PropertiesConfiguration();
properties.addProperty(AdapterConfig.ADAPTER_CLASS, "adapterClass");
properties.addProperty(AdapterConfig.ADAPTER_DIR, "adapterDir");
properties.addProperty(AdapterConfig.AUTH_ENDPOINT, "authEndpoint");
properties.addProperty(AdapterConfig.COLLECT_THREADS, "1");
properties.addProperty(AdapterConfig.PROVIDER_ID, "providerId");
properties.addProperty(AdapterConfig.PROVIDER_NAME, "providerName");
properties.addProperty(AdapterConfig.PROVIDER_TYPE, "providerType");
properties.addProperty(AdapterConfig.SCHEDULING_INTERVAL, "2");
properties.addProperty(AdapterConfig.FILE_PATH, "filePath");
return properties;
}
示例12: create
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
/**
* Retrieves {@link CompactionManager}.
*
* @param options map of various options keyed by name
* @return {@link CompactionManager}
*/
public static CompactionManager create(Map<String, String> options) throws Exception {
final Configuration configuration = new Configuration();
configuration.addResource(new Path("/etc/hadoop/conf/hdfs-site.xml"));
configuration.addResource(new Path("/etc/hadoop/conf/core-site.xml"));
configuration.addResource(new Path("/etc/hadoop/conf/yarn-site.xml"));
configuration.addResource(new Path("/etc/hadoop/conf/mapred-site.xml"));
try {
PropertiesConfiguration config = new PropertiesConfiguration(CONF_PATH);
DEFAULT_THRESHOLD_IN_BYTES = config.getLong("default.threshold");
} catch (Exception e) {
throw new RuntimeException("Exception while loading default threshold in bytes" + e);
}
final CompactionCriteria criteria = new CompactionCriteria(options);
if (StringUtils.isNotBlank(options.get("targetPath"))) {
return new CompactionManagerImpl(configuration, criteria);
}
return new CompactionManagerInPlaceImpl(configuration, criteria);
}
示例13: ConfigHelper
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
public ConfigHelper(String propertyPath) {
try {
propertiesConfiguration = new PropertiesConfiguration(propertyPath);
} catch (Exception e) {
throw new RuntimeException(
"Please configure check file: " + propertyPath);
}
}
示例14: init
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
public static void init(String configFilePath) {
try {
defultConfigFilePath = configFilePath;
config = new PropertiesConfiguration(defultConfigFilePath);
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
示例15: fromPropertiesFile
import org.apache.commons.configuration.PropertiesConfiguration; //导入依赖的package包/类
public static MarketMakerConfiguration fromPropertiesFile(final String fileName) throws ConfigurationException {
final Configuration configuration = new PropertiesConfiguration(fileName);
return new MarketMakerConfiguration(
configuration.getInt(ConfigKey.TIME_SLEEP_SECONDS.getKey()),
new BigDecimal(configuration.getString(ConfigKey.SPREAD_FRACTION.getKey())),
configuration.getDouble(ConfigKey.FAIR_VOLATILITY.getKey()),
configuration.getDouble(ConfigKey.VOLATILITY_SPREAD_FRACTION.getKey()),
configuration.getInt(ConfigKey.NUM_LEVELS.getKey()),
configuration.getInt(ConfigKey.QUANTITY_ON_LEVEL.getKey()),
configuration.getDouble(ConfigKey.DELTA_LIMIT.getKey()),
configuration.getDouble(ConfigKey.VEGA_LIMIT.getKey())
);
}