Example usage for java.util Properties putAll

List of usage examples for java.util Properties putAll

Introduction

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

Prototype

@Override
    public synchronized void putAll(Map<?, ?> t) 

Source Link

Usage

From source file:org.apache.gobblin.source.extractor.extract.kafka.KafkaSimpleStreamingSource.java

static public Consumer getKafkaConsumer(Config config) {
    List<String> brokers = ConfigUtils.getStringList(config, ConfigurationKeys.KAFKA_BROKERS);
    Properties props = new Properties();
    props.put("bootstrap.servers", Joiner.on(",").join(brokers));
    props.put("group.id", ConfigUtils.getString(config, ConfigurationKeys.JOB_NAME_KEY, StringUtils.EMPTY));
    props.put("enable.auto.commit", "false");
    Preconditions.checkArgument(config.hasPath(TOPIC_KEY_DESERIALIZER));
    props.put("key.deserializer", config.getString(TOPIC_KEY_DESERIALIZER));
    Preconditions.checkArgument(config.hasPath(TOPIC_VALUE_DESERIALIZER));
    props.put("value.deserializer", config.getString(TOPIC_VALUE_DESERIALIZER));

    // pass along any config scoped under source.kafka.config
    // one use case of this is to pass SSL configuration
    Config scopedConfig = ConfigUtils.getConfigOrEmpty(config, KAFKA_CONSUMER_CONFIG_PREFIX);
    props.putAll(ConfigUtils.configToProperties(scopedConfig));

    Consumer consumer = null;/*w w w.j a  v  a 2 s .c  o m*/
    try {
        consumer = new KafkaConsumer<>(props);
    } catch (Exception e) {
        LOG.error("Exception when creating Kafka consumer - {}", e);
        throw Throwables.propagate(e);
    }
    return consumer;
}

From source file:org.apache.pig.impl.util.PropertiesUtil.java

/**
 * Loads the properties from a given file.
 * @param properties Properties object that is to be loaded.
 * @param fileName file name of the file that contains the properties.
 */// ww w .j  av  a 2 s . c  om
public static void loadPropertiesFromFile(Properties properties, String fileName) {
    BufferedInputStream bis = null;
    Properties pigrcProps = new Properties();
    try {
        File pigrcFile = new File(fileName);
        if (pigrcFile.exists()) {
            if (fileName.endsWith("/.pigrc")) {
                log.warn(pigrcFile.getAbsolutePath() + " exists but will be deprecated soon."
                        + " Use conf/pig.properties instead!");
            }

            bis = new BufferedInputStream(new FileInputStream(pigrcFile));
            pigrcProps.load(bis);
        }
    } catch (Exception e) {
        log.error("unable to parse .pigrc :", e);
    } finally {
        if (bis != null)
            try {
                bis.close();
            } catch (Exception e) {
            }
    }

    properties.putAll(pigrcProps);
}

From source file:org.apache.karaf.eik.core.KarafCorePluginUtils.java

/**
 * Loads a configuration file relative to the specified base directory. This
 * method also processes any include directives that import other properties
 * files relative to the specified property file.
 *
 * @param base//from   ww  w  . ja v  a2  s.  com
 *            the directory containing the file
 * @param filename
 *            the relative path to the properties file
 * @param processIncludes
 *            true if {@link #INCLUDES_PROPERTY} statements should be
 *            followed; false otherwise.
 * @return the {@link Properties} object created from the contents of
 *         configuration file
 * @throws CoreException
 *             if there is a problem loading the file
 */
public static Properties loadProperties(final File base, final String filename, final boolean processIncludes)
        throws CoreException {
    final File f = new File(base, filename);

    try {
        final Properties p = new Properties();
        p.load(new FileInputStream(f));

        if (processIncludes) {
            final String includes = p.getProperty(INCLUDES_PROPERTY);
            if (includes != null) {
                final StringTokenizer st = new StringTokenizer(includes, "\" ", true);
                if (st.countTokens() > 0) {
                    String location;
                    do {
                        location = nextLocation(st);
                        if (location != null) {
                            final Properties includeProps = loadProperties(base, location);
                            p.putAll(includeProps);
                        }
                    } while (location != null);
                }
                p.remove(INCLUDES_PROPERTY);
            }
        }

        return p;
    } catch (final IOException e) {
        final String message = "Unable to load configuration file from configuration directory: "
                + f.getAbsolutePath();
        throw new CoreException(
                new Status(IStatus.ERROR, KarafCorePluginActivator.PLUGIN_ID, IStatus.OK, message, e));
    }

}

From source file:com.cyclopsgroup.waterview.DummyTest.java

/**
 * Dummy  test case// www  .  j  a v a  2 s  . c  o m
 */
public void testDummy() {
    MultiHashMap map = new MultiHashMap();
    map.put("a", "a1");
    map.put("a", "a2");
    Properties p = new Properties();
    p.putAll(map);
    System.out.println(p.getProperty("a"));
}

From source file:org.cobbzilla.mail.TemplatedMailKestrelConfiguration.java

public Properties getPropertiesObject() {
    final Properties props = new Properties();
    props.putAll(properties);
    return props;
}

From source file:org.apache.metron.management.KafkaFunctions.java

/**
 * Assembles the set of Properties required by the Kafka client.
 *
 * A set of default properties has been defined to provide minimum functionality.
 * Any properties defined in the global configuration override these defaults.
 * Any user-defined overrides then override all others.
 *
 * @param overrides Property overrides provided by the user.
 * @param context The Stellar context./*from  ww  w. j  a v  a 2 s .c  o  m*/
 */
private static Properties buildKafkaProperties(Map<String, String> overrides, Context context) {
    // start with minimal set of default properties
    Properties properties = new Properties();
    properties.putAll(defaultProperties);

    // override the default properties with those in the global configuration
    Optional<Object> globalCapability = context.getCapability(GLOBAL_CONFIG, false);
    if (globalCapability.isPresent()) {
        Map<String, Object> global = (Map<String, Object>) globalCapability.get();
        properties.putAll(global);
    }

    // any user-defined properties will override both the defaults and globals
    properties.putAll(overrides);

    return properties;
}

From source file:es.csic.iiia.planes.generator.Cli.java

/**
 * Parse the provided list of arguments according to the program's options.
 *
 * @param in_args list of input arguments.
 * @return a configuration object set according to the input options.
 *//*from   w w  w .j a  v  a 2s  .  c  o m*/
private static Configuration parseOptions(String[] in_args) {
    CommandLineParser parser = new PosixParser();
    CommandLine line = null;
    Properties settings = loadDefaultSettings();

    try {
        line = parser.parse(options, in_args);
    } catch (ParseException ex) {
        Logger.getLogger(Cli.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        showHelp();
    }

    if (line.hasOption('h')) {
        showHelp();
    }

    if (line.hasOption('d')) {
        dumpSettings();
    }

    if (line.hasOption('s')) {
        String fname = line.getOptionValue('s');
        try {
            settings.load(new FileReader(fname));
        } catch (IOException ex) {
            throw new IllegalArgumentException("Unable to load the settings file \"" + fname + "\"");
        }
    }

    // Apply overrides
    settings.setProperty("quiet", String.valueOf(line.hasOption('q')));
    Properties overrides = line.getOptionProperties("o");
    settings.putAll(overrides);

    String[] args = line.getArgs();
    if (args.length < 1) {
        showHelp();
    }
    settings.setProperty("problem", args[0]);

    Configuration c = new Configuration(settings);

    if (line.hasOption('t')) {
        System.exit(0);
    }
    return c;
}

From source file:com.google.enterprise.connector.filenet4.FileNetConnectorFactory.java

/**
 * Creates a connector instance by loading the bean definitions and creating
 * the connector bean instance using Spring      *
 *
 *  @see com.google.enterprise.connector.spi.ConnectorFactory#makeConnector(java.util.Map)
 **///from w  w  w. ja v  a 2  s .c  o m

@Override
public Connector makeConnector(Map<String, String> config) throws RepositoryException {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(factory);
    Resource connectorInstanceConfig = new ClassPathResource(CONNECTOR_DEFAULTS_XML);
    Resource connectorDefaultsConfig = new ClassPathResource(CONNECTOR_INSTANCE_XML);
    beanReader.loadBeanDefinitions(connectorInstanceConfig);
    beanReader.loadBeanDefinitions(connectorDefaultsConfig);
    Properties props = new Properties();
    props.putAll(config);
    PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    configurer.setProperties(props);
    configurer.postProcessBeanFactory(factory);
    Connector connector = (Connector) factory.getBean("Filenet_P8");
    if (connector == null) {
        throw new RepositoryException("Filenet_P8 bean could not be loaded");
    }
    return connector;
}

From source file:com.partnet.automation.util.SystemPropsUtil.java

/**
 * Load properties from the given configuration file name.
 * <p>//  w  w  w .  j av a2 s.c  o m
 * Given error message is displayed if file not found.
 * <p>
 * 
 * @param configFileName
 *          - File name of properties file.
 * @throws RuntimeException
 *           - If the file has a error while reading the properties file
 */
public static void loadProperties(String configFileName) {
    Properties cmdlineProps = System.getProperties();
    Properties fileProps = new Properties();

    // load property file
    InputStream inputStream = SystemPropsUtil.class.getResourceAsStream(configFileName);
    if (inputStream == null) {
        // force use of classloader to look for properties file
        inputStream = SystemPropsUtil.class.getClassLoader().getResourceAsStream(configFileName);
        if (inputStream == null) {
            log.warn(String.format("Failed to locate and load properties file: %s", configFileName));
            return;
        }
    } else {
        log.info("Properties file ({}) exists", configFileName);
    }

    // load fileProps with config.properties
    try {
        fileProps.load(inputStream);
    } catch (IOException e) {
        throw new RuntimeException(
                String.format("Failure occurred while reading properties file: %s", configFileName), e);
    }

    // Override any fileProp with cmdlineProps
    fileProps.putAll(cmdlineProps);
    System.setProperties(fileProps);
}

From source file:org.apache.kylin.common.KylinConfigExt.java

protected Properties getAllProperties() {
    Properties result = new Properties();
    result.putAll(super.getRawAllProperties());
    result.putAll(overrides);/*from w w w  .  j  a  v a  2  s.co m*/
    return result;
}