Example usage for java.util Properties stringPropertyNames

List of usage examples for java.util Properties stringPropertyNames

Introduction

In this page you can find the example usage for java.util Properties stringPropertyNames.

Prototype

public Set<String> stringPropertyNames() 

Source Link

Document

Returns an unmodifiable set of keys from this property list where the key and its corresponding value are strings, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Usage

From source file:com.ssy.havefunweb.util.WeixinUtil.java

public AccessToken readProperties() throws IOException {
    //?a.properties
    Properties prop = new Properties();
    AccessToken token = new AccessToken();
    InputStream in = null;/*from www  . ja  va2  s.  com*/
    try {
        String path = this.getClass().getResource("/").getPath();
        path = path.substring(1, path.indexOf("classes"));//?
        path = path + TOKENPROPERTIES;
        //            in = getClass().getResourceAsStream("/WEB-INF/"+TOKENPROPERTIES);
        in = new BufferedInputStream(new FileInputStream(path));
        prop.load(in); ///
        Iterator<String> it = prop.stringPropertyNames().iterator();
        while (it.hasNext()) {
            String key = it.next();
            if (key.equals("access_token")) {
                token.setAccess_token(prop.getProperty(key));
            } else if (key.equals("expires_in")) {
                String value = prop.getProperty("expires_in");
                if (null != value && !value.equals("")) {
                    token.setExpires_in(Integer.parseInt(value));
                } else {
                    token.setExpires_in(-1);
                }
            } else if (key.equals("updateTime")) {
                String value = prop.getProperty("updateTime");
                if (null != value && !value.equals("")) {
                    token.setUpdateTime(Long.parseLong(value));
                } else {
                    token.setUpdateTime(-1L);
                }
            }

            System.out.println(key + ":" + prop.getProperty(key));
        }
    } finally {
        in.close();
    }
    return token;
}

From source file:com.facebook.LinkBench.LinkBenchDriver.java

/**
 * Load properties from auxilliary workload properties file if provided.
 * Properties from workload properties file do not override existing
 * properties/*from  w  w w .  java2s  .c o m*/
 * @throws IOException
 * @throws FileNotFoundException
 */
private void loadWorkloadProps() throws IOException, FileNotFoundException {
    if (props.containsKey(Config.WORKLOAD_CONFIG_FILE)) {
        workloadConfigFile = props.getProperty(Config.WORKLOAD_CONFIG_FILE);
        if (!new File(workloadConfigFile).isAbsolute()) {
            String linkBenchHome = ConfigUtil.findLinkBenchHome();
            if (linkBenchHome == null) {
                throw new RuntimeException("Data file config property " + Config.WORKLOAD_CONFIG_FILE
                        + " was specified using a relative path, but linkbench home"
                        + " directory was not specified through environment var "
                        + ConfigUtil.linkbenchHomeEnvVar);
            } else {
                workloadConfigFile = linkBenchHome + File.separator + workloadConfigFile;
            }
        }
        Properties workloadProps = new Properties();
        workloadProps.load(new FileInputStream(workloadConfigFile));
        // Add workload properties, but allow other values to override
        for (String key : workloadProps.stringPropertyNames()) {
            if (props.getProperty(key) == null) {
                props.setProperty(key, workloadProps.getProperty(key));
            }
        }
    }
}

From source file:gobblin.runtime.job_catalog.FSJobCatalogHelperTest.java

@Test
public void testloadGenericJobConfigs() throws ConfigurationException, IOException, URISyntaxException {
    Properties properties = new Properties();
    properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY,
            this.jobConfigDir.getAbsolutePath());
    List<JobSpec> jobSpecs = Lists.transform(
            Lists.newArrayList(/*from w  w  w  .  ja  v  a  2 s . c o m*/
                    loader.loadPullFilesRecursively(loader.getRootDirectory(), this.sysConfig, false)),
            this.converter);

    List<Properties> jobConfigs = convertJobSpecList2PropList(jobSpecs);
    Assert.assertEquals(jobConfigs.size(), 4);

    // test-job-conf-dir/test1/test11/test111.pull
    Properties jobProps1 = getJobConfigForFile(jobConfigs, "test111.pull");

    //5 is consisting of three attributes, plus ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY
    // which is on purpose to keep
    // plus ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY, which is not necessary to convert into JobSpec
    // but keep it here to avoid NullPointer exception and validation purpose for testing.
    Assert.assertEquals(jobProps1.stringPropertyNames().size(), 5);
    Assert.assertTrue(jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY));
    Assert.assertEquals(jobProps1.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY),
            this.jobConfigDir.getAbsolutePath());
    Assert.assertEquals(jobProps1.getProperty("k1"), "d1");
    Assert.assertEquals(jobProps1.getProperty("k8"), "a8");
    Assert.assertEquals(jobProps1.getProperty("k9"), "a8");

    // test-job-conf-dir/test1/test11.pull
    Properties jobProps2 = getJobConfigForFile(jobConfigs, "test11.pull");
    Assert.assertEquals(jobProps2.stringPropertyNames().size(), 5);
    Assert.assertTrue(jobProps2.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY));
    Assert.assertEquals(jobProps2.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY),
            this.jobConfigDir.getAbsolutePath());
    Assert.assertEquals(jobProps2.getProperty("k1"), "c1");
    Assert.assertEquals(jobProps2.getProperty("k3"), "b3");
    Assert.assertEquals(jobProps2.getProperty("k6"), "a6");

    // test-job-conf-dir/test1/test12.PULL
    Properties jobProps3 = getJobConfigForFile(jobConfigs, "test12.PULL");
    Assert.assertEquals(jobProps3.stringPropertyNames().size(), 3);
    Assert.assertTrue(jobProps3.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY));
    Assert.assertEquals(jobProps3.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY),
            this.jobConfigDir.getAbsolutePath());
    Assert.assertEquals(jobProps3.getProperty("k7"), "a7");

    // test-job-conf-dir/test2/test21.PULL
    Properties jobProps4 = getJobConfigForFile(jobConfigs, "test21.PULL");
    Assert.assertEquals(jobProps4.stringPropertyNames().size(), 3);
    Assert.assertTrue(jobProps4.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY));
    Assert.assertEquals(jobProps4.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY),
            this.jobConfigDir.getAbsolutePath());
    Assert.assertEquals(jobProps4.getProperty("k5"), "b5");
}

From source file:org.apache.gobblin.runtime.job_catalog.FSJobCatalogHelperTest.java

@Test(enabled = false)
public void testloadGenericJobConfigs() throws ConfigurationException, IOException, URISyntaxException {
    Properties properties = new Properties();
    properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY,
            this.jobConfigDir.getAbsolutePath());
    List<JobSpec> jobSpecs = Lists.transform(
            Lists.newArrayList(/*from   ww  w  . j a  va2 s .com*/
                    loader.loadPullFilesRecursively(loader.getRootDirectory(), this.sysConfig, false)),
            this.converter);

    List<Properties> jobConfigs = convertJobSpecList2PropList(jobSpecs);
    Assert.assertEquals(jobConfigs.size(), 4);

    // test-job-conf-dir/test1/test11/test111.pull
    Properties jobProps1 = getJobConfigForFile(jobConfigs, "test111.pull");

    //5 is consisting of three attributes, plus ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY
    // which is on purpose to keep
    // plus ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY, which is not necessary to convert into JobSpec
    // but keep it here to avoid NullPointer exception and validation purpose for testing.
    Assert.assertEquals(jobProps1.stringPropertyNames().size(), 5);
    Assert.assertTrue(jobProps1.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY));
    Assert.assertEquals(jobProps1.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY),
            this.jobConfigDir.getAbsolutePath());
    Assert.assertEquals(jobProps1.getProperty("k1"), "d1");
    Assert.assertEquals(jobProps1.getProperty("k8"), "a8");
    Assert.assertEquals(jobProps1.getProperty("k9"), "a8");

    // test-job-conf-dir/test1/test11.pull
    Properties jobProps2 = getJobConfigForFile(jobConfigs, "test11.pull");
    Assert.assertEquals(jobProps2.stringPropertyNames().size(), 5);
    Assert.assertTrue(jobProps2.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY));
    Assert.assertEquals(jobProps2.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY),
            this.jobConfigDir.getAbsolutePath());
    Assert.assertEquals(jobProps2.getProperty("k1"), "c1");
    Assert.assertEquals(jobProps2.getProperty("k3"), "b3");
    Assert.assertEquals(jobProps2.getProperty("k6"), "a6");

    // test-job-conf-dir/test1/test12.PULL
    Properties jobProps3 = getJobConfigForFile(jobConfigs, "test12.PULL");
    Assert.assertEquals(jobProps3.stringPropertyNames().size(), 3);
    Assert.assertTrue(jobProps3.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY));
    Assert.assertEquals(jobProps3.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY),
            this.jobConfigDir.getAbsolutePath());
    Assert.assertEquals(jobProps3.getProperty("k7"), "a7");

    // test-job-conf-dir/test2/test21.PULL
    Properties jobProps4 = getJobConfigForFile(jobConfigs, "test21.PULL");
    Assert.assertEquals(jobProps4.stringPropertyNames().size(), 3);
    Assert.assertTrue(jobProps4.containsKey(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY));
    Assert.assertEquals(jobProps4.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY),
            this.jobConfigDir.getAbsolutePath());
    Assert.assertEquals(jobProps4.getProperty("k5"), "b5");
}

From source file:com.haulmont.cuba.core.app.prettytime.CubaPrettyTimeParser.java

@PostConstruct
public void init() {
    StrTokenizer tokenizer = new StrTokenizer(serverConfig.getPrettyTimeProperties());
    try {/*from   www .j a  v a 2s  .  c om*/
        for (String fileName : tokenizer.getTokenArray()) {
            InputStream stream = null;

            try {
                stream = resources.getResourceAsStream(fileName);
                if (stream == null) {
                    throw new IllegalStateException("Resource is not found: " + fileName);
                }
                InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8.name());
                Properties properties = new Properties() {
                    private Set orderedKeySet = new LinkedHashSet();

                    @Override
                    public Set<String> stringPropertyNames() {
                        return orderedKeySet;
                    }

                    @Override
                    public synchronized Object put(Object key, Object value) {
                        orderedKeySet.add(key);
                        return super.put(key, value);
                    }
                };
                properties.load(reader);
                for (String key : properties.stringPropertyNames()) {
                    String value = properties.getProperty(key);
                    replacements.put(key, value);
                }
            } finally {
                IOUtils.closeQuietly(stream);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.vertica.hivestoragehandler.VerticaStorageHandler.java

private void configureJobProperties(TableDesc tableDesc, Map<String, String> jobProperties) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("tableDesc: " + tableDesc);
        LOG.debug("jobProperties: " + jobProperties);
    }/*w w  w .j  a  v  a2 s  . com*/

    String tblName = tableDesc.getTableName();
    Properties tblProps = tableDesc.getProperties();
    String columnNames = tblProps.getProperty(Constants.LIST_COLUMNS);
    jobProperties.put(DBConfiguration.INPUT_CLASS_PROPERTY, DbRecordWritable.class.getName());
    jobProperties.put(DBConfiguration.INPUT_TABLE_NAME_PROPERTY, tblName);
    jobProperties.put(DBConfiguration.OUTPUT_TABLE_NAME_PROPERTY, tblName);
    jobProperties.put(DBConfiguration.INPUT_FIELD_NAMES_PROPERTY, columnNames);
    jobProperties.put(DBConfiguration.OUTPUT_FIELD_NAMES_PROPERTY, columnNames);

    for (String key : tblProps.stringPropertyNames()) {
        if (key.startsWith("mapred.jdbc.")) {
            String value = tblProps.getProperty(key);
            LOG.info("JSH key = " + key + ", value = " + value);
            jobProperties.put(key, value);
            String key2 = key.replace("mapred.", "mapreduce.");
            if (!key.equalsIgnoreCase(key2)) {
                LOG.info("JSH key = " + key2 + ", value = " + value);
                jobProperties.put(key2, value);
            }
        }
    }
}

From source file:eu.eidas.config.impl.FileEidasNodeConfiguration.java

@Override
public void load() {
    parameters = new HashMap<String, EIDASNodeParameter>();
    eidasProperties = new Properties();
    if (metadataProvider instanceof EIDASNodeMetaconfigProviderImpl) {
        EIDASNodeMetaconfigProviderImpl metadataProviderImpl = (EIDASNodeMetaconfigProviderImpl) metadataProvider;
        for (EIDASNodeConfFile f : metadataProviderImpl.getFileList()) {
            Properties p = new Properties();
            if (EIDASNodeConfFile.FileType.XML.toString().equalsIgnoreCase(f.getType())) {
                p = ((FileConfigurationRepository) repository).loadPropertiesFromXML(f.getFileName());
            } else if (EIDASNodeConfFile.FileType.PROPERTIES.toString().equalsIgnoreCase(f.getType())) {
                p = ((FileConfigurationRepository) repository).loadPropsFromTextFile(f.getFileName());
            }//from  ww  w . j  av a  2s.co m
            loadParametersMap(p, f);
            for (String key : p.stringPropertyNames()) {
                eidasProperties.put(key, p.getProperty(key));
            }
        }
        loadCountries();
    }
}

From source file:org.darkstar.batch.LuaScriptNpcIdUpdate.java

private void updateLuaScriptIds() {
    final Properties configProperties = DarkstarUtils.loadBatchConfiguration();
    final Properties npcIdShiftProperties = DarkstarUtils.loadShiftProperties(configProperties);
    final String darkStarRoot = configProperties.getProperty("darkstar_root", "");
    final String scriptsRoot = String.format("%s/%s", darkStarRoot, "scripts");
    final File scriptsDirectory = new File(scriptsRoot);
    final String[] extensions = new String[1];
    extensions[0] = "lua";

    if (!scriptsDirectory.exists() || !scriptsDirectory.isDirectory()) {
        throw new RuntimeException(String.format("Cannot Find Scripts Directory! <%s>", scriptsRoot));
    }//from  w  w  w  .j a va  2  s  .c  o  m

    LOG.info("Preparing Shift Properties...");

    final Set<String> shiftKeysSet = npcIdShiftProperties.stringPropertyNames();
    final String[] shiftKeysArray = new String[shiftKeysSet.size()];
    shiftKeysSet.toArray(shiftKeysArray);
    final List<String> shiftKeys = Arrays.asList(shiftKeysArray);
    Collections.sort(shiftKeys, Collections.reverseOrder());

    if (shiftKeys.isEmpty()) {
        throw new RuntimeException("Error: Empty Shift Properties Detected!");
    }

    LOG.info(String.format("Searching: %s", scriptsRoot));

    final Iterator<File> luaFiles = FileUtils.iterateFiles(scriptsDirectory, extensions, true);

    while (luaFiles.hasNext()) {
        final File luaFile = luaFiles.next();
        updateFile(luaFile, shiftKeys, npcIdShiftProperties);
    }

    final StringBuilder elevatorSqlPathBuilder = new StringBuilder();
    elevatorSqlPathBuilder.append(configProperties.getProperty("darkstar_root", ""));
    elevatorSqlPathBuilder.append("sql/elevators.sql");

    final File elevatorFile = new File(elevatorSqlPathBuilder.toString());
    updateFile(elevatorFile, shiftKeys, npcIdShiftProperties);

    final StringBuilder transportSqlPathBuilder = new StringBuilder();
    transportSqlPathBuilder.append(configProperties.getProperty("darkstar_root", ""));
    transportSqlPathBuilder.append("sql/transport.sql");

    final File transportFile = new File(transportSqlPathBuilder.toString());
    updateFile(transportFile, shiftKeys, npcIdShiftProperties);

    LOG.info(String.format("Finished Updating Lua Scripts With <%d> Errors!", errors));
}

From source file:org.dcm4che3.tool.unvscp.UnvSCP.java

private static void addTransferCapabilities(ApplicationEntity ae, Properties p, TransferCapability.Role role,
        EnumSet<QueryOption> queryOptions) {
    for (String cuid : p.stringPropertyNames()) {
        String ts = p.getProperty(cuid);
        TransferCapability tc = new TransferCapability(null, cuid, role,
                ts.equals("*") ? new String[] { "*" } : toUIDs(StringUtils.split(ts, ',')));
        tc.setQueryOptions(queryOptions);
        ae.addTransferCapability(tc);// ww w  .jav  a2  s  .  c  om
    }
}

From source file:com.facebook.LinkBench.LinkBenchDriver.java

LinkBenchDriver(String configfile, Properties overrideProps, String logFile)
        throws java.io.FileNotFoundException, IOException, LinkBenchConfigError {
    // which link store to use
    props = new Properties();
    props.load(new FileInputStream(configfile));
    for (String key : overrideProps.stringPropertyNames()) {
        props.setProperty(key, overrideProps.getProperty(key));
    }//from  w  w w .  j  ava  2s .c  om

    loadWorkloadProps();

    ConfigUtil.setupLogging(props, logFile);

    logger.info("Config file: " + configfile);
    logger.info("Workload config file: " + workloadConfigFile);
}