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:io.hawkcd.agent.AgentConfiguration.java

private static String generateAgentId(Properties properties) {
    UUID agentId = UUID.randomUUID();

    try {/*from  w w w  . jav a 2  s.c  o  m*/
        File configFile = new File(ConfigConstants.AGENT_CONFIG_FILE_LOCATION);
        OutputStream output = new FileOutputStream(configFile);
        properties.setProperty("agentId", agentId.toString());
        properties.store(output, null);
        output.close();
    } catch (IOException io) {
        io.printStackTrace();
    }

    return agentId.toString();
}

From source file:com.ztesoft.zsmart.remoting.util.ServerUtil.java

/**
 * Description:commandLine -> properties <br>
 * //from  w  w  w.ja v a2s  .  c o m
 * @author wang.jun<br>
 * @taskId <br>
 * @param commandLine
 * @return <br>
 */
public static Properties commandLine2Properties(final CommandLine commandLine) {
    Properties properties = new Properties();
    Option[] opts = commandLine.getOptions();

    if (opts != null) {
        for (Option opt : opts) {
            String name = opt.getLongOpt();
            String value = commandLine.getOptionValue(name);
            if (value != null) {
                properties.setProperty(name, value);
            }
        }
    }
    return properties;
}

From source file:com.adaptris.core.services.metadata.SimpleSequenceNumberService.java

private static void incrementSequenceNumberProperty(Properties p, Long count, Long maximum) {
    if (greaterThanMaximum(String.valueOf(count + 1), maximum)) {
        p.setProperty(PROPERTY_KEY, ONE);
    } else {//from  ww  w  . ja va 2  s.  c o m
        p.setProperty(PROPERTY_KEY, String.valueOf(count + 1));
    }
}

From source file:org.uimafit.factory.ExternalResourceFactoryTest.java

@BeforeClass
public static void initJNDI() throws Exception {
    // Set up JNDI context to test the JndiResourceLocator
    final SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
    Properties deDict = new Properties();
    deDict.setProperty("Hans", "proper noun");
    builder.bind("dictionaries/german", deDict);
    builder.activate();/*from  w ww. ja  v a 2  s. c o  m*/
}

From source file:io.symcpe.hendrix.api.dao.TestTemplateManager.java

@BeforeClass
public static void beforeClass() throws Exception {
    Properties config = new Properties(System.getProperties());
    File db = new File(TARGET_RULES_DB);
    if (db.exists()) {
        FileUtils.deleteDirectory(db);//from w  ww. ja  v a 2s. co m
    }
    config.setProperty("javax.persistence.jdbc.url", CONNECTION_STRING);
    try {
        emf = Persistence.createEntityManagerFactory("hendrix", config);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }

    EntityManager em = emf.createEntityManager();

    Tenant tenant = new Tenant();
    tenant.setTenant_id(TENANT_ID_1);
    tenant.setTenant_name(TEST_TENANT);
    TenantManager.getInstance().createTenant(em, tenant);

    em.close();
}

From source file:gdt.data.grain.Locator.java

/**
   * Append the name/value pair to the locator. If the name
   * already exists its value  will be replaced. 
   * @param locator$ the locator string//www  .j ava  2 s  .co m
   * @param name$ the name
   * @param value$ the value$ 
* @return  the locator string.   
   */
public static String append(String locator$, String name$, String value$) {
    if (name$ == null || value$ == null)
        return locator$;
    Properties locator = toProperties(locator$);
    if (locator == null)
        locator = new Properties();
    locator.setProperty(name$, value$);
    return toString(locator);
}

From source file:com.mkwhitacre.kafka.mapreduce.utils.KafkaBrokerTestHarness.java

/**
 * Creates a collection of Kafka Broker configurations based on the number of brokers and zookeeper.
 * @param brokers the number of brokers to create configuration for.
 * @param zookeeperPort the zookeeper port for the brokers to connect to.
 * @param baseProperties basic properties that should be applied for each broker config.  These properties will be
 *                       honored in favor of any default properties.
 * @return configuration for a collection of brokers.
 * @throws IllegalArgumentException if {@code brokers} is less than 1 or {@code baseProperties} is {@code null}.
 *///from w w w .  jav  a2s .c o m
public static List<KafkaConfig> getBrokerConfig(int brokers, int zookeeperPort, Properties baseProperties) {
    if (brokers < 1) {
        throw new IllegalArgumentException("Invalid broker count: " + brokers);
    }
    if (baseProperties == null) {
        throw new IllegalArgumentException("The 'baseProperties' cannot be 'null'.");
    }

    int ports[] = KafkaTestUtils.getPorts(brokers);

    List<KafkaConfig> configs = new ArrayList<KafkaConfig>(brokers);
    for (int i = 0; i < brokers; ++i) {
        Properties props = new Properties();
        props.setProperty(KAFKA_ZOOKEEPERS, "localhost:" + zookeeperPort);
        props.setProperty("broker.id", String.valueOf(i + 1));
        props.setProperty("host.name", "localhost");
        props.setProperty("port", String.valueOf(ports[i]));
        props.setProperty("log.dir", KafkaTestUtils.getTempDir().getAbsolutePath());
        props.setProperty("log.flush.interval.messages", String.valueOf(1));
        props.setProperty("num.partitions", String.valueOf(PARTITIONS_PER_TOPIC));
        props.setProperty("default.replication.factor", String.valueOf(brokers));
        props.setProperty("auto.create.topics.enable", Boolean.FALSE.toString());

        props.putAll(baseProperties);

        configs.add(new KafkaConfig(props));
    }
    return configs;
}

From source file:com.srotya.tau.api.dao.TestTemplateManager.java

@BeforeClass
public static void beforeClass() throws Exception {
    Properties config = new Properties(System.getProperties());
    File db = new File(TARGET_RULES_DB);
    if (db.exists()) {
        FileUtils.deleteDirectory(db);/*from w w  w . j  a  va 2s . co m*/
    }
    config.setProperty("javax.persistence.jdbc.url", CONNECTION_STRING);
    try {
        emf = Persistence.createEntityManagerFactory("tau", config);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }

    EntityManager em = emf.createEntityManager();

    RuleGroup ruleGroup = new RuleGroup();
    ruleGroup.setRuleGroupId(RULE_GROUP_ID_1);
    ruleGroup.setRuleGroupName(TEST_RULE_GROUP);
    RuleGroupManager.getInstance().createRuleGroup(em, ruleGroup);

    em.close();
}

From source file:org.unbunt.ella.lang.sql.DBUtils.java

public static DriverManagerDataSource createDataSourceFromProps(Properties props, String user, String pass,
        String classOrType) throws DBConnectionFailedException {
    // canonicalize user/username property
    if (props.getProperty("username") != null && props.getProperty("user") == null) {
        props.setProperty("user", props.getProperty("username"));
    } else if (props.getProperty("user") != null && props.getProperty("username") == null) {
        props.setProperty("username", props.getProperty("user"));
    }//w ww.j a va 2  s. co m

    String url = props.getProperty("url");
    if (url == null) {
        throw new DBConnectionFailedException("Missing url property");
    }

    if (user == null) {
        user = props.getProperty("username");
    }
    if (pass == null) {
        pass = props.getProperty("password");
    }

    if (classOrType == null) {
        classOrType = props.getProperty("type");
    }
    if (classOrType == null) {
        classOrType = props.getProperty("driverClassName");
    }

    return createDataSourceInternal(props, url, user, pass, classOrType);
}

From source file:lux.xqts.TestCase.java

public static String resultToString(XdmNode node) throws XPathException {
    StringWriter sw = new StringWriter();
    Properties props = new Properties();
    props.setProperty("method", "xml");
    props.setProperty("indent", "no");
    props.setProperty("omit-xml-declaration", "yes");
    QueryResult.serialize(node.getUnderlyingNode(), new StreamResult(sw), props);
    return sw.toString();
}