Example usage for java.util Properties put

List of usage examples for java.util Properties put

Introduction

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

Prototype

@Override
    public synchronized Object put(Object key, Object value) 

Source Link

Usage

From source file:com.googlecode.flyway.commandline.Main.java

/**
 * Initializes the properties with the default configuration for the command-line tool.
 *
 * @param properties The properties object to initialize.
 *///from ww w.  j  a v a2  s  .c om
private static void initializeDefaults(Properties properties) {
    properties.put("flyway.password", "");
    properties.put("flyway.locations", "/,db/migration");
}

From source file:org.dcache.xrootd.spring.ChannelHandlerFactoryFactoryBean.java

private static Properties toProperties(final Map<String, Object> env) {
    Replaceable replaceable = new Replaceable() {
        @Override/*  w ww . ja  v  a2s  .c  om*/
        public String getReplacement(String name) {
            Object value = env.get(name);
            return (value == null) ? null : value.toString().trim();
        }
    };

    Properties properties = new Properties();
    for (Map.Entry<String, Object> e : env.entrySet()) {
        String key = e.getKey();
        String value = String.valueOf(e.getValue());
        properties.put(key, Formats.replaceKeywords(value, replaceable));
    }

    return properties;
}

From source file:ddf.security.PropertiesLoader.java

/**
 * Will attempt to load properties from a file using the given classloader. If that fails,
 * several other methods will be tried until the properties file is located.
 *
 * @param propertiesFile/*from   w w  w . j  a v a  2 s. c  o  m*/
 * @param classLoader
 * @return Properties
 */
public static Properties loadProperties(String propertiesFile, ClassLoader classLoader) {
    boolean error = false;
    Properties properties = new Properties();
    if (propertiesFile != null) {
        try {
            LOGGER.debug("Attempting to load properties from {} with Spring PropertiesLoaderUtils.",
                    propertiesFile);
            properties = PropertiesLoaderUtils.loadAllProperties(propertiesFile);
        } catch (IOException e) {
            error = true;
            LOGGER.error("Unable to load properties using default Spring properties loader.", e);
        }
        if (error || properties.isEmpty()) {
            if (classLoader != null) {
                try {
                    LOGGER.debug(
                            "Attempting to load properties from {} with Spring PropertiesLoaderUtils with class loader.",
                            propertiesFile);
                    properties = PropertiesLoaderUtils.loadAllProperties(propertiesFile, classLoader);
                    error = false;
                } catch (IOException e) {
                    error = true;
                    LOGGER.error("Unable to load properties using default Spring properties loader.", e);
                }
            } else {
                try {
                    LOGGER.debug(
                            "Attempting to load properties from {} with Spring PropertiesLoaderUtils with class loader.",
                            propertiesFile);
                    properties = PropertiesLoaderUtils.loadAllProperties(propertiesFile,
                            PropertiesLoader.class.getClassLoader());
                    error = false;
                } catch (IOException e) {
                    error = true;
                    LOGGER.error("Unable to load properties using default Spring properties loader.", e);
                }
            }
        }

        if (error || properties.isEmpty()) {
            LOGGER.debug("Attempting to load properties from file system: {}", propertiesFile);
            File propFile = new File(propertiesFile);
            // If properties file has fully-qualified absolute path (which
            // the blueprint file specifies) then can load it directly.
            if (propFile.isAbsolute()) {
                LOGGER.debug("propertiesFile {} is absolute", propertiesFile);
                propFile = new File(propertiesFile);
            } else {
                String karafHome = System.getProperty("karaf.home");
                if (karafHome != null && !karafHome.isEmpty()) {
                    propFile = new File(karafHome, propertiesFile);
                } else {
                    karafHome = System.getProperty("ddf.home");
                    if (karafHome != null && !karafHome.isEmpty()) {
                        propFile = new File(karafHome, propertiesFile);
                    } else {
                        propFile = new File(propertiesFile);
                    }
                }
            }
            properties = new Properties();

            try (InputStreamReader reader = new InputStreamReader(new FileInputStream(propertiesFile),
                    StandardCharsets.UTF_8)) {
                properties.load(reader);
            } catch (FileNotFoundException e) {
                error = true;
                LOGGER.error("Could not find properties file: {}", propFile.getAbsolutePath(), e);
            } catch (IOException e) {
                error = true;
                LOGGER.error("Error reading properties file: {}", propFile.getAbsolutePath(), e);
            }
        }
        if (error || properties.isEmpty()) {
            LOGGER.debug("Attempting to load properties as a resource: {}", propertiesFile);
            InputStream ins = PropertiesLoader.class.getResourceAsStream(propertiesFile);
            if (ins != null) {
                try {
                    properties.load(ins);
                    ins.close();
                } catch (IOException e) {
                    LOGGER.error("Unable to load properties: {}", propertiesFile, e);
                } finally {
                    IOUtils.closeQuietly(ins);
                }
            }
        }

        //replace any ${prop} with system properties
        Properties filtered = new Properties();
        for (Map.Entry<?, ?> entry : properties.entrySet()) {
            filtered.put(StrSubstitutor.replaceSystemProperties(entry.getKey()),
                    StrSubstitutor.replaceSystemProperties(entry.getValue()));
        }
        properties = filtered;

    } else {
        LOGGER.debug("Properties file must not be null.");
    }

    return properties;
}

From source file:Main.java

public static boolean savePreferencesInExternal(Context ctx, SharedPreferences pref) {

    Properties propfile = new Properties();
    Map<String, ?> keymap = pref.getAll();
    Iterator<String> keyit = keymap.keySet().iterator();
    Log.d("External", "Saving prefrences to external Storages");

    while (keyit.hasNext()) {
        String key = keyit.next();
        propfile.put(key, keymap.get(key));
    }//from  w w w .j a v a 2  s. c  om
    if (isExternalStorageAvailableforWriting() == true) {
        try {
            propfile.storeToXML(new FileOutputStream(new File(ctx.getExternalFilesDir(null), "install_info")),
                    null);
        } catch (Exception e) {

            e.printStackTrace();
        }

        Log.d("External", "Saved prefrences to external ");
        return true;
    } else {
        Log.d("External", "Failed to Save prefrences for external ");
        return false;
    }
}

From source file:com.qubole.quark.planner.test.PartialCubeTest.java

protected static SqlQueryParser getParser(String filter) throws JsonProcessingException, QuarkException {
    Properties info = new Properties();
    info.put("unitTestMode", "true");
    info.put("schemaFactory", "com.qubole.quark.planner.test.PartialCubeSchemaFactory");

    ImmutableList<String> defaultSchema = ImmutableList.of("TPCDS");
    final ObjectMapper mapper = new ObjectMapper();

    info.put("defaultSchema", mapper.writeValueAsString(defaultSchema));
    info.put("filter", filter);
    return new SqlQueryParser(info);
}

From source file:uk.ac.cam.cl.dtg.picky.client.analytics.Analytics.java

private static void fillProperties(Properties properties, Plan plan) {
    if (plan == null)
        return;//w w w . ja v  a2s. c o  m

    long bytesToDownload = plan.getChunksToDownload().stream().mapToLong(c -> c.getLengthCompressed()).sum();

    properties.put(KEY_PLAN_DELETE_DIR_ACTIONS, "" + plan.getDeleteDirActions().size());
    properties.put(KEY_PLAN_DELETE_FILE_ACTIONS, "" + plan.getDeleteFileActions().size());
    properties.put(KEY_PLAN_INSTALL_FILE_ACTIONS, "" + plan.getInstallFileActions().size());
    properties.put(KEY_PLAN_MAKE_DIR_ACTIONS, "" + plan.getMakeDirActions().size());
    properties.put(KEY_PLAN_UPDATE_FILE_ACTIONS, "" + plan.getUpdateFileActions().size());

    properties.put(KEY_PLAN_CHUNKS_TO_DOWNLOAD, "" + plan.getChunksToDownload().size());
    properties.put(KEY_PLAN_BYTES_TO_DOWNLOAD, "" + bytesToDownload);
}

From source file:es.eucm.rage.realtime.BeaconingBundleOverallFullDataTest.java

private static Producer<Long, String> createProducer() {
    Properties props = new Properties();
    props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
    props.put(ProducerConfig.CLIENT_ID_CONFIG, "KafkaExampleProducer");
    props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, LongSerializer.class.getName());
    props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
    return new KafkaProducer<>(props);
}

From source file:com.glaf.core.config.CustomProperties.java

public static Properties getProperties() {
    Properties p = new Properties();
    Enumeration<?> e = properties.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        String value = properties.getProperty(key);
        p.put(key, value);
    }/*  ww w.  j av  a 2 s.  c  o  m*/
    return p;
}

From source file:at.kc.tugraz.ss.cloud.impl.fct.op.SSCloudPublishServiceFct.java

License:asdf

private static void startServiceRemotely(final String serviceDestDirPath, final String host,
        final String userName, final String password) throws Exception {

    Session session = null;//ww w.  j a v  a  2  s  .  c  om
    Channel channel = null;

    try {

        final ChannelExec channelExec;
        JSch jsch = new JSch();

        session = jsch.getSession(userName, host, 22);

        java.util.Properties config = new java.util.Properties();
        config.put("StrictHostKeyChecking", "no");

        session.setConfig(config);
        session.setPassword(password);
        session.connect();

        String command = "cd " + serviceDestDirPath + SSStrU.semiColon
                + "java -jar -Dlog4j.configuration=file:log4j.properties " + serviceDestDirPath
                + SSVocConf.fileNameSSSJar;

        channel = session.openChannel("exec");

        channelExec = (ChannelExec) channel;
        channelExec.setCommand(command);

        channel.setInputStream(null);

        ((ChannelExec) channel).setErrStream(System.err);

        channel.connect();

        Thread.sleep(4000);

    } catch (Exception error) {
        SSServErrReg.regErrThrow(error);
    } finally {

        if (channel != null) {
            channel.disconnect();
        }

        if (session != null) {
            session.disconnect();
        }
    }
}

From source file:scalespace.filter.Gaussian_Derivative_.java

public static void savePreferences(Properties prefs) {
    prefs.put(GN, Integer.toString(nn));
    prefs.put(GM, Integer.toString(mm));
    prefs.put(LEN, Integer.toString(sz));
    prefs.put(ISSEP, Boolean.toString(sep));
    prefs.put(SCNORM, Boolean.toString(scnorm));
    // prefs.put(SIGMA, Float.toString(sigma));

}