本文整理了Java中org.apache.felix.utils.properties.Properties
类的一些代码示例,展示了Properties
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Properties
类的具体详情如下:
包路径:org.apache.felix.utils.properties.Properties
类名称:Properties
[英]Enhancement of the standard Properties
managing the maintain of comments, etc.
[中]加强标准Properties
管理评论的维护等。
代码示例来源:origin: io.fabric8/fabric-zookeeper
private void markCreated(BundleContext bundleContext) throws IOException {
File marker = new File(dataDir, ENSEMBLE_MARKER);
if (!marker.exists() && !marker.getParentFile().exists() && !marker.getParentFile().mkdirs()) {
throw new IOException("Cannot create marker file");
}
org.apache.felix.utils.properties.Properties props = new org.apache.felix.utils.properties.Properties(marker);
props.put("created", "true");
props.save();
}
代码示例来源:origin: codice/ddf
@Override
public Dictionary<String, Object> read(InputStream in) throws IOException {
notNull(in, "Input stream cannot be null");
final Properties props = new Properties();
props.load(in);
return new Hashtable<>(props);
}
}
代码示例来源:origin: org.apache.felix/org.apache.felix.fileinstall
public boolean update(Properties properties) {
boolean modified = false;
// Remove "removed" properties from the cfg file
for (String key : new ArrayList<String>(this.keySet())) {
if (!properties.containsKey(key)) {
this.remove(key);
modified = true;
}
}
// Update existing keys
for (String key : properties.keySet()) {
String v = this.get(key);
List<String> comments = properties.getComments(key);
List<String> value = properties.getRaw(key);
if (v == null) {
this.put(key, comments, value);
modified = true;
} else if (!v.equals(properties.get(key))) {
if (comments.isEmpty()) {
comments = this.getComments(key);
}
this.put(key, comments, value);
modified = true;
}
}
return modified;
}
代码示例来源:origin: jboss-fuse/fabric8
public static Properties toProperties(Map<String, String> source) {
if (source instanceof Properties) {
return (Properties) source;
}
Properties rc = new Properties(false);
rc.putAll(source);
return rc;
}
代码示例来源:origin: apache/karaf
private static void trimValues(Properties configProps) {
for (String key : configProps.keySet()) {
configProps.put(key, configProps.get(key).trim());
}
}
代码示例来源:origin: org.fusesource.fabric/fabric-jaas
/**
* Delete a User.
*
* @param username
*/
public void deleteUser(String username) {
users.remove(username);
try {
users.save();
} catch (Exception ex) {
LOGGER.error("Cannot remove users file,", ex);
}
}
代码示例来源:origin: io.fabric8/fabric-zookeeper
public static void setProperties(CuratorFramework curator, String path, Properties properties) throws Exception {
try {
org.apache.felix.utils.properties.Properties p = new org.apache.felix.utils.properties.Properties();
if(curator.checkExists().forPath(path) == null){
create(curator, path);
}
String org = getStringData(curator, path);
if (org != null) {
p.load(new StringReader(org));
}
List<String> keys = new ArrayList<String>();
for (String key : properties.stringPropertyNames()) {
p.put(key, properties.getProperty(key));
keys.add(key);
}
List<String> deleted = new ArrayList<String>(p.keySet());
deleted.removeAll(keys);
for (String key : deleted) {
p.remove(key);
}
StringWriter writer = new StringWriter();
p.save(writer);
setData(curator, path, writer.toString());
} catch (IOException e) {
// ignore
}
}
代码示例来源:origin: org.apache.felix/org.apache.felix.utils
private void ensureTyped() {
if (!storage.typed) {
storage.typed = true;
Set<String> keys = new HashSet<String>(storage.keySet());
for (String key : keys) {
storage.put(key,
storage.getComments(key),
Arrays.asList(convertToString(storage.get(key)).split("\n")));
}
}
}
代码示例来源:origin: org.apache.felix/org.apache.felix.fileinstall
public boolean update(Map<String, String> props) {
Properties properties;
if (props instanceof Properties) {
properties = (Properties) props;
} else {
properties = new Properties();
for (Map.Entry<? extends String, ? extends String> e : props.entrySet()) {
properties.put(e.getKey(), e.getValue());
}
}
return update(properties);
}
代码示例来源:origin: io.fabric8/fabric-zookeeper
private void loadPropertiesFrom(Dictionary<String, Object> dictionary, String from) {
InputStream is = null;
Properties properties = new Properties();
try {
is = new FileInputStream(from);
properties.load(is);
for (String key : properties.keySet()) {
dictionary.put(key, properties.get(key));
}
} catch (Exception e) {
// Ignore
} finally {
if (is != null) {
try {
is.close();
} catch (Exception e) {
// Ignore
}
}
}
}
代码示例来源:origin: org.apache.karaf.system/org.apache.karaf.system.core
public void setFrameworkDebug(boolean debug) {
try {
Properties properties = loadProps();
if (debug) {
properties.put("felix.log.level", "4");
properties.put("osgi.debug", "etc/equinox-debug.properties");
} else {
properties.remove("felix.log.level");
properties.remove("osgi.debug");
}
// TODO populate the equinox-debug.properties file with the one provided in shell/dev module
properties.save();
} catch (IOException e) {
throw new RuntimeException("Error setting framework debugging: " + e.getMessage(), e);
}
}
代码示例来源:origin: apache/karaf
public void setFramework(FrameworkType framework) {
if (framework == null) {
return;
}
try {
Properties properties = loadProps();
properties.put("karaf.framework", framework.name());
properties.save();
} catch (IOException e) {
throw new RuntimeException("Error setting framework: " + e.getMessage(), e);
}
}
代码示例来源:origin: org.apache.felix/org.apache.felix.utils
/**
* Store a properties into a output stream, preserving comments, special character, etc.
* This method is mainly to be compatible with the java.util.Properties class.
*
* @param os an output stream.
* @param comment this parameter is ignored as this Properties
* @throws IOException If storing fails
*/
public void store(OutputStream os, String comment) throws IOException {
this.save(os);
}
代码示例来源:origin: org.apache.felix/org.apache.felix.fileinstall
/**
* Calls the map method put. Provided for parallelism with the getProperty method.
* Enforces use of strings for property keys and values. The value returned is the result of the map call to put.
*
* @param key the key to be placed into this property list.
* @param value the value corresponding to the key.
* @return the previous value of the specified key in this property list, or null if it did not have one.
*/
public Object setProperty(String key, String value) {
return this.put(key, value);
}
代码示例来源:origin: org.apache.felix/org.apache.felix.utils
public Properties(File location, InterpolationHelper.SubstitutionCallback callback) throws IOException {
this.location = location;
this.callback = callback;
if(location.exists())
load(location);
}
代码示例来源:origin: apache/karaf
private void reformatClauses(Properties config, String key) {
String val = config.getProperty(key);
if (val != null && !val.isEmpty()) {
List<String> comments = config.getComments(key);
Clause[] clauses = org.apache.felix.utils.manifest.Parser.parseHeader(val);
Set<String> strings = new LinkedHashSet<>();
for (Clause clause : clauses) {
strings.add(clause.toString());
}
List<String> lines = new ArrayList<>();
lines.add("");
int index = 0;
for (String string : strings) {
String s = " " + string;
if (index++ < strings.size() - 1) {
s += ", ";
}
lines.add(s);
}
config.put(key, comments, lines);
}
}
代码示例来源:origin: apache/karaf
public Properties getProperties() {
Properties props = new Properties();
try {
org.apache.felix.utils.properties.Properties properties
= new org.apache.felix.utils.properties.Properties();
properties.load(new StringReader(value));
for (Map.Entry<String, String> e : properties.entrySet()) {
props.put(e.getKey(), e.getValue());
}
} catch (IOException e) {
// ignore??
}
return props;
}
代码示例来源:origin: apache/karaf
public Map<GroupPrincipal, String> listGroups() {
Map<GroupPrincipal, String> result = new HashMap<>();
for (String name : users.keySet()) {
if (name.startsWith(GROUP_PREFIX)) {
result.put(new GroupPrincipal(name.substring(GROUP_PREFIX.length())), users.get(name));
}
}
return result;
}
代码示例来源:origin: org.apache.felix/org.apache.felix.fileinstall
public TypedProperties(SubstitutionCallback callback, boolean substitute) {
this.storage = new Properties(false);
this.callback = callback;
this.substitute = substitute;
}
代码示例来源:origin: apache/karaf
private String getPropertyOrFail(String propertyName) {
String value = props.getProperty(propertyName);
if (value == null) {
throw new IllegalArgumentException("Property " + propertyName + " must be set in the etc/" + CONFIG_PROPERTIES_FILE_NAME + " configuration file");
}
return value;
}
内容来源于网络,如有侵权,请联系作者删除!