下面列出了java.util.Properties#keys ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Creates a new <code>FailedProperties40</code> instance. Since
* Derby doesn't support any properties, all the keys from the
* <code>props</code> parameter are added to the
* <code>failedProps_</code> member with value
* REASON_UNKNOWN_PROPERTY.
*
* @param props a <code>Properties</code> value. Can be null or empty
*/
public FailedProperties40(Properties props) {
if (props == null || props.isEmpty()) {
firstKey_ = null;
firstValue_ = null;
return;
}
Enumeration e = props.keys();
firstKey_ = (String)e.nextElement();
firstValue_ = props.getProperty(firstKey_);
failedProps_.put(firstKey_, ClientInfoStatus.REASON_UNKNOWN_PROPERTY);
while (e.hasMoreElements()) {
failedProps_.put((String)e.nextElement(),
ClientInfoStatus.REASON_UNKNOWN_PROPERTY);
}
}
/**
* The user selected properties are set with 'marathon.properties' prefix in
* the MPF files. This function removes this prefix (if exist).
*
* @param mpfProps
* , properties for which the substitution need to be performed.
* @return new property list.
*/
public static Properties removePrefixes(Properties mpfProps) {
Enumeration<Object> enumeration = mpfProps.keys();
Properties props = new Properties();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
String value = mpfProps.getProperty(key);
if (key.startsWith(Constants.PROP_PROPPREFIX)) {
key = key.substring(Constants.PROP_PROPPREFIX.length());
props.setProperty(key, value);
} else if (!props.containsKey(key)) {
props.setProperty(key, value);
}
}
return props;
}
protected String getNoDbUrl(String url) throws SQLException {
Properties props = getPropertiesFromUrl(ConnectionUrl.getConnectionUrlInstance(url, null));
final String host = props.getProperty(PropertyKey.HOST.getKeyName(), "localhost");
final String port = props.getProperty(PropertyKey.PORT.getKeyName(), "3306");
props.remove(PropertyKey.DBNAME.getKeyName());
removeHostRelatedProps(props);
final StringBuilder urlBuilder = new StringBuilder("jdbc:mysql://").append(host).append(":").append(port).append("/?");
Enumeration<Object> keyEnum = props.keys();
while (keyEnum.hasMoreElements()) {
String key = (String) keyEnum.nextElement();
urlBuilder.append(key);
urlBuilder.append("=");
urlBuilder.append(props.get(key));
if (keyEnum.hasMoreElements()) {
urlBuilder.append("&");
}
}
return urlBuilder.toString();
}
/**
* Displays current system environment settings.
*/
private void printSysEnvironment() {
Properties sysEnv = null;
try {
sysEnv = SystemEnvReader.getEnvVars();
Enumeration sysKeys = sysEnv.keys();
while (sysKeys.hasMoreElements()) {
String key = (String) sysKeys.nextElement();
if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(),
"initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_launching_with_service_env__FINEST",
new Object[] { Thread.currentThread().getName(), key, sysEnv.getProperty(key) });
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
/**
* Creates a <code>Connection</code>, overriding the default properties with
* the ones provided.
*
* @param override
* the overriding properties
*
* @return
* a <code>Connection</code> object
*/
private Connection getConnectionOverrideProperties( Properties override ) throws Exception
{
// Get properties, override with provided values
Properties props = (Properties) TestBase.props.clone();
for( Enumeration e = override.keys(); e.hasMoreElements(); )
{
String key = (String) e.nextElement();
props.setProperty( key, override.getProperty( key ) );
}
// Obtain connection
Class.forName( props.getProperty( "driver" ) );
String url = props.getProperty( "url" );
return DriverManager.getConnection( url, props );
}
/** */
private void loadProperties() throws IOException
{
p = new Properties();
for (int i = 0; i < 50; i++) {
msgFile = i;
InputStream is = (InputStream) java.security.AccessController.doPrivileged(this);
if (is == null)
continue;
try {
p.load(is);
} finally {
try {
is.close();
} catch (IOException ioe) {
}
}
}
keys = p.keys();
}
private void strip(Properties props)
{
for (Enumeration<Object> keys = props.keys(); keys.hasMoreElements();)
{
String key = (String) keys.nextElement();
String val = StringUtils.trimTrailingWhitespace(props.getProperty(key));
if (logger.isTraceEnabled())
{
logger.trace("Trimmed trailing whitespace for property " + key + " = " + val);
}
props.setProperty(key, val);
}
}
/**
* Reads the Java DMK property list from a file and
* adds the read properties as system properties.
*/
public static void load(String file) throws IOException {
Properties props = new Properties();
InputStream is = new FileInputStream(file);
props.load(is);
is.close();
for (final Enumeration<?> e = props.keys(); e.hasMoreElements() ; ) {
final String key = (String) e.nextElement();
System.setProperty(key,props.getProperty(key));
}
}
/**
* This method was introduced to fix defect #26964. For Java 1.0.2
* on Win NT, the escape sequence \u0020 was not being handled
* correctly by the Java Properties class when it was the final
* character of a line. Instead the trailing blank was dropped
* and the next line was swallowed as a continuation. To work
* around the problem, we introduced our own metasymbol to represent
* a trailing blank. Hence:
*
* Performs substitution for any metasymbols in the message
* templates. So far only %B is needed. This was introduced
* to make it more convenient for .properties files to
* contain message templates with leading or trailing blanks
* (although %B may actually occur anywhere in a template).
* Subsequently, checking for '\n' has also been added. Now,
* wherever '\n' occurs in a message template, it is replaced
* with the value of System.getProperty ("line.separator").
*/
private static final void fixMessages (Properties p) {
Enumeration keys = p.keys ();
Enumeration elems = p.elements ();
while (keys.hasMoreElements ()) {
String key = (String) keys.nextElement ();
String elem = (String) elems.nextElement ();
int i = elem.indexOf (LTB);
boolean changed = false;
while (i != -1) {
if (i == 0)
elem = " " + elem.substring (2);
else
elem = elem.substring (0, i) + " " + elem.substring (i+2);
changed = true;
i = elem.indexOf (LTB);
}
int lsIncr = lineSeparator.length () - 1;
for (i=0; i<elem.length (); i++) {
if (elem.charAt (i) == NL) {
elem = elem.substring (0, i) +
lineSeparator + elem.substring (i+1);
i += lsIncr;
changed = true;
}
}
if (changed)
p.put (key, elem);
}
}
private List<OMapProperty> getGeneralProperties(Properties attributes) {
List<OMapProperty> ompl = new ArrayList<OMapProperty>();
Enumeration<Object> keys = attributes.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
OMapProperty omp = new OMapProperty();
omp.setName(key);
omp.setValue(attributes.getProperty(key));
ompl.add(omp);
}
return ompl;
}
public ResultSet() {
Properties sysprops = System.getProperties();
props = (Hashtable) preferprops.clone();
Enumeration enum_ = sysprops.keys();
while (enum_.hasMoreElements()) {
Object key = enum_.nextElement();
if (!ignoreprops.containsKey(key)) {
props.put(key, sysprops.get(key));
}
}
results = new Vector();
start = System.currentTimeMillis();
}
private void addEnvironment(Properties envProps) {
JsonArray containerEnv = new JsonArray();
Enumeration keys = envProps.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
String value = envProps.getProperty(key);
if (value == null) {
value = "";
}
containerEnv.add(key + "=" + value);
}
createConfig.add("Env", containerEnv);
}
@Override
public ITestLauncher createLauncher(Properties props) {
Map<String, Object> ps = new HashMap<String, Object>();
Enumeration<Object> ks = props.keys();
while (ks.hasMoreElements()) {
String object = (String) ks.nextElement();
ps.put(object, props.getProperty(object));
}
return new TestLauncher(this, ps);
}
/**
* 获取相同key的一组properties
* @param props
* @param mask
* @return
*/
public static Properties extractProperties(Properties props, String mask) {
Properties results = new Properties();
Enumeration<?> enum1 = props.keys();
while (enum1.hasMoreElements()) {
String aKey = (String) enum1.nextElement();
if (aKey != null && aKey.indexOf(mask) >= 0) {
Object aValue = props.getProperty(aKey);
results.put(aKey, aValue);
}
}
return results;
}
SysPropMetatypeProvider(BundleContext bc)
{
super("System properties");
final Dictionary<String, Object> defProps = new Hashtable<String, Object>();
final Properties sysProps = System.getProperties();
for (final Enumeration<?> e = sysProps.keys(); e.hasMoreElements();) {
final String key = (String) e.nextElement();
// Use the local value for the current framework instance; props
// that have not been exported with some value as system
// properties will not be visible due to the limitation of
// BundleContex.getProprty() on OSGi R4.
final Object val = bc.getProperty(key);
if (key.startsWith("java.") || key.startsWith("os.")
|| key.startsWith("sun.") || key.startsWith("awt.")
|| key.startsWith("user.")) {
continue;
}
if (null != val) {
defProps.put(key, val);
}
}
spOCD = new OCD(PID, PID, "Java system properties", defProps);
addService(PID, spOCD);
}
/**
*
*
*/
public RealHashTableStatistics(
int numOpens,
int rowsSeen,
int rowsFiltered,
long constructorTime,
long openTime,
long nextTime,
long closeTime,
int resultSetNumber,
int hashtableSize,
int[] hashKeyColumns,
String nextQualifiers,
Properties scanProperties,
double optimizerEstimatedRowCount,
double optimizerEstimatedCost,
ResultSetStatistics[] subqueryTrackingArray,
ResultSetStatistics childResultSetStatistics
)
{
super(
numOpens,
rowsSeen,
rowsFiltered,
constructorTime,
openTime,
nextTime,
closeTime,
resultSetNumber,
optimizerEstimatedRowCount,
optimizerEstimatedCost
);
this.hashtableSize = hashtableSize;
this.hashKeyColumns = hashKeyColumns;
this.nextQualifiers = nextQualifiers;
this.scanProperties = new FormatableProperties();
if (scanProperties != null)
{
for (Enumeration e = scanProperties.keys(); e.hasMoreElements(); )
{
String key = (String)e.nextElement();
this.scanProperties.put(key, scanProperties.get(key));
}
}
this.subqueryTrackingArray = subqueryTrackingArray;
this.childResultSetStatistics = childResultSetStatistics;
}
/**
*
*
*/
public RealHashTableStatistics(
int numOpens,
int rowsSeen,
int rowsFiltered,
long constructorTime,
long openTime,
long nextTime,
long closeTime,
int resultSetNumber,
int hashtableSize,
int[] hashKeyColumns,
String nextQualifiers,
Properties scanProperties,
double optimizerEstimatedRowCount,
double optimizerEstimatedCost,
ResultSetStatistics[] subqueryTrackingArray,
ResultSetStatistics childResultSetStatistics
)
{
super(
numOpens,
rowsSeen,
rowsFiltered,
constructorTime,
openTime,
nextTime,
closeTime,
resultSetNumber,
optimizerEstimatedRowCount,
optimizerEstimatedCost
);
this.hashtableSize = hashtableSize;
this.hashKeyColumns = hashKeyColumns;
this.nextQualifiers = nextQualifiers;
this.scanProperties = new FormatableProperties();
if (scanProperties != null)
{
for (Enumeration e = scanProperties.keys(); e.hasMoreElements(); )
{
String key = (String)e.nextElement();
this.scanProperties.put(key, scanProperties.get(key));
}
}
this.subqueryTrackingArray = subqueryTrackingArray;
this.childResultSetStatistics = childResultSetStatistics;
}
/**
*
*
*/
public RealHashScanStatistics(
int numOpens,
int rowsSeen,
int rowsFiltered,
long constructorTime,
long openTime,
long nextTime,
long closeTime,
int resultSetNumber,
String tableName,
String indexName,
boolean isConstraint,
int hashtableSize,
int[] hashKeyColumns,
String scanQualifiers,
String nextQualifiers,
Properties scanProperties,
String startPosition,
String stopPosition,
String isolationLevel,
String lockString,
double optimizerEstimatedRowCount,
double optimizerEstimatedCost
)
{
super(
numOpens,
rowsSeen,
rowsFiltered,
constructorTime,
openTime,
nextTime,
closeTime,
resultSetNumber,
optimizerEstimatedRowCount,
optimizerEstimatedCost
);
this.tableName = tableName;
this.indexName = indexName;
this.isConstraint = isConstraint;
this.hashtableSize = hashtableSize;
this.hashKeyColumns = hashKeyColumns;
this.scanQualifiers = scanQualifiers;
this.nextQualifiers = nextQualifiers;
this.scanProperties = new FormatableProperties();
if (scanProperties != null)
{
for (Enumeration e = scanProperties.keys(); e.hasMoreElements(); )
{
String key = (String)e.nextElement();
this.scanProperties.put(key, scanProperties.get(key));
}
}
this.startPosition = startPosition;
this.stopPosition = stopPosition;
this.isolationLevel = isolationLevel;
this.lockString = lockString;
}
public void printFixture(Properties props, PrintStream ps, String launcher, List<String> keys) {
printComments(ps, comment_fixture_properties, "");
ps.println("#{{{ Fixture Properties");
ps.println("fixture_properties = {");
printKeyValue(Constants.PROP_PROJECT_LAUNCHER_MODEL, launcher, ps, false);
keys = new ArrayList<String>(keys);
int size = keys.size();
for (int i = 0; i < size; i++) {
printProperty(props, keys.get(i), ps, false);
}
Enumeration<Object> allKeys = props.keys();
while (allKeys.hasMoreElements()) {
String key = (String) allKeys.nextElement();
if (key.startsWith(Constants.PROP_PROPPREFIX)) {
printProperty(props, key, ps, false);
}
}
printProperty(props, Constants.FIXTURE_REUSE, ps, true);
ps.print(Indent.getDefaultIndent());
ps.println("}");
ps.println("#}}} Fixture Properties");
ps.println();
String d = props.getProperty(Constants.FIXTURE_DESCRIPTION);
if (!"".equals(d)) {
printComments(ps, d, "");
}
ps.println("class Fixture");
ps.println();
printComments(ps, comment_teardown, Indent.getDefaultIndent());
ps.print(Indent.getDefaultIndent());
ps.println("def teardown");
ps.print(Indent.getDefaultIndent());
ps.print(Indent.getDefaultIndent());
ps.println();
ps.print(Indent.getDefaultIndent());
ps.println("end");
ps.println();
printComments(ps, comment_setup, Indent.getDefaultIndent());
ps.print(Indent.getDefaultIndent());
ps.println("def setup");
ps.print(Indent.getDefaultIndent());
ps.println("end");
ps.println();
printComments(ps, comment_test_setup, Indent.getDefaultIndent());
ps.print(Indent.getDefaultIndent());
ps.println("def test_setup");
ps.print(Indent.getDefaultIndent());
ps.print(Indent.getDefaultIndent());
ps.println();
ps.print(Indent.getDefaultIndent());
ps.println("end");
ps.println();
ps.println("end");
ps.println();
ps.println("$fixture = Fixture.new");
ps.println();
printComments(ps, comment_final, "");
ps.close();
}
/**
* Loads a list of all the supported encodings.
*
* System property "encodings" formatted using URL syntax may define an
* external encodings list. Thanks to Sergey Ushakov for the code
* contribution!
*/
private void loadEncodingInfo() {
try {
// load (java name)->(preferred mime name) mapping.
final Properties props = loadProperties();
// create instances of EncodingInfo from the loaded mapping
Enumeration<Object> keys = props.keys();
Map<String, EncodingInfo> canonicals = new HashMap<>();
while (keys.hasMoreElements()) {
final String javaName = (String) keys.nextElement();
final String[] mimes = parseMimeTypes(props.getProperty(javaName));
final String charsetName = findCharsetNameFor(javaName, mimes);
if (charsetName != null) {
final String kj = toUpperCaseFast(javaName);
final String kc = toUpperCaseFast(charsetName);
for (int i = 0; i < mimes.length; ++i) {
final String mimeName = mimes[i];
final String km = toUpperCaseFast(mimeName);
EncodingInfo info = new EncodingInfo(mimeName, charsetName);
_encodingTableKeyMime.put(km, info);
if (!canonicals.containsKey(kc)) {
// canonicals will map the charset name to
// the info containing the prefered mime name
// (the preferred mime name is the first mime
// name in the list).
canonicals.put(kc, info);
_encodingTableKeyJava.put(kc, info);
}
_encodingTableKeyJava.put(kj, info);
}
} else {
// None of the java or mime names on the line were
// recognized => this charset is not supported?
}
}
// Fix up the _encodingTableKeyJava so that the info mapped to
// the java name contains the preferred mime name.
// (a given java name can correspond to several mime name,
// but we want the _encodingTableKeyJava to point to the
// preferred mime name).
for (Entry<String, EncodingInfo> e : _encodingTableKeyJava.entrySet()) {
e.setValue(canonicals.get(toUpperCaseFast(e.getValue().javaName)));
}
} catch (java.net.MalformedURLException mue) {
throw new com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException(mue);
} catch (java.io.IOException ioe) {
throw new com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException(ioe);
}
}