本文整理了Java中java.util.Properties.propertyNames()
方法的一些代码示例,展示了Properties.propertyNames()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Properties.propertyNames()
方法的具体详情如下:
包路径:java.util.Properties
类名称:Properties
方法名:propertyNames
[英]Returns all of the property names (keys) in this Properties object.
[中]返回此属性对象中的所有属性名称(键)。
代码示例来源:origin: spring-projects/spring-framework
/**
* Copy the configured output {@link Properties}, if any, into the
* {@link Transformer#setOutputProperty output property set} of the supplied
* {@link Transformer}.
* @param transformer the target transformer
*/
protected final void copyOutputProperties(Transformer transformer) {
if (this.outputProperties != null) {
Enumeration<?> en = this.outputProperties.propertyNames();
while (en.hasMoreElements()) {
String name = (String) en.nextElement();
transformer.setOutputProperty(name, this.outputProperties.getProperty(name));
}
}
}
代码示例来源:origin: eclipse-vertx/vert.x
private void clearProperties() {
Set<String> toClear = new HashSet<>();
Enumeration e = System.getProperties().propertyNames();
// Uhh, properties suck
while (e.hasMoreElements()) {
String propName = (String) e.nextElement();
if (propName.startsWith("vertx.options")) {
toClear.add(propName);
}
}
toClear.forEach(System::clearProperty);
}
代码示例来源:origin: javamelody/javamelody
final Map<String, Date> result = new HashMap<String, Date>();
if (versionsFile.exists()) {
final Properties versionsProperties = new Properties();
try {
final InputStream input = new FileInputStream(versionsFile);
.list(versionsProperties.propertyNames());
final SimpleDateFormat dateFormat = new SimpleDateFormat(VERSIONS_DATE_PATTERN,
Locale.US);
for (final String version : propertyNames) {
try {
final Date date = dateFormat.parse(versionsProperties.getProperty(version));
result.put(version, date);
} catch (final ParseException e) {
continue;
代码示例来源:origin: javamelody/javamelody
private static void readCollectorApplications() throws IOException {
// le fichier applications.properties contient les noms et les urls des applications à monitorer
// par ex.: recette=http://recette1:8080/myapp
// ou production=http://prod1:8080/myapp,http://prod2:8080/myapp
// Dans une instance de Properties, les propriétés ne sont pas ordonnées,
// mais elles seront ordonnées lorsqu'elles seront mises dans cette TreeMap
final Map<String, List<URL>> result = new TreeMap<String, List<URL>>();
final File file = getCollectorApplicationsFile();
if (file.exists()) {
final Properties properties = new Properties();
final FileInputStream input = new FileInputStream(file);
try {
properties.load(input);
} finally {
input.close();
}
@SuppressWarnings("unchecked")
final List<String> propertyNames = (List<String>) Collections
.list(properties.propertyNames());
for (final String property : propertyNames) {
result.put(property, parseUrl(String.valueOf(properties.get(property))));
}
}
urlsByApplications = result;
}
代码示例来源:origin: stackoverflow.com
public Enumeration<String> getKeys()
return properties != null ? ((Enumeration<String>) properties.propertyNames()) : null;
protected Object handleGetObject(String key)
return properties.getProperty(key);
if (format.equals("db"))
Properties p = new Properties();
DataSource ds = (DataSource) ContextFactory.getApplicationContext().getBean("clinicalDataSource");
Connection con = null;
代码示例来源:origin: stackoverflow.com
Properties props = new OrderedProperties();
props.load(new FileInputStream(args[0]));
for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
}
代码示例来源: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: stackoverflow.com
@SuppressWarnings("unchecked")
public Enumeration<String> getKeys() {
return properties != null ? (Enumeration<String>) properties.propertyNames() : parent.getKeys();
String include = properties.getProperty("include");
if (include != null) {
for (String includeBaseName : include.split("\\s*,\\s*")) {
Properties properties = new Properties();
properties.load(loader.getResourceAsStream(baseName + ".properties"));
return properties;
代码示例来源:origin: eclipse-vertx/vert.x
private void clearProperties() {
Set<String> toClear = new HashSet<>();
Enumeration e = System.getProperties().propertyNames();
// Uhh, properties suck
while (e.hasMoreElements()) {
String propName = (String) e.nextElement();
if (propName.startsWith("vertx.options")) {
toClear.add(propName);
}
}
for (String propName : toClear) {
System.clearProperty(propName);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Resolve the given interface mappings, turning class names into Class objects.
* @param mappings the specified interface mappings
* @return the resolved interface mappings (with Class objects as values)
*/
private Map<String, Class<?>[]> resolveInterfaceMappings(Properties mappings) {
Map<String, Class<?>[]> resolvedMappings = new HashMap<>(mappings.size());
for (Enumeration<?> en = mappings.propertyNames(); en.hasMoreElements();) {
String beanKey = (String) en.nextElement();
String[] classNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
Class<?>[] classes = resolveClassNames(classNames, beanKey);
resolvedMappings.put(beanKey, classes);
}
return resolvedMappings;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Merge the given Properties instance into the given Map,
* copying all properties (key-value pairs) over.
* <p>Uses {@code Properties.propertyNames()} to even catch
* default properties linked into the original Properties instance.
* @param props the Properties instance to merge (may be {@code null})
* @param map the target Map to merge the properties into
*/
@SuppressWarnings("unchecked")
public static <K, V> void mergePropertiesIntoMap(@Nullable Properties props, Map<K, V> map) {
if (props != null) {
for (Enumeration<?> en = props.propertyNames(); en.hasMoreElements();) {
String key = (String) en.nextElement();
Object value = props.get(key);
if (value == null) {
// Allow for defaults fallback or potentially overridden accessor...
value = props.getProperty(key);
}
map.put((K) key, (V) value);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Map specific URL paths to specific cache seconds.
* <p>Overrides the default cache seconds setting of this interceptor.
* Can specify "-1" to exclude a URL path from default caching.
* <p>Supports direct matches, e.g. a registered "/test" matches "/test",
* and a various Ant-style pattern matches, e.g. a registered "/t*" matches
* both "/test" and "/team". For details, see the AntPathMatcher javadoc.
* <p><b>NOTE:</b> Path patterns are not supposed to overlap. If a request
* matches several mappings, it is effectively undefined which one will apply
* (due to the lack of key ordering in {@code java.util.Properties}).
* @param cacheMappings a mapping between URL paths (as keys) and
* cache seconds (as values, need to be integer-parsable)
* @see #setCacheSeconds
* @see org.springframework.util.AntPathMatcher
*/
public void setCacheMappings(Properties cacheMappings) {
this.cacheMappings.clear();
Enumeration<?> propNames = cacheMappings.propertyNames();
while (propNames.hasMoreElements()) {
String path = (String) propNames.nextElement();
int cacheSeconds = Integer.parseInt(cacheMappings.getProperty(path));
this.cacheMappings.put(path, cacheSeconds);
}
}
代码示例来源:origin: google/guava
/**
* Creates an {@code ImmutableMap<String, String>} from a {@code Properties} instance. Properties
* normally derive from {@code Map<Object, Object>}, but they typically contain strings, which is
* awkward. This method lets you get a plain-old-{@code Map} out of a {@code Properties}.
*
* @param properties a {@code Properties} object to be converted
* @return an immutable map containing all the entries in {@code properties}
* @throws ClassCastException if any key in {@code Properties} is not a {@code String}
* @throws NullPointerException if any key or value in {@code Properties} is null
*/
@GwtIncompatible // java.util.Properties
public static ImmutableMap<String, String> fromProperties(Properties properties) {
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
builder.put(key, properties.getProperty(key));
}
return builder.build();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Convert the given merged properties, converting property values
* if necessary. The result will then be processed.
* <p>The default implementation will invoke {@link #convertPropertyValue}
* for each property value, replacing the original with the converted value.
* @param props the Properties to convert
* @see #processProperties
*/
protected void convertProperties(Properties props) {
Enumeration<?> propertyNames = props.propertyNames();
while (propertyNames.hasMoreElements()) {
String propertyName = (String) propertyNames.nextElement();
String propertyValue = props.getProperty(propertyName);
String convertedValue = convertProperty(propertyName, propertyValue);
if (!ObjectUtils.nullSafeEquals(propertyValue, convertedValue)) {
props.setProperty(propertyName, convertedValue);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
Properties entityReferences = new Properties();
Enumeration<?> keys = entityReferences.propertyNames();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
int referredChar = Integer.parseInt(key);
Assert.isTrue((referredChar < 1000 || (referredChar >= 8000 && referredChar < 10000)),
() -> "Invalid reference to special HTML entity: " + referredChar);
int index = (referredChar < 1000 ? referredChar : referredChar - 7000);
String reference = entityReferences.getProperty(key);
this.characterToEntityReferenceMap[index] = REFERENCE_START + reference + REFERENCE_END;
this.entityReferenceToCharacterMap.put(reference, (char) referredChar);
代码示例来源:origin: org.apache.maven/maven-project
public void preserveProperties()
{
Properties p = getProperties();
if ( p != null )
{
preservedProperties = new Properties();
for( Enumeration e = p.propertyNames(); e.hasMoreElements(); )
{
String key = (String) e.nextElement();
preservedProperties.setProperty( key, p.getProperty( key ) );
}
}
}
代码示例来源:origin: apache/hive
private static void internProperties(Properties properties) {
for (Enumeration<?> keys = properties.propertyNames(); keys.hasMoreElements();) {
String key = (String) keys.nextElement();
String oldValue = properties.getProperty(key);
if (oldValue != null) {
properties.setProperty(key, oldValue.intern());
}
}
}
代码示例来源:origin: org.apache.maven/maven-project
public static Properties cloneProperties( Properties src )
{
if ( src == null )
{
return null;
}
Properties result = new Properties();
for( Enumeration e = src.propertyNames(); e.hasMoreElements(); )
{
String key = (String) e.nextElement();
result.setProperty( key, src.getProperty( key ) );
}
return result;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Find a matching view name in the given exception mappings.
* @param exceptionMappings mappings between exception class names and error view names
* @param ex the exception that got thrown during handler execution
* @return the view name, or {@code null} if none found
* @see #setExceptionMappings
*/
@Nullable
protected String findMatchingViewName(Properties exceptionMappings, Exception ex) {
String viewName = null;
String dominantMapping = null;
int deepest = Integer.MAX_VALUE;
for (Enumeration<?> names = exceptionMappings.propertyNames(); names.hasMoreElements();) {
String exceptionMapping = (String) names.nextElement();
int depth = getDepth(exceptionMapping, ex);
if (depth >= 0 && (depth < deepest || (depth == deepest &&
dominantMapping != null && exceptionMapping.length() > dominantMapping.length()))) {
deepest = depth;
dominantMapping = exceptionMapping;
viewName = exceptionMappings.getProperty(exceptionMapping);
}
}
if (viewName != null && logger.isDebugEnabled()) {
logger.debug("Resolving to view '" + viewName + "' based on mapping [" + dominantMapping + "]");
}
return viewName;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
throws BeansException {
for (Enumeration<?> names = props.propertyNames(); names.hasMoreElements();) {
String key = (String) names.nextElement();
try {
processKey(beanFactory, key, props.getProperty(key));
}
catch (BeansException ex) {
String msg = "Could not process key '" + key + "' in PropertyOverrideConfigurer";
if (!this.ignoreInvalidKeys) {
throw new BeanInitializationException(msg, ex);
}
if (logger.isDebugEnabled()) {
logger.debug(msg, ex);
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!