本文整理了Java中java.util.Properties.getProperty()
方法的一些代码示例,展示了Properties.getProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Properties.getProperty()
方法的具体详情如下:
包路径:java.util.Properties
类名称:Properties
方法名:getProperty
[英]Searches for the property with the specified name. If the property is not found, the default Properties are checked. If the property is not found in the default Properties, null is returned.
[中]搜索具有指定名称的属性。如果未找到该属性,则会选中默认属性。如果在默认属性中找不到该属性,则返回null。
代码示例来源:origin: square/okhttp
private static String versionString() {
try {
Properties prop = new Properties();
InputStream in = Main.class.getResourceAsStream("/okcurl-version.properties");
prop.load(in);
in.close();
return prop.getProperty("version");
} catch (IOException e) {
throw new AssertionError("Could not load okcurl-version.properties.");
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
public HeidelTimeAnnotator(String name, Properties props) {
this(new File(props.getProperty(HEIDELTIME_PATH_PROPERTY,
System.getProperty("heideltime",
DEFAULT_PATH))),
props.getProperty(HEIDELTIME_LANGUAGE_PROPERTY, "english"),
Boolean.valueOf(props.getProperty(HEIDELTIME_OUTPUT_RESULTS, "false")));
}
代码示例来源:origin: apache/incubator-druid
static Map<String, Object> makeLoggingMap(Properties props)
{
Map<String, Object> loggingMap = new HashMap<>();
loggingMap.put(
"loggerClass", props.getProperty("org.apache.druid.java.util.emitter.logging.class", LoggingEmitter.class.getName())
);
loggingMap.put(
"logLevel", props.getProperty("org.apache.druid.java.util.emitter.logging.level", "debug")
);
return loggingMap;
}
代码示例来源:origin: elasticjob/elastic-job-lite
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
Properties props = new Properties();
URL classLoaderURL = Thread.currentThread().getContextClassLoader().getResource("");
if (null != classLoaderURL) {
String configFilePath = Joiner.on(FILE_SEPARATOR).join(classLoaderURL.getPath(), "conf", "auth.properties");
try {
props.load(new FileInputStream(configFilePath));
} catch (final IOException ex) {
log.warn("Cannot found auth config file, use default auth config.");
}
}
rootUsername = props.getProperty("root.username", ROOT_DEFAULT_USERNAME);
rootPassword = props.getProperty("root.password", ROOT_DEFAULT_PASSWORD);
guestUsername = props.getProperty("guest.username", GUEST_DEFAULT_USERNAME);
guestPassword = props.getProperty("guest.password", GUEST_DEFAULT_PASSWORD);
}
代码示例来源:origin: apache/incubator-dubbo
public static Map<String, String> parseProperties(String content) throws IOException {
Map<String, String> map = new HashMap<>();
if (StringUtils.isEmpty(content)) {
logger.warn("You specified the config centre, but there's not even one single config item in it.");
} else {
Properties properties = new Properties();
properties.load(new StringReader(content));
properties.stringPropertyNames().forEach(
k -> map.put(k, properties.getProperty(k))
);
}
return map;
}
代码示例来源:origin: stanfordnlp/CoreNLP
private static Properties updatePropertiesWithOptions(Properties props, String[] args) {
Properties allProperties = new Properties();
// copy it so props isn't changed but can be overridden by args
for (String key : props.stringPropertyNames()) {
allProperties.setProperty(key, props.getProperty(key));
}
Properties options = StringUtils.argsToProperties(args);
for (String key : options.stringPropertyNames()) {
allProperties.setProperty(key, options.getProperty(key));
}
return allProperties;
}
代码示例来源:origin: ctripcorp/apollo
private String loadConfigFor(String namespace) {
String filename = String.format("mockdata-%s.properties", namespace);
final Properties prop = ResourceUtils.readConfigFile(filename, new Properties());
Map<String, String> configurations = Maps.newHashMap();
for (String propertyName : prop.stringPropertyNames()) {
configurations.put(propertyName, prop.getProperty(propertyName));
}
ApolloConfig apolloConfig = new ApolloConfig("someAppId", "someCluster", namespace, "someReleaseKey");
Map<String, String> mergedConfigurations = mergeOverriddenProperties(namespace, configurations);
apolloConfig.setConfigurations(mergedConfigurations);
return gson.toJson(apolloConfig);
}
代码示例来源:origin: alibaba/druid
String home = vm.getSystemProperties().getProperty("java.home");
File f = new File(agent);
if (!f.exists()) {
agent = home + File.separator + "lib" + File.separator + "management-agent.jar";
f = new File(agent);
if (!f.exists()) {
throw new IOException("Management agent not found");
代码示例来源:origin: stanfordnlp/CoreNLP
public static Properties overWriteProperties(Properties bp, Properties ovp) {
for (String propertyName : ovp.stringPropertyNames()) {
bp.setProperty(propertyName,ovp.getProperty(propertyName));
}
return bp;
}
代码示例来源:origin: spring-projects/spring-framework
private Properties loadProperties(String propString, boolean useReader) throws IOException {
DefaultPropertiesPersister persister = new DefaultPropertiesPersister();
Properties props = new Properties();
if (useReader) {
persister.load(props, new StringReader(propString));
}
else {
persister.load(props, new ByteArrayInputStream(propString.getBytes()));
}
assertEquals("message1", props.getProperty("code1"));
assertEquals("message2", props.getProperty("code2"));
return props;
}
代码示例来源:origin: javaee-samples/javaee7-samples
public Credentials() {
try {
final Properties creds = new Properties();
creds.load(new FileInputStream(System.getProperty("user.home")
+ System.getProperty("file.separator")
+ ".javamail"));
from = creds.getProperty("from");
password = creds.getProperty("password");
to = creds.getProperty("to");
} catch (IOException ex) {
Logger.getLogger(Credentials.class.getName()).log(Level.SEVERE, null, ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Set the HTTP status code that this exception resolver will apply for a given
* resolved error view. Keys are view names; values are status codes.
* <p>Note that this error code will only get applied in case of a top-level request.
* It will not be set for an include request, since the HTTP status cannot be modified
* from within an include.
* <p>If not specified, the default status code will be applied.
* @see #setDefaultStatusCode(int)
*/
public void setStatusCodes(Properties statusCodes) {
for (Enumeration<?> enumeration = statusCodes.propertyNames(); enumeration.hasMoreElements();) {
String viewName = (String) enumeration.nextElement();
Integer statusCode = Integer.valueOf(statusCodes.getProperty(viewName));
this.statusCodes.put(viewName, statusCode);
}
}
代码示例来源:origin: apache/incubator-dubbo
public static Map<String, String> parseProperties(String content) throws IOException {
Map<String, String> map = new HashMap<>();
if (StringUtils.isEmpty(content)) {
logger.warn("You specified the config centre, but there's not even one single config item in it.");
} else {
Properties properties = new Properties();
properties.load(new StringReader(content));
properties.stringPropertyNames().forEach(
k -> map.put(k, properties.getProperty(k))
);
}
return map;
}
代码示例来源:origin: stanfordnlp/CoreNLP
public HeidelTimeKBPAnnotator(String name, Properties props) {
this.heideltimePath = new File(props.getProperty(HEIDELTIME_PATH_PROPERTY,
System.getProperty("heideltime",
DEFAULT_PATH)));
this.outputResults = Boolean.valueOf(props.getProperty(HEIDELTIME_OUTPUT_RESULTS, "false"));
this.language = props.getProperty(HEIDELTIME_LANGUAGE_PROPERTY, "english");
// this.tagList = Arrays.asList(props.getProperty("clean.xmltags", "").toLowerCase().split("\\|"))
// .stream().filter(x -> x.length() > 0)
// .collect(Collectors.toList());
}
代码示例来源:origin: spring-cloud-incubator/spring-cloud-alibaba
@Override
public NacosDataSource getObject() throws Exception {
if (!StringUtils.isEmpty(System.getProperties()
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_ENDPOINT))) {
Properties properties = new Properties();
properties.setProperty(PropertyKeyConst.ACCESS_KEY, this.accessKey);
properties.setProperty(PropertyKeyConst.SERVER_ADDR, this.secretKey);
properties.setProperty(PropertyKeyConst.ENDPOINT, this.endpoint);
properties.setProperty(PropertyKeyConst.NAMESPACE, this.namespace);
return new NacosDataSource(properties, groupId, dataId, converter);
}
return new NacosDataSource(serverAddr, groupId, dataId, converter);
}
代码示例来源:origin: jenkinsci/jenkins
private static String computeVersion() {
Properties props = new Properties();
try {
InputStream is = CLI.class.getResourceAsStream("/jenkins/cli/jenkins-cli-version.properties");
if(is!=null) {
try {
props.load(is);
} finally {
is.close();
}
}
} catch (IOException e) {
e.printStackTrace(); // if the version properties is missing, that's OK.
}
return props.getProperty("version","?");
}
代码示例来源:origin: apache/zookeeper
+ missingProperties);
this.workDir = new File(workDir, Long.toString(System.currentTimeMillis()));
if (!this.workDir.exists()
&& !this.workDir.mkdirs()) {
throw new RuntimeException("Cannot create directory " + this.workDir);
port = Integer.parseInt(conf.getProperty(KDC_PORT));
String orgName= conf.getProperty(ORG_NAME);
String orgDomain = conf.getProperty(ORG_DOMAIN);
realm = orgName.toUpperCase(Locale.ENGLISH) + "."
+ orgDomain.toUpperCase(Locale.ENGLISH);
代码示例来源:origin: stanfordnlp/CoreNLP
public static Properties noClobberWriteProperties(Properties bp, Properties ovp) {
for (String propertyName : ovp.stringPropertyNames()) {
if (bp.containsKey(propertyName))
continue;
bp.setProperty(propertyName,ovp.getProperty(propertyName));
}
return bp;
}
代码示例来源:origin: redisson/redisson
@Override
public ReactorConfiguration read() {
Properties configuration = new Properties();
applyProfile(loadDefaultProfile(), configuration);
for (Properties activeProfile : loadActiveProfiles()) {
applyProfile(activeProfile, configuration);
}
applySystemProperties(configuration);
String defaultDispatcherName = configuration.getProperty(PROPERTY_NAME_DEFAULT_DISPATCHER, Environment.SHARED);
List<DispatcherConfiguration> dispatcherConfiguration = createDispatcherConfiguration(configuration);
return new ReactorConfiguration(dispatcherConfiguration, defaultDispatcherName, configuration);
}
代码示例来源:origin: gocd/gocd
private static String readFromOsRelease() throws Exception {
try (FileReader fileReader = new FileReader(new File("/etc/os-release"))) {
Properties properties = new Properties();
properties.load(fileReader);
return unQuote(properties.getProperty("PRETTY_NAME"));
}
}
内容来源于网络,如有侵权,请联系作者删除!