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.cfg4j.source.context.propertiesprovider.JsonBasedPropertiesProvider.java

/**
 * Get {@link Properties} for a given {@code inputStream} treating it as a JSON file.
 *
 * @param inputStream input stream representing JSON file
 * @return properties representing values from {@code inputStream}
 * @throws IllegalStateException when unable to read properties
 *//*from  w  w  w.j  a v a  2  s .  c om*/
@Override
public Properties getProperties(InputStream inputStream) {
    requireNonNull(inputStream);

    Properties properties = new Properties();

    try {

        JSONTokener tokener = new JSONTokener(inputStream);
        if (tokener.end()) {
            return properties;
        }
        if (tokener.nextClean() == '"') {
            tokener.back();
            properties.put("content", tokener.nextValue().toString());
        } else {
            tokener.back();
            JSONObject obj = new JSONObject(tokener);

            Map<String, Object> yamlAsMap = convertToMap(obj);
            properties.putAll(flatten(yamlAsMap));
        }

        return properties;

    } catch (Exception e) {
        throw new IllegalStateException("Unable to load json configuration from provided stream", e);
    }
}

From source file:org.apache.solr.handler.dataimport.DataImporter.java

public DataSource getDataSourceInstance(Entity key, String name, Context ctx) {
    Map<String, String> p = requestLevelDataSourceProps.get(name);
    if (p == null)
        p = config.getDataSources().get(name);
    if (p == null)
        p = requestLevelDataSourceProps.get(null);// for default data source
    if (p == null)
        p = config.getDataSources().get(null);
    if (p == null)
        throw new DataImportHandlerException(SEVERE,
                "No dataSource :" + name + " available for entity :" + key.getName());
    String type = p.get(TYPE);/*from  w ww .  j ava 2 s  . c om*/
    DataSource dataSrc = null;
    if (type == null) {
        dataSrc = new JdbcDataSource();
    } else {
        try {
            dataSrc = (DataSource) DocBuilder.loadClass(type, getCore()).newInstance();
        } catch (Exception e) {
            wrapAndThrow(SEVERE, e, "Invalid type for data source: " + type);
        }
    }
    try {
        Properties copyProps = new Properties();
        copyProps.putAll(p);
        Map<String, Object> map = ctx.getRequestParameters();
        if (map.containsKey("rows")) {
            int rows = Integer.parseInt((String) map.get("rows"));
            if (map.containsKey("start")) {
                rows += Integer.parseInt((String) map.get("start"));
            }
            copyProps.setProperty("maxRows", String.valueOf(rows));
        }
        dataSrc.init(ctx, copyProps);
    } catch (Exception e) {
        wrapAndThrow(SEVERE, e, "Failed to initialize DataSource: " + key.getDataSourceName());
    }
    return dataSrc;
}

From source file:org.apache.gobblin.service.modules.core.GobblinServiceHATest.java

@BeforeClass
public void setup() throws Exception {
    // Clean up common Flow Spec Dir
    cleanUpDir(COMMON_SPEC_STORE_PARENT_DIR);

    // Clean up work dir for Node 1
    cleanUpDir(NODE_1_SERVICE_WORK_DIR);
    cleanUpDir(NODE_1_SPEC_STORE_PARENT_DIR);

    // Clean up work dir for Node 2
    cleanUpDir(NODE_2_SERVICE_WORK_DIR);
    cleanUpDir(NODE_2_SPEC_STORE_PARENT_DIR);

    // Use a random ZK port
    this.testingZKServer = new TestingServer(-1);
    logger.info("Testing ZK Server listening on: " + testingZKServer.getConnectString());
    HelixUtils.createGobblinHelixCluster(testingZKServer.getConnectString(), TEST_HELIX_CLUSTER_NAME);

    Properties commonServiceCoreProperties = new Properties();
    commonServiceCoreProperties.put(ServiceConfigKeys.ZK_CONNECTION_STRING_KEY,
            testingZKServer.getConnectString());
    commonServiceCoreProperties.put(ServiceConfigKeys.HELIX_CLUSTER_NAME_KEY, TEST_HELIX_CLUSTER_NAME);
    commonServiceCoreProperties.put(ServiceConfigKeys.HELIX_INSTANCE_NAME_KEY,
            "GaaS_" + UUID.randomUUID().toString());
    commonServiceCoreProperties.put(ServiceConfigKeys.TOPOLOGY_FACTORY_TOPOLOGY_NAMES_KEY,
            TEST_GOBBLIN_EXECUTOR_NAME);
    commonServiceCoreProperties.put(//from   w  w  w  .  ja v a 2  s  . c o  m
            ServiceConfigKeys.TOPOLOGY_FACTORY_PREFIX + TEST_GOBBLIN_EXECUTOR_NAME + ".description",
            "StandaloneTestExecutor");
    commonServiceCoreProperties
            .put(ServiceConfigKeys.TOPOLOGY_FACTORY_PREFIX + TEST_GOBBLIN_EXECUTOR_NAME + ".version", "1");
    commonServiceCoreProperties.put(
            ServiceConfigKeys.TOPOLOGY_FACTORY_PREFIX + TEST_GOBBLIN_EXECUTOR_NAME + ".uri", "gobblinExecutor");
    commonServiceCoreProperties.put(
            ServiceConfigKeys.TOPOLOGY_FACTORY_PREFIX + TEST_GOBBLIN_EXECUTOR_NAME + ".specExecutorInstance",
            "org.gobblin.service.InMemorySpecExecutor");
    commonServiceCoreProperties.put(ServiceConfigKeys.TOPOLOGY_FACTORY_PREFIX + TEST_GOBBLIN_EXECUTOR_NAME
            + ".specExecInstance.capabilities", TEST_SOURCE_NAME + ":" + TEST_SINK_NAME);

    Properties node1ServiceCoreProperties = new Properties();
    node1ServiceCoreProperties.putAll(commonServiceCoreProperties);
    node1ServiceCoreProperties.put(ConfigurationKeys.TOPOLOGYSPEC_STORE_DIR_KEY,
            NODE_1_TOPOLOGY_SPEC_STORE_DIR);
    node1ServiceCoreProperties.put(ConfigurationKeys.FLOWSPEC_STORE_DIR_KEY, NODE_1_FLOW_SPEC_STORE_DIR);
    node1ServiceCoreProperties.put(QUARTZ_INSTANCE_NAME, "QuartzScheduler1");
    node1ServiceCoreProperties.put(QUARTZ_THREAD_POOL_COUNT, 3);

    Properties node2ServiceCoreProperties = new Properties();
    node2ServiceCoreProperties.putAll(commonServiceCoreProperties);
    node2ServiceCoreProperties.put(ConfigurationKeys.TOPOLOGYSPEC_STORE_DIR_KEY,
            NODE_2_TOPOLOGY_SPEC_STORE_DIR);
    node2ServiceCoreProperties.put(ConfigurationKeys.FLOWSPEC_STORE_DIR_KEY, NODE_2_FLOW_SPEC_STORE_DIR);
    node2ServiceCoreProperties.put(QUARTZ_INSTANCE_NAME, "QuartzScheduler2");
    node2ServiceCoreProperties.put(QUARTZ_THREAD_POOL_COUNT, 3);

    // Start Node 1
    this.node1GobblinServiceManager = new GobblinServiceManager("CoreService1", "1",
            ConfigUtils.propertiesToConfig(node1ServiceCoreProperties),
            Optional.of(new Path(NODE_1_SERVICE_WORK_DIR)));
    this.node1GobblinServiceManager.start();

    // Start Node 2
    this.node2GobblinServiceManager = new GobblinServiceManager("CoreService2", "2",
            ConfigUtils.propertiesToConfig(node2ServiceCoreProperties),
            Optional.of(new Path(NODE_2_SERVICE_WORK_DIR)));
    this.node2GobblinServiceManager.start();

    // Initialize Node 1 Client
    this.node1FlowConfigClient = new FlowConfigClient(
            String.format("http://localhost:%s/", this.node1GobblinServiceManager.restliServer.getPort()));

    // Initialize Node 2 Client
    this.node2FlowConfigClient = new FlowConfigClient(
            String.format("http://localhost:%s/", this.node2GobblinServiceManager.restliServer.getPort()));
}

From source file:org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.java

protected final Connection createConnection(String url, Properties info) throws SQLException {
    Properties augmentedInfo = PropertiesUtil.deepCopy(info);
    augmentedInfo.putAll(getDefaultProps().asMap());
    ConnectionQueryServices connectionServices = getConnectionQueryServices(url, augmentedInfo);
    PhoenixConnection connection = connectionServices.connect(url, augmentedInfo);
    return connection;
}

From source file:org.apache.geode.management.internal.cli.commands.ConnectCommand.java

Properties loadProperties(File... files) {
    Properties properties = new Properties();
    if (files == null) {
        return properties;
    }//from  ww w  . java  2 s  .c  o m
    for (File file : files) {
        if (file != null) {
            properties.putAll(loadPropertiesFromFile(file));
        }
    }
    return properties;
}

From source file:com.baidu.cc.spring.ConfigCenterPropertyPlaceholderConfigurer.java

/**
 * if properties already loaded will ignore repeated load.
 * //from w w  w  . j a  v  a  2  s.c o m
 * @param props loaded properties.
 * @throws IOException IO exception
 */
@Override
protected void loadProperties(Properties props) throws IOException {
    if (cachedProps != null) {
        props.putAll(cachedProps);
        return;
    }

    super.loadProperties(props);
}

From source file:com.webpagebytes.cms.local.WPBLocalFileStorage.java

public void updateFileCustomProperties(WPBFilePath file, Map<String, String> customProps) throws IOException {
    String fullFilePath = getLocalFullDataPath(file);
    if (!checkIfFileExists(fullFilePath)) {
        throw new IOException("file does not already exists");
    }//from   ww  w.  jav  a 2 s .  c  om

    String metaPath = getLocalFullMetaPath(file);
    Properties props = getFileProperties(metaPath);

    customProps.remove("path");
    customProps.remove("contentType");
    customProps.remove("size");
    customProps.remove("md5");
    customProps.remove("crc32");
    customProps.remove("creationTime");
    customProps.remove("filePath");

    props.putAll(customProps);

    storeFileProperties(props, metaPath);
}

From source file:org.apache.archiva.redback.rest.services.DefaultUtilServices.java

private void loadResource(final Properties finalProperties, String resourceName, String locale)
        throws IOException {
    InputStream is = null;//from w  w w  .j  a  v  a2 s.  c  om
    Properties properties = new Properties();
    try {
        if (StringUtils.isNotEmpty(locale)) {
            resourceName = resourceName + "_" + locale;
        }
        resourceName = resourceName + ".properties";
        is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
        if (is != null) {
            properties.load(is);
            finalProperties.putAll(properties);
        } else {
            if (!StringUtils.equalsIgnoreCase(locale, "en")) {
                log.info("cannot load resource {}", resourceName);
            }
        }
    } finally {
        IOUtils.closeQuietly(is);
    }

}

From source file:net.sourceforge.pmd.util.database.DBType.java

/**
 * Load properties from one or more files or resources.
 *
 * <p>/*from  w  ww . j  a v a2s .  c  om*/
 * This method recursively finds property files or JAR resources matching
 * {@matchstring}.
 * </p>
 * .
 * <p>
 * The method is intended to be able to use , so any
 *
 * @param matchString
 * @return "current" set of properties (from one or more resources/property
 *         files)
 */
private Properties loadDBProperties(String matchString) throws IOException {
    LOGGER.entering(DBType.class.getCanonicalName(), matchString);
    // Locale locale = Control.g;
    ResourceBundle resourceBundle = null;
    InputStream stream = null;

    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.finest("class_path+" + System.getProperty("java.class.path"));
    }

    /*
     * Attempt to match properties files in this order:- File path with
     * properties suffix File path without properties suffix Resource
     * without class prefix Resource with class prefix
     */
    try {
        File propertiesFile = new File(matchString);
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("Attempting File no file suffix: " + matchString);
        }
        stream = new FileInputStream(propertiesFile);
        resourceBundle = new PropertyResourceBundle(stream);
        propertiesSource = propertiesFile.getAbsolutePath();
        LOGGER.finest("FileSystemWithoutExtension");
    } catch (FileNotFoundException notFoundOnFilesystemWithoutExtension) {
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest("notFoundOnFilesystemWithoutExtension");
            LOGGER.finest("Attempting File with added file suffix: " + matchString + ".properties");
        }
        try {
            File propertiesFile = new File(matchString + ".properties");
            stream = new FileInputStream(propertiesFile);
            resourceBundle = new PropertyResourceBundle(stream);
            propertiesSource = propertiesFile.getAbsolutePath();
            LOGGER.finest("FileSystemWithExtension");
        } catch (FileNotFoundException notFoundOnFilesystemWithExtensionTackedOn) {
            if (LOGGER.isLoggable(Level.FINEST)) {
                LOGGER.finest("Attempting JARWithoutClassPrefix: " + matchString);
            }
            try {
                resourceBundle = ResourceBundle.getBundle(matchString);
                propertiesSource = "[" + INTERNAL_SETTINGS + "]" + File.separator + matchString + ".properties";
                LOGGER.finest("InJarWithoutPath");
            } catch (Exception notInJarWithoutPath) {
                if (LOGGER.isLoggable(Level.FINEST)) {
                    LOGGER.finest("Attempting JARWithClass prefix: " + DBType.class.getCanonicalName() + "."
                            + matchString);
                }
                try {
                    resourceBundle = ResourceBundle
                            .getBundle(DBType.class.getPackage().getName() + "." + matchString);
                    propertiesSource = "[" + INTERNAL_SETTINGS + "]" + File.separator + matchString
                            + ".properties";
                    LOGGER.finest("found InJarWithPath");
                } catch (Exception notInJarWithPath) {
                    notInJarWithPath.printStackTrace();
                    notFoundOnFilesystemWithExtensionTackedOn.printStackTrace();
                    throw new RuntimeException(" Could not locate DBTYpe settings : " + matchString,
                            notInJarWithPath);
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(stream);
    }

    // Properties in this matched resource
    Properties matchedProperties = getResourceBundleAsProperties(resourceBundle);
    resourceBundle = null;
    String saveLoadedFrom = getPropertiesSource();

    /*
     * If the matched properties contain the "extends" key, use the value as
     * a matchstring, to recursively set the properties before overwriting
     * any previous properties with the matched properties.
     */
    String extendedPropertyFile = (String) matchedProperties.remove("extends");
    if (null != extendedPropertyFile && !"".equals(extendedPropertyFile.trim())) {
        Properties extendedProperties = loadDBProperties(extendedPropertyFile.trim());

        // Overwrite extended properties with properties in the matched
        // resource
        extendedProperties.putAll(matchedProperties);
        matchedProperties = extendedProperties;
    }

    /*
     * Record the location of the original matched resource/property file,
     * and the current set of properties secured.
     */
    propertiesSource = saveLoadedFrom;
    setProperties(matchedProperties);

    return matchedProperties;
}

From source file:com.webpagebytes.cms.controllers.FlatStorageImporterExporter.java

private void exportToXMLFormat(Map<String, Object> props, OutputStream os) throws IOException {
    Properties properties = new Properties();
    properties.putAll(props);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    properties.storeToXML(bos, "", "UTF-8");
    byte metadataBytes[] = bos.toByteArray();
    os.write(metadataBytes);//w  w w.ja  va2  s  .  c  o m
}