java.util.Properties#stringPropertyNames ( )源码实例Demo

下面列出了java.util.Properties#stringPropertyNames ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: quarkus   文件: ConfigUtils.java
DotEnvConfigSource(Path path) {
    Map<String, String> values = new HashMap<>();
    try (InputStream is = Files.newInputStream(path)) {
        try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8)) {
            final Properties properties = new Properties();
            properties.load(isr);
            for (String name : properties.stringPropertyNames()) {
                values.put(name, properties.getProperty(name));
            }
        }
    } catch (FileNotFoundException | NoSuchFileException ignored) {
    } catch (IOException e) {
        log.debug("Failed to load `.env` file", e);
    }
    this.values = values;
}
 
源代码2 项目: BigData-In-Practice   文件: ConsumerFactory.java
/**
 * 工厂方法创建 kafka 消费者客户端
 */
public KafkaConsumer<K, V> create(Properties properties) {
    Properties defaultProperties = new Properties();
    defaultProperties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
    defaultProperties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
    defaultProperties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, brokerList);
    defaultProperties.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);

    if (properties != null) {
        // 合并
        for (String key : properties.stringPropertyNames()) {
            defaultProperties.put(key, properties.getProperty(key));
        }
    }
    KafkaConsumer<K, V> consumer = new KafkaConsumer<K, V>(defaultProperties);
    consumer.subscribe(Collections.singletonList(topic));
    return consumer;
}
 
源代码3 项目: sakai   文件: DefaultGlossary.java
/**
 * initialize glossary
 */
protected void init()
{
  URL glossaryFile = this.getClass().getResource(getFile());
  Properties glossaryTerms = new Properties();
  try
  {
    glossaryTerms.load(glossaryFile.openStream());
    
    for (String term : glossaryTerms.stringPropertyNames())
    {
      glossary.put(term.toLowerCase(), new GlossaryEntryBean(term
          .toLowerCase(), glossaryTerms.getProperty(term)));
    }
    initialized = true;
  }
  catch (IOException e)
  {
    log.error(e.getMessage());
  }
}
 
源代码4 项目: phoebus   文件: PropertyPreferenceLoader.java
/** Load preferences from a property file
 *
 *  <p>Properties have the name "package/setting",
 *  where the package name in dot notation
 *  is used to locate the preference node.
 *
 *  @param stream Stream for property file
 *  @throws Exception on error
 */
public static void load(final InputStream stream) throws Exception
{
    final Properties props = new Properties();
    props.load(stream);

    for (String prop : props.stringPropertyNames())
    {
        final int sep = prop.lastIndexOf('/');
        if (sep < 0)
            throw new Exception("Expected 'package_name/setting = value', got property '" + prop + "'");

        final String pack = "/" + prop.substring(0, sep).replace('.', '/');
        final String name = prop.substring(sep+1);
        final String value = props.getProperty(prop);
        final Preferences prefs = Preferences.userRoot().node(pack);
        prefs.put(name, value);
        // System.out.println(pack + "/" + name + "=" + value);
    }
}
 
源代码5 项目: cloudstack   文件: RegistryLifecycle.java
protected synchronized void loadExcluded() {
    Properties props = applicationContext.getBean("DefaultConfigProperties", Properties.class);
    excludes = new HashSet<String>();
    for (String exclude : props.getProperty(EXTENSION_EXCLUDE, "").trim().split("\\s*,\\s*")) {
        if (StringUtils.hasText(exclude)) {
            excludes.add(exclude);
        }
    }

    for (String key : props.stringPropertyNames()) {
        if (key.startsWith(EXTENSION_INCLUDE_PREFIX)) {
            String module = key.substring(EXTENSION_INCLUDE_PREFIX.length());
            boolean include = props.getProperty(key).equalsIgnoreCase("true");
            if (!include) {
                excludes.add(module);
            }
        }
    }
}
 
源代码6 项目: incubator-tamaya   文件: SimplePropertySource.java
/**
 * loads the Properties from the given URL
 *
 * @param propertiesFile {@link URL} to load Properties from
 * @return loaded {@link Properties}
 * @throws IllegalStateException in case of an error while reading properties-file
 */
private static Map<String, PropertyValue> load(URL propertiesFile) {
    boolean isXML = isXMLPropertieFiles(propertiesFile);

    Map<String, PropertyValue> properties = new HashMap<>();
    try (InputStream stream = propertiesFile.openStream()) {
        Properties props = new Properties();
        if (stream != null) {
            if (isXML) {
                props.loadFromXML(stream);
            } else {
                props.load(stream);
            }
        }
        String source = propertiesFile.toString();
        for (String key : props.stringPropertyNames()) {
            properties.put(key, PropertyValue.createValue(key, props.getProperty(key))
                    .setMeta("source", source));
        }
    } catch (IOException e) {
        throw new ConfigException("Error loading properties from " + propertiesFile, e);
    }

    return properties;
}
 
源代码7 项目: CloverETL-Engine   文件: XmlUtils.java
/**
 * Creates org.w3c.dom.Document with single root element, which has attributes
 * assembled from the given properties.
 * Example result:
 * <myRoot property1="value1" property2="value2" property3="value3"/>
 * 	
 * @param rootElement name of root element
 * @param properties properties which will be converted to attributes of the only root element
 * @return XML document with described structure 
 */
public static Document createDocumentFromProperties(String rootElement, Properties properties) {
	if (!StringUtils.isEmpty(rootElement) && properties != null) {
		try {
			// create new Document
			DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
			DocumentBuilder docBuilder = null;
			docBuilder = dbfac.newDocumentBuilder();
			Document doc = docBuilder.newDocument();
	
			// create the root element and add it to the document
			Element root = doc.createElement(rootElement);
			doc.appendChild(root);
			
			for (String propertyName : properties.stringPropertyNames()) {
				root.setAttribute(propertyName, properties.getProperty(propertyName));
			}
			return doc;
		} catch (ParserConfigurationException e) {
			throw new JetelRuntimeException(e);
		}
	} else {
		throw new NullPointerException("rootElement=" + rootElement + "; properties=" + properties);
	}
}
 
源代码8 项目: suro   文件: HdfsFileSink.java
@JsonCreator
public HdfsFileSink(
        @JsonProperty("localFileSink") LocalFileSink localFileSink,
        @JsonProperty("directory") String directory,
        @JsonProperty("concurrentUpload") int concurrentUpload,
        @JsonProperty("notice") Notice notice,
        @JsonProperty("prefixFormatter") RemotePrefixFormatter prefixFormatter,
        @JsonProperty("batchUpload") boolean batchUpload,
        @JsonProperty("properties") Properties properties
) {
    super(localFileSink, prefixFormatter, concurrentUpload, batchUpload);

    this.directory = directory;
    this.notice = notice;
    hadoopConf = new Configuration();
    if (properties != null) {
        for (String propertyName : properties.stringPropertyNames()) {
            hadoopConf.set(propertyName, properties.getProperty(propertyName));
        }
    }

    Preconditions.checkNotNull(directory, "directory is needed");
}
 
private void setPamProperties() {
    try {
        this.groupsFromUGI = ApplicationProperties.get().getBoolean("atlas.authentication.method.pam.ugi-groups", true);
        Properties properties = ConfigurationConverter.getProperties(ApplicationProperties.get()
                .subset("atlas.authentication.method.pam"));
        for (String key : properties.stringPropertyNames()) {
            String value = properties.getProperty(key);
            options.put(key, value);
        }
        if (!options.containsKey("service")) {
            options.put("service", "atlas-login");
        }
    } catch (Exception e) {
        LOG.error("Exception while setLdapProperties", e);
    }
}
 
源代码10 项目: swift-k   文件: CoasterPersistentService.java
private static AbstractSettings loadSharedSettings(String fileName, JobQueue jobQueue) throws IOException {
    Properties props = new Properties();
    FileReader r = new FileReader(fileName);
    props.load(r);
    r.close();
    
    jobQueue.initQueueProcessor(props.getProperty("workerManager"));
    
    AbstractSettings settings = jobQueue.getQueueProcessor().getSettings();
    for (String name : props.stringPropertyNames()) {
        settings.put(name, props.getProperty(name));
    }
    jobQueue.startQueueProcessor();
    return settings;
}
 
源代码11 项目: io   文件: StatusResource.java
/**
 * GETメソッドに対する処理.
 * @return JAS-RS Response
 */
@SuppressWarnings("unchecked")
@GET
@Produces("application/json")
public Response get() {
    StringBuilder sb = new StringBuilder();

    // プロパティ一覧
    Properties props = DcCoreConfig.getProperties();
    JSONObject responseJson = new JSONObject();
    JSONObject propertiesJson = new JSONObject();
    for (String key : props.stringPropertyNames()) {
        String value = props.getProperty(key);
        propertiesJson.put(key, value);
    }
    responseJson.put("properties", propertiesJson);

    // Cell作成/削除
    //responseJson.put("service", checkServiceStatus());

    // Adsの死活チェック
    responseJson.put("ads", checkAds());

    // ElasticSearch Health
    EsClient client = EsModel.client();
    JSONObject esJson = new JSONObject();
    esJson.put("health", client.checkHealth());
    responseJson.put("ElasticSearch", esJson);

    sb.append(responseJson.toJSONString());
    return Response.status(HttpStatus.SC_OK).entity(sb.toString()).build();
}
 
源代码12 项目: coffee-gb   文件: SwingController.java
public SwingController(Properties properties) {
    EnumMap<Button, Integer> buttonToKey = new EnumMap<>(Button.class);

    buttonToKey.put(Button.LEFT, KeyEvent.VK_LEFT);
    buttonToKey.put(Button.RIGHT, KeyEvent.VK_RIGHT);
    buttonToKey.put(Button.UP, KeyEvent.VK_UP);
    buttonToKey.put(Button.DOWN, KeyEvent.VK_DOWN);
    buttonToKey.put(Button.A, KeyEvent.VK_Z);
    buttonToKey.put(Button.B, KeyEvent.VK_X);
    buttonToKey.put(Button.START, KeyEvent.VK_ENTER);
    buttonToKey.put(Button.SELECT, KeyEvent.VK_BACK_SPACE);

    for (String k : properties.stringPropertyNames()) {
        String v = properties.getProperty(k);
        if (k.startsWith("btn_") && v.startsWith("VK_")) {
            try {
                Button button = Button.valueOf(k.substring(4).toUpperCase());
                Field field = KeyEvent.class.getField(properties.getProperty(k));
                if (field.getType() != int.class) {
                    continue;
                }
                int value = field.getInt(null);
                buttonToKey.put(button, value);
            } catch (IllegalArgumentException | NoSuchFieldException | IllegalAccessException e) {
                LOG.error("Can't parse button configuration", e);
            }
        }
    }

    mapping = buttonToKey.entrySet()
            .stream()
            .collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
}
 
源代码13 项目: openjdk-jdk8u   文件: RuntimeImpl.java
public Map<String,String> getSystemProperties() {
    Properties sysProps = System.getProperties();
    Map<String,String> map = new HashMap<>();

    // Properties.entrySet() does not include the entries in
    // the default properties.  So use Properties.stringPropertyNames()
    // to get the list of property keys including the default ones.
    Set<String> keys = sysProps.stringPropertyNames();
    for (String k : keys) {
        String value = sysProps.getProperty(k);
        map.put(k, value);
    }

    return map;
}
 
源代码14 项目: glowroot   文件: PropertiesFiles.java
static void upgradeIfNeededAndLoadInto(File confDir, Map<String, String> properties)
        throws IOException {
    File propFile = new File(confDir, "glowroot.properties");
    if (!propFile.exists()) {
        return;
    }
    // upgrade from 0.9.6 to 0.9.7
    org.glowroot.common.util.PropertiesFiles.upgradeIfNeeded(propFile,
            ImmutableMap.of("agent.rollup=", "agent.rollup.id="));
    // upgrade from 0.9.13 to 0.9.14
    upgradeToCollectorAddressIfNeeded(propFile);
    // upgrade from 0.9.26 to 0.9.27
    addSchemeToCollectorAddressIfNeeded(propFile);
    // upgrade from 0.9.28 to 0.10.0
    prependAgentRollupToAgentIdIfNeeded(propFile);
    InputStream in = new FileInputStream(propFile);
    Properties props = new Properties();
    try {
        props.load(in);
    } finally {
        in.close();
    }
    for (String key : props.stringPropertyNames()) {
        String value = props.getProperty(key);
        if (value != null && !value.isEmpty()) {
            // need to trim trailing spaces (leading spaces are already trimmed during load)
            properties.put("glowroot." + key, value.trim());
        }
    }
}
 
源代码15 项目: netbeans-mmd-plugin   文件: JHtmlLabel.java
public void replaceMacroses(final Properties properties) {
  String text = this.getText();
  for (final String k : properties.stringPropertyNames()) {
    text = text.replace("${" + k + "}", properties.getProperty(k));
  }
  this.setText(text);
}
 
源代码16 项目: Flink-CEPplus   文件: ConfigurationUtils.java
/**
 * Creates a new {@link Configuration} from the given {@link Properties}.
 *
 * @param properties to convert into a {@link Configuration}
 * @return {@link Configuration} which has been populated by the values of the given {@link Properties}
 */
@Nonnull
public static Configuration createConfiguration(Properties properties) {
	final Configuration configuration = new Configuration();

	final Set<String> propertyNames = properties.stringPropertyNames();

	for (String propertyName : propertyNames) {
		configuration.setString(propertyName, properties.getProperty(propertyName));
	}

	return configuration;
}
 
源代码17 项目: sqlg   文件: SqlgPostgresProvider.java
@Override
public Map<String, Object> getBaseConfiguration(String graphName, Class<?> test, String testMethodName, LoadGraphWith.GraphData loadGraphWith) {
    logger.info("Postgresql, Starting test: " + test.getSimpleName() + "." + testMethodName);
    Map<String, Object> m = new HashMap<String, Object>() {{
        put("gremlin.graph", SqlgGraph.class.getName());
        put("jdbc.url", "jdbc:postgresql://localhost:5432/" + graphName);
        put("jdbc.username", "postgres");
        put("jdbc.password", "postgres");
        put("maxPoolSize", 10);
    }};

    InputStream sqlProperties = Thread.currentThread().getContextClassLoader().getResourceAsStream("sqlg.properties");

    if (sqlProperties != null) {
        Properties p = new Properties();
        try {
            p.load(sqlProperties);
            sqlProperties.close();
            for (String k : p.stringPropertyNames()) {
                String v = p.getProperty(k);
                if (k.equals("jdbc.url")) {
                    v = v.substring(0, v.lastIndexOf("/") + 1);
                    v = v + graphName;
                }
                m.put(k, v);
            }
        } catch (IOException ioe) {
            LoggerFactory.getLogger(getClass()).error("Cannot read properties from sqlg.properties", ioe.getMessage());
        }

    }
    return m;


}
 
private InitialLoggerManager() {
    Properties props = System.getProperties();
    Set<String> names = props.stringPropertyNames();
    List<String> categories = new ArrayList<>();
    Map<String, BootstrapLogger.Level> levels = new HashMap<>();

    for (String name : names) {
        if (name.startsWith(PREFIX)) {
            String category = name.substring(PREFIX.length());
            BootstrapLogger.Level level;
            String levelStr = props.getProperty(name);
            if (levelStr.equals("")) {
                level = BootstrapLogger.Level.INFO;
            } else {
                try {
                    level = Enum.valueOf(BootstrapLogger.Level.class, levelStr);
                } catch (IllegalArgumentException e) {
                    level = BootstrapLogger.Level.INFO;
                }
            }
            categories.add(category);
            levels.put(category, level);
        }
    }

    categories.sort((l, r) -> l.compareTo(r));

    BootstrapLogger.Level rootLevel = levels.get("ROOT");
    if (rootLevel == null) {
        rootLevel = BootstrapLogger.Level.NONE;
    }

    this.root = new LevelNode("", rootLevel);

    for (String each : categories) {
        if (each.equals("ROOT")) {
            continue;
        }

        this.root.add(each, levels.get(each));
    }
}
 
源代码19 项目: boost   文件: LibertyServerConfigGenerator.java
private void addDatasourceProperties(Properties serverProperties, Element propertiesElement) {
    for (String property : serverProperties.stringPropertyNames()) {
        String attribute = property.replace(BoostProperties.DATASOURCE_PREFIX, "");
        propertiesElement.setAttribute(attribute, BoostUtil.makeVariable(property));
    }
}
 
源代码20 项目: birt   文件: MongoDBDriver.java
ServerNodeKey( Properties connProperties )
{

	m_connProperties = new Properties( );
	String useKerberos = getStringPropValue( connProperties,
			USE_KERBEROS_PROP );
	String ignoreMongoUri = getStringPropValue( connProperties,
			IGNORE_URI_PROP );
	// to disable properties based on MongoUri radio button selection
	if ( ignoreMongoUri.equals( "false" ) )
	{
		connProperties.remove( MongoDBDriver.SERVER_HOST_PROP );
		connProperties.remove( MongoDBDriver.SERVER_PORT_PROP );
		connProperties.remove( MongoDBDriver.DBNAME_PROP );
		connProperties.remove( MongoDBDriver.USERNAME_PROP );
		connProperties.remove( MongoDBDriver.PASSWORD_PROP );
	}
	// to disable properties based on kerberos check box selection
	if ( useKerberos.equals( "false" ) )
	{
		connProperties.remove( MongoDBDriver.KERBEROS_PRINCIPAL_PROP );
		connProperties.remove(
				MongoDBDriver.KERBEROS_GSSAPI_SERVICENAME_PROP );
		connProperties
				.remove( MongoDBDriver.KERBEROS_KRB5CONFIG_FILE_PROP );
		connProperties.remove(
				MongoDBDriver.KERBEROS_GSS_JAAS_CONFIG_FILE_PROP );
		connProperties.remove( MongoDBDriver.KERBEROS_PASSWORD_PROP );
	}
	for ( String propertyName : connProperties.stringPropertyNames( ) )
	{

		m_connProperties.setProperty( propertyName,
				connProperties.getProperty( propertyName ) );
		
		if ( propertyName.equals( MONGO_URI_PROP ) )
		{
			MongoClientURI mongoUri = getMongoURI( connProperties );
			if ( mongoUri != null && mongoUri.getUsername( ) != null )
			{
				m_connProperties.setProperty( USERNAME_PROP,
						mongoUri.getUsername( ) );
			}
		}
	}
      }