Example usage for java.util Properties setProperty

List of usage examples for java.util Properties setProperty

Introduction

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

Prototype

public synchronized Object setProperty(String key, String value) 

Source Link

Document

Calls the Hashtable method put .

Usage

From source file:GitHubApiTestCase.java

/**
 * It's not possible to store username/password in the test file,
 * this cretentials are stored in a properties file
 * under user home directory./*  w w  w  .  ja  v a2 s . co  m*/
 * <p/>
 * This method would be used to fetch parameters for the test
 * and allow to avoid committing createntials with source file.
 *
 * @return username, repo, password
 */
@NotNull
public static Properties readGitHubAccount() {
    File propsFile = new File(System.getProperty("user.home"), ".github.test.account");
    System.out.println("Loading properites from: " + propsFile);
    try {
        if (!propsFile.exists()) {
            FileUtil.createParentDirs(propsFile);
            Properties ps = new Properties();
            ps.setProperty(URL, "https://api.github.com");
            ps.setProperty(USERNAME, "jonnyzzz");
            ps.setProperty(REPOSITORY, "TeamCity.GitHub");
            ps.setProperty(PASSWORD_REV, rewind("some-password-written-end-to-front"));
            ps.setProperty(PR_COMMIT, "4e86fc6dcef23c733f36bc8bbf35fb292edc9cdb");
            ps.setProperty(ACCESS_TOKEN, "insert a github personal access token here");
            PropertiesUtil.storeProperties(ps, propsFile, "mock properties");
            return ps;
        } else {
            return PropertiesUtil.loadProperties(propsFile);
        }
    } catch (IOException e) {
        throw new RuntimeException("Could not read Amazon Access properties: " + e.getMessage(), e);
    }
}

From source file:DatabaseTest.java

/**
 * Initialize the logging system. It is used by dbunit.
 *///from w ww .  ja v  a2s  .c o m
@BeforeClass
public static void setupLogger() throws Exception {
    Properties logProperties = new Properties();
    logProperties.setProperty("log4j.rootCategory", "DEBUG, CONSOLE");
    logProperties.setProperty("log4j.appender.CONSOLE", "org.apache.log4j.ConsoleAppender");
    logProperties.setProperty("log4j.appender.CONSOLE.Threshold", "ERROR");
    logProperties.setProperty("log4j.appender.CONSOLE.layout", "org.apache.log4j.PatternLayout");
    logProperties.setProperty("log4j.appender.CONSOLE.layout.ConversionPattern", "- %m%n");
    PropertyConfigurator.configure(logProperties);
}

From source file:com.moviejukebox.tools.TraktTV.java

private static void storeTraktTvProperties(TokenResponse response) {
    // set properties
    Properties props = new Properties();
    props.setProperty(PROP_ACCESS_TOKEN, response.getAccessToken());
    props.setProperty(PROP_REFRESH_TOKEN, response.getRefreshToken());
    props.setProperty(PROP_EXPIRATION_DATE, String.valueOf(buildExpirationDate(response)));

    // store properties file
    File propsFile = new File(PROPS_FILE);
    try (OutputStream out = new FileOutputStream(propsFile)) {
        props.store(out, "Trakt.TV settings");
    } catch (Exception e) {
        LOG.error("Failed to store Trakt.TV properties");
    }/*from  w w w  .j  a va  2s.  c o m*/
}

From source file:com.smartitengineering.events.async.api.impl.hub.AppTest.java

@BeforeClass
public static void globalSetup() throws Exception {

    /*/*www  . j a v a2 s . com*/
     * Start web application container
     */
    jettyServer = new Server(PORT);
    HandlerList handlerList = new HandlerList();
    /*
     * The following is for solr for later, when this is to be used it
     */
    Handler solr = new WebAppContext("./target/hub/", "/hub");
    handlerList.addHandler(solr);
    jettyServer.setHandler(handlerList);
    jettyServer.setSendDateHeader(true);
    jettyServer.start();

    /*
     * Setup client properties
     */
    System.setProperty(ApplicationWideClientFactoryImpl.TRACE, "true");

    Client client = CacheableClient.create();
    client.resource("http://localhost:10080/hub/api/channels/test")
            .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).put("{\"name\":\"test\"}");
    LOGGER.info("Created test channel!");
    /*
     * Ensure DIs done
     */
    Properties properties = new Properties();
    properties.setProperty(GuiceUtil.CONTEXT_NAME_PROP, "com.smartitengineering");
    properties.setProperty(GuiceUtil.IGNORE_MISSING_DEP_PROP, Boolean.TRUE.toString());
    properties.setProperty(GuiceUtil.MODULES_LIST_PROP, ConfigurationModule.class.getName());
    final GuiceUtil instance = GuiceUtil.getInstance(properties);
    instance.register();
    LOGGER.info("Register injectors!");
    /*
     * Initialize injector
     */
    injector = instance.getInjectors()[0];
    publisher = injector.getInstance(EventPublisher.class);
    subscriber = injector.getInstance(EventSubscriber.class);
    LOGGER.info("Initialize publisher and subscriber!");
}

From source file:hudson.plugins.blazemeter.utils.Utils.java

public static String version() {
    Properties props = new Properties();
    try {//from  w ww . j  a  v a 2s.com
        props.load(Utils.class.getResourceAsStream("/version.properties"));
    } catch (IOException ex) {
        props.setProperty(Constants.VERSION, "N/A");
    }
    return props.getProperty(Constants.VERSION);
}

From source file:com.continuuity.weave.kafka.client.KafkaTest.java

private static Properties generateKafkaConfig(String zkConnectStr) throws IOException {
    int port = Networks.getRandomPort();
    Preconditions.checkState(port > 0, "Failed to get random port.");

    Properties prop = new Properties();
    prop.setProperty("log.dir", TMP_FOLDER.newFolder().getAbsolutePath());
    prop.setProperty("zk.connect", zkConnectStr);
    prop.setProperty("num.threads", "8");
    prop.setProperty("port", Integer.toString(port));
    prop.setProperty("log.flush.interval", "1000");
    prop.setProperty("max.socket.request.bytes", "104857600");
    prop.setProperty("log.cleanup.interval.mins", "1");
    prop.setProperty("log.default.flush.scheduler.interval.ms", "1000");
    prop.setProperty("zk.connectiontimeout.ms", "1000000");
    prop.setProperty("socket.receive.buffer", "1048576");
    prop.setProperty("enable.zookeeper", "true");
    prop.setProperty("log.retention.hours", "24");
    prop.setProperty("brokerid", "0");
    prop.setProperty("socket.send.buffer", "1048576");
    prop.setProperty("num.partitions", "1");
    // Use a really small file size to force some flush to happen
    prop.setProperty("log.file.size", "1024");
    prop.setProperty("log.default.flush.interval.ms", "1000");
    return prop;//from w ww  .jav  a 2s. co  m
}

From source file:com.snowplowanalytics.snowplow.hadoop.hive.SnowPlowEventDeserializer.java

/**
 * A helper which deserializes and inspects a single row
 *
 * @param line The line of text to deserialize
 * @param verbose Whether to debug-print the contents of the struct using reflection
 * @param continueOn Whether to continue on an unexpected error or not
 * @return The struct object from deserializing the text
 * @throws SerDeException if there is a problem deserializing the line, or reflection-inspecting the struct's contents
 *///from w  w w. j a  v a  2 s  .  c o m
public static Object deserializeLine(String line, Boolean verbose, Boolean continueOn) throws SerDeException {

    // Prep the deserializer
    SnowPlowEventDeserializer serDe = new SnowPlowEventDeserializer();
    Configuration conf = new Configuration();
    Properties tbl = new Properties();
    tbl.setProperty(CONTINUE_ON, continueOn ? "1" : "0");

    serDe.initialize(conf, tbl);

    // Run the deserializer with the sample row
    Text text = new Text(line);
    Object row = serDe.deserialize(text);

    // Loop through and output each field in the struct, if required.
    if (verbose) {
        ReflectionStructObjectInspector oi = (ReflectionStructObjectInspector) serDe.getObjectInspector();
        List<? extends StructField> fieldRefs = oi.getAllStructFieldRefs();
        for (int i = 0; i < fieldRefs.size(); i++) {
            System.out.println(fieldRefs.get(i).toString());
            Object fieldData = oi.getStructFieldData(row, fieldRefs.get(i));
            if (fieldData == null) {
                System.out.println("null");
            } else {
                System.out.println(fieldData.toString());
            }
        }
    }

    return row;
}

From source file:Main.java

public static boolean setProperty(String filePath, String fileName, Map<String, String> propertyMap) {
    try {//from   w w w  . j a  va 2  s.  c om
        Properties p = loadPropertyInstance(filePath, fileName);
        for (String name : propertyMap.keySet()) {
            p.setProperty(name, propertyMap.get(name));
        }
        String comment = "Update '" + propertyMap.keySet().toString() + "' value";
        return storePropertyInstance(filePath, fileName, p, comment);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:edu.mit.lib.mama.Mama.java

private static Properties findConfig(String[] args) {
    Properties props = new Properties();
    if (args.length == 3) {
        props.setProperty("dburl", args[0]);
        props.setProperty("user", args[1]);
        props.setProperty("password", args[2]);
    } else {/* w w w. j  a v a2 s. c  o  m*/
        props.setProperty("dburl", nullToEmpty(System.getenv("MAMA_DB_URL")));
        props.setProperty("user", nullToEmpty(System.getenv("MAMA_DB_USER")));
        props.setProperty("password", nullToEmpty(System.getenv("MAMA_DB_PASSWD")));
        props.setProperty("readOnly", "true"); // Postgres only, h2 chokes on this directive
    }
    return props;
}

From source file:ezbake.security.EzSecurityITBase.java

@BeforeClass
public static void setUpServerPool() throws Exception {
    Random portChooser = new Random();
    int port = portChooser.nextInt((34999 - 30000) + 1) + 30000;
    int zooPort = portChooser.nextInt((20499 - 20000) + 1) + 20000;

    redisServer = new LocalRedis();

    EzConfiguration ezConfiguration = new EzConfiguration(new ClasspathConfigurationLoader());
    properties = ezConfiguration.getProperties();
    properties.setProperty(EzBakePropertyConstants.REDIS_HOST, "localhost");
    properties.setProperty(EzBakePropertyConstants.REDIS_PORT, Integer.toString(redisServer.getPort()));
    properties.setProperty(EzBakePropertyConstants.ZOOKEEPER_CONNECTION_STRING,
            "localhost:" + String.valueOf(zooPort));
    properties.setProperty(FileUAService.USERS_FILENAME,
            EzSecurityITBase.class.getResource("/users.json").getFile());
    properties.setProperty(EzBakePropertyConstants.EZBAKE_ADMINS_FILE,
            EzSecurityITBase.class.getResource("/admins").getFile());
    properties.setProperty(AdminServiceModule.PUBLISHING, Boolean.TRUE.toString());

    Properties localConfig = new Properties();
    localConfig.putAll(properties);/*ww  w .  ja  va 2 s  .c o m*/
    localConfig.setProperty(EzBakePropertyConstants.EZBAKE_CERTIFICATES_DIRECTORY,
            EzSecurityITBase.class.getResource("/pki/server").getFile());
    localConfig.setProperty("storage.directory", folder.getRoot().toString());

    serverPool = new ThriftServerPool(localConfig, port);
    serverPool.startCommonService(new EzSecurityHandler(), EzSecurityServicesConstants.SECURITY_SERVICE_NAME,
            "12345");
    serverPool.startCommonService(new ezbake.groups.service.EzBakeThriftService(),
            EzGroupsConstants.SERVICE_NAME, "12345");

    ServiceDiscoveryClient client = new ServiceDiscoveryClient(
            properties.getProperty(EzBakePropertyConstants.ZOOKEEPER_CONNECTION_STRING));
    client.setSecurityIdForCommonService(AppName, "10000000");
    client.setSecurityIdForApplication(AppName, "10000000");

    properties.setProperty(EzBakePropertyConstants.EZBAKE_CERTIFICATES_DIRECTORY,
            EzSecurityITBase.class.getResource("/pki/client").getFile());
    properties.setProperty(EzBakePropertyConstants.EZBAKE_SECURITY_ID, "10000000");
}