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:org.apache.crunch.kafka.inputformat.KafkaInputFormat.java

/**
 * Filters out Kafka connection properties that were tagged using {@link #generateConnectionPropertyKey(String)
 * generateConnectionPropertyKey}./*from  w w  w . j ava 2  s.  c  o  m*/
 *
 * @param props the properties to be filtered.
 * @return the properties containing Kafka connection information that were tagged using
 *         {@link #generateConnectionPropertyKey(String)}.
 */
public static Properties filterConnectionProperties(Properties props) {
    Properties filteredProperties = new Properties();

    for (final String name : props.stringPropertyNames()) {
        if (CONNECTION_PROPERTY_REGEX.matcher(name).matches()) {
            filteredProperties.put(getConnectionPropertyFromKey(name), props.getProperty(name));
        }
    }

    return filteredProperties;
}

From source file:com.jivesoftware.sdk.utils.JiveSDKUtils.java

public static void initBeanFromProperties(String fileName, Object bean) {

    if (bean == null) {
        if (log.isWarnEnabled()) {
            log.warn("Bean is null, cant init.  Ignoring ...");
        }//from  w w w  . j a v a 2s  .co  m
        return;
    } // end if

    Properties props = new Properties();
    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
    if (is != null) {
        try {
            props.load(is);
            for (String key : props.stringPropertyNames()) {
                try {
                    BeanUtils.setProperty(bean, key, props.getProperty(key));
                    if (log.isTraceEnabled()) {
                        log.trace("Sucessfully set [" + key + "] to [" + props.getProperty(key));
                    }
                } catch (IllegalAccessException iae) {
                    log.error(
                            "Unable to Set Field[" + key + "] on [" + bean.getClass().getSimpleName()
                                    + "], continuing on but may be problematic.  Check your [" + fileName + "]",
                            iae);
                } catch (InvocationTargetException ite) {
                    log.error(
                            "Unable to Set Field[" + key + "] on [" + bean.getClass().getSimpleName()
                                    + "], continuing on but may be problematic.  Check your [" + fileName + "]",
                            ite);
                } // end try/catch
            } // end for key
        } catch (IOException ioe) {
            log.error("Unable to Read File[" + fileName + ".properties] file", ioe);
        } finally {
            try {
                if (is != null) {
                    is.close();
                } // end if
            } catch (IOException ioe) {
                /** NOOP **/
                if (log.isDebugEnabled()) {
                    log.debug("Error Closing Property File Stream, unexpected", ioe);
                }
            } // end try/catch
            is = null;
        } // end try/catch
        props = null;
    } // end if

}

From source file:com.linkedin.cubert.ScriptExecutor.java

private static Map<String, String> extractCubertParams(Properties executorProps) {
    Map<String, String> cubertParams = new HashMap<String, String>();

    int stripLen = CUBERT_PROP_IDENTIFIER.length();
    String regEx = CUBERT_PROP_IDENTIFIER + "*";

    for (String p : executorProps.stringPropertyNames()) {
        if (!p.matches(regEx))
            continue;

        String key = p.substring(stripLen, p.length());
        String value = executorProps.getProperty(p);

        cubertParams.put(key, value);/*from  w w w .  j a  va  2  s  . co  m*/
    }

    return cubertParams;
}

From source file:uk.ac.ncl.aries.entanglement.cli.export.MongoGraphToGDF.java

private static Map<String, Color> loadColorMappings(File propFile) throws IOException {
    FileInputStream is = new FileInputStream(propFile);
    Properties props = new Properties();
    props.load(is);/*from   www.j ava 2s  .co m*/
    is.close();

    Map<String, Color> nodeTypeToColour = new HashMap<>();
    for (String nodeType : props.stringPropertyNames()) {
        String colorString = props.getProperty(nodeType);
        Color color;

        switch (colorString) {
        case "BLACK":
            color = Color.BLACK;
            break;
        case "BLUE":
            color = Color.BLUE;
            break;
        case "CYAN":
            color = Color.CYAN;
            break;
        case "DARK_GRAY":
            color = Color.DARK_GRAY;
            break;
        case "GRAY":
            color = Color.GRAY;
            break;
        case "GREEN":
            color = Color.GREEN;
            break;
        case "LIGHT_GRAY":
            color = Color.LIGHT_GRAY;
            break;
        case "MAGENTA":
            color = Color.MAGENTA;
            break;
        case "ORANGE":
            color = Color.ORANGE;
            break;
        case "PINK":
            color = Color.PINK;
            break;
        case "RED":
            color = Color.RED;
            break;
        case "WHITE":
            color = Color.WHITE;
            break;
        case "YELLOW":
            color = Color.YELLOW;
            break;
        default:
            color = DEFAULT_COLOR;
        }

        nodeTypeToColour.put(nodeType, color);
    }
    return nodeTypeToColour;
}

From source file:org.apache.jackrabbit.oak.upgrade.blob.LengthCachingDataStore.java

private static Map<String, Object> propsToMap(Properties p) {
    Map<String, Object> result = Maps.newHashMap();
    for (String keyName : p.stringPropertyNames()) {
        result.put(keyName, p.getProperty(keyName));
    }/*from  w w  w.j a  va  2  s.c om*/
    return result;
}

From source file:org.apache.crunch.kafka.inputformat.KafkaInputFormat.java

/**
 * Generates a {@link Properties} object containing the properties in {@code connectionProperties}, but with every
 * property prefixed with "org.apache.crunch.kafka.connection.properties".
 *
 * @param connectionProperties the properties to be prefixed with "org.apache.crunch.kafka.connection.properties"
 * @return a {@link Properties} object representing Kafka connection properties
 */// ww w.j  a v  a2s.  co m
public static Properties tagExistingKafkaConnectionProperties(Properties connectionProperties) {
    Properties taggedProperties = new Properties();

    for (final String name : connectionProperties.stringPropertyNames()) {
        taggedProperties.put(generateConnectionPropertyKey(name), connectionProperties.getProperty(name));
    }

    return taggedProperties;
}

From source file:org.evosuite.CommandLineParameters.java

/**
 * Add all the properties that were set with -D
 * //from   w w w . j a v a2 s  .  c  o  m
 * @param javaOpts
 * @param line
 * @throws Error
 */
public static void addJavaDOptions(List<String> javaOpts, CommandLine line) throws Error {

    java.util.Properties properties = line.getOptionProperties("D");
    Set<String> propertyNames = new HashSet<>(Properties.getParameters());

    for (String propertyName : properties.stringPropertyNames()) {

        if (!propertyNames.contains(propertyName)) {
            LoggingUtils.getEvoLogger().error("* Unknown property: " + propertyName);
            throw new Error("Unknown property: " + propertyName);
        }

        String propertyValue = properties.getProperty(propertyName);
        javaOpts.add("-D" + propertyName + "=" + propertyValue);
        System.setProperty(propertyName, propertyValue);

        try {
            Properties.getInstance().setValue(propertyName, propertyValue);
        } catch (Exception e) {
            throw new Error("Invalid value for property " + propertyName + ": " + propertyValue + ". Exception "
                    + e.getMessage(), e);
        }
    }
}

From source file:com.griddynamics.jagger.JaggerLauncher.java

public static void loadBootProperties(URL directory, String environmentPropertiesLocation,
        Properties environmentProperties) throws IOException {
    URL bootPropertiesFile = new URL(directory, environmentPropertiesLocation);
    System.setProperty(ENVIRONMENT_PROPERTIES, environmentPropertiesLocation);
    environmentProperties.load(bootPropertiesFile.openStream());

    String defaultBootPropertiesLocation = environmentProperties.getProperty(DEFAULT_ENVIRONMENT_PROPERTIES);
    if (defaultBootPropertiesLocation == null) {
        defaultBootPropertiesLocation = DEFAULT_ENVIRONMENT_PROPERTIES_LOCATION;
    }//from w  ww . j av a2s .c om
    URL defaultBootPropertiesFile = new URL(directory, defaultBootPropertiesLocation);
    Properties defaultBootProperties = new Properties();
    defaultBootProperties.load(defaultBootPropertiesFile.openStream());
    for (String name : defaultBootProperties.stringPropertyNames()) {
        if (!environmentProperties.containsKey(name)) {
            environmentProperties.setProperty(name, defaultBootProperties.getProperty(name));
        }
    }

    Properties properties = System.getProperties();
    for (Enumeration<String> enumeration = (Enumeration<String>) properties.propertyNames(); enumeration
            .hasMoreElements();) {
        String key = enumeration.nextElement();
        environmentProperties.put(key, properties.get(key));
    }

    System.setProperty(ENVIRONMENT_PROPERTIES, environmentPropertiesLocation);
    System.setProperty(DEFAULT_ENVIRONMENT_PROPERTIES, defaultBootPropertiesLocation);
}

From source file:org.apache.gobblin.compaction.CliOptions.java

/**
 * Parse command line arguments and return a {@link java.util.Properties} object for the Gobblin job found.
 * @param caller Class of the calling main method. Used for error logs.
 * @param args Command line arguments.//from   w ww  .  j a  va2s.  com
 * @param conf Hadoop configuration object
 * @return Instance of {@link Properties} for the Gobblin job to run.
 * @throws IOException
 */
public static Properties parseArgs(Class<?> caller, String[] args, Configuration conf) throws IOException {
    try {

        // Parse command-line options
        if (conf != null) {
            args = new GenericOptionsParser(conf, args).getCommandLine().getArgs();
        }
        CommandLine cmd = new DefaultParser().parse(options(), args);

        if (cmd.hasOption(HELP_OPTION.getOpt())) {
            printUsage(caller);
            System.exit(0);
        }

        String jobConfigLocation = JOB_CONFIG_OPTION.getLongOpt();
        if (!cmd.hasOption(jobConfigLocation)) {
            printUsage(caller);
            System.exit(1);
        }

        // Load job configuration properties
        Properties jobConfig;
        if (conf == null) {
            jobConfig = JobConfigurationUtils.fileToProperties(cmd.getOptionValue(jobConfigLocation));
        } else {
            jobConfig = JobConfigurationUtils.fileToProperties(cmd.getOptionValue(jobConfigLocation), conf);
            for (String configKey : jobConfig.stringPropertyNames()) {
                if (conf.get(configKey) != null) {
                    conf.unset(configKey);
                }
            }
            JobConfigurationUtils.putConfigurationIntoProperties(conf, jobConfig);
        }
        return jobConfig;
    } catch (ParseException | ConfigurationException e) {
        throw new IOException(e);
    }
}

From source file:org.apache.hadoop.mapred.QueueManagerTestUtils.java

public static Element createProperties(Document doc, Properties props) {
    Element propsElement = doc.createElement("properties");
    if (props != null) {
        Set<String> propList = props.stringPropertyNames();
        for (String prop : propList) {
            Element property = doc.createElement("property");
            property.setAttribute("key", prop);
            property.setAttribute("value", (String) props.get(prop));
            propsElement.appendChild(property);
        }/* ww w .j  a v  a  2 s  .c o m*/
    }
    return propsElement;
}