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.qubole.quark.planner.test.LayeredCubeTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    Properties info = new Properties();
    info.put("unitTestMode", "true");
    info.put("schemaFactory", "com.qubole.quark.planner.test.LayeredCubeTest$SchemaFactory");

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

    info.put("defaultSchema", mapper.writeValueAsString(defaultSchema));
    parser = new SqlQueryParser(info);
}

From source file:com.chigix.autosftp.Application.java

private static void sshOpen() throws JSchException {
    if (isOpened) {
        return;//from  w w w . jav a  2 s  .  c  om
    }
    isOpened = true;
    Session currentSession = sshSession;
    final Properties sshConfig = new Properties();
    sshConfig.put("StrictHostKeyChecking", "no");
    for (int i = 0; i < 3; i++) {
        currentSession.setConfig(sshConfig);
        try {
            currentSession.connect();
        } catch (JSchException ex) {
            if (ex.getCause() instanceof ConnectException) {
                System.err.println("ssh: connect to host " + currentSession.getHost() + " port "
                        + currentSession.getPort() + ": " + ex.getCause().getMessage());
                System.exit(1);
            }
            if (ex.getMessage().equals("Auth fail")) {
                Console console = System.console();
                if (console == null) {
                    System.err.println(
                            "Couldn't get console instance, Please consider involving identity_file in command line.");
                    System.exit(1);
                }
                currentSession.disconnect();
                char passwordArray[] = console.readPassword("richard@192.168.2.103's password: ");
                Session newSession = new JSch().getSession(sshSession.getUserName(), sshSession.getHost(),
                        sshSession.getPort());
                newSession.setConfig(sshConfig);
                newSession.setPassword(new String(passwordArray));
                currentSession = newSession;
                continue;
            }
            Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
            return;
        }
        break;
    }
    sshSession = currentSession;
    Channel channel = sshSession.openChannel("sftp");
    channel.connect();
    sftpChannel = (ChannelSftp) channel;
    sftpChannel.setPty(false);
    if (remotePath == null) {
        try {
            remotePath = Paths.get(sftpChannel.pwd());
        } catch (SftpException ex) {
            Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
            return;
        }
    }
}

From source file:net.firejack.platform.core.utils.MiscUtils.java

/**
 * @param properties/*from www. ja  v  a  2 s.  c  o m*/
 * @param checkFileExists
 * @param property
 * @param value
 * @throws java.io.IOException
 */
public static void setProperties(File properties, boolean checkFileExists, String property, String value)
        throws IOException {
    if (checkFileExists && !properties.exists()) {
        logger.error("Properties file [" + properties.getAbsolutePath() + "] does not exist.");
        throw new FileNotFoundException("Properties file does not found.");
        //            IOHelper.delete(dbProperties);
    }
    Properties props = new Properties();
    if (properties.exists()) {
        FileReader reader = new FileReader(properties);
        props.load(reader);
        reader.close();
    }
    props.put(property, value);
    FileWriter writer = new FileWriter(properties);
    props.store(writer, null);
    writer.flush();
    writer.close();
}

From source file:org.onesun.atomator.core.SubscriptionManager.java

public static Properties toProperties(SecretEntry entry) {
    if (entry != null) {
        Properties properties = new Properties();

        properties.put(Scribe.ScribeOAuthParams.CONSUMER_KEY, entry.getConsumerKey());
        properties.put(Scribe.ScribeOAuthParams.CONSUMER_SECRET, entry.getConsumerSecret());
        properties.put(Scribe.ScribeOAuthParams.REQUEST_TOKEN_VERB, "POST");
        properties.put(Scribe.ScribeOAuthParams.REQUEST_TOKEN_URL, entry.getRequestTokenURL());
        properties.put(Scribe.ScribeOAuthParams.ACCESS_TOKEN_VERB, "POST");
        properties.put(Scribe.ScribeOAuthParams.ACCESS_TOKEN_URL, entry.getAccessTokenURL());
        properties.put(Scribe.ScribeOAuthParams.CALLBACK_URL, Configuration.getCallbackURL());

        properties.put(OAuthSecretsManager.AUTHORIZE_URL, entry.getAuthorizeURL());

        return properties;
    }//w  w w. j a  va2 s.c o  m

    return null;
}

From source file:com.metamx.tranquility.kafka.KafkaConsumerTest.java

private static KafkaConfig getKafkaTestConfig() throws Exception {
    int port;//  w w  w  . j ava  2s  .  c o m
    try (ServerSocket server = new ServerSocket(0)) {
        port = server.getLocalPort();
    }

    Properties props = new Properties();
    props.put("broker.id", "0");
    props.put("host.name", "localhost");
    props.put("port", port);
    props.put("log.dir", tempDir.getPath());
    props.put("zookeeper.connect", zk.getConnectString());
    props.put("replica.socket.timeout.ms", "1500");
    return new KafkaConfig(props);
}

From source file:info.magnolia.cms.core.SystemProperty.java

/**
 * @deprecated since 4.5 - while this still "works" and returns an aggregate of the local properties and those provided by
 * MagnoliaConfigurationProperties, writing to this Property object will not be reflected anywhere.
 *///from  ww w.j  a  v  a 2 s.com
public static Properties getProperties() {
    // DeprecationUtil.isDeprecated();
    // providing a MagnoliaConfigurationProperties-compliant replacement...
    final Properties p = new Properties();
    p.putAll(properties);
    for (String k : magnoliaConfigurationProperties.getKeys()) {
        p.put(k, magnoliaConfigurationProperties.getProperty(k));
    }
    return p;
}

From source file:com.amazon.pay.impl.Util.java

/**
 * This method uses PayConfig to set proxy settings and uses
 * HttpURLConnection instance to make requests.
 *
 * @param method The HTTP method (GET,POST,PUT,etc.).
 * @param url The URL/*from  w ww  . j  a  va 2s  . c o m*/
 * @param urlParameters URL Parameters
 * @param config client configuration container
 * @return ResponseData
 * @throws IOException
 */
public static ResponseData httpSendRequest(String method, String url, String urlParameters,
        Map<String, String> headers, PayConfig config) throws IOException {

    Map<String, String> headerMap = new HashMap<String, String>();

    if (config != null) {

        final String applicationName = config.getApplicationName();
        final String applicationVersion = config.getApplicationVersion();
        StringBuilder userAgent = new StringBuilder(
                ServiceConstants.GITHUB_SDK_NAME + "/" + ServiceConstants.APPLICATION_LIBRARY_VERSION);

        if ((applicationName != null && !applicationName.trim().isEmpty())
                && (applicationVersion != null && !applicationVersion.trim().isEmpty())) {
            userAgent.append(" (" + applicationName + "/" + applicationVersion + "; ");
        } else if (applicationVersion != null && !applicationVersion.trim().isEmpty()) {
            userAgent.append(" (" + applicationVersion + "; ");
        } else if (applicationName != null && !applicationName.trim().isEmpty()) {
            userAgent.append(" (" + applicationName + "; ");
        } else {
            userAgent.append(" (");
        }

        userAgent.append("Java/" + JAVA_VERSION + "; " + OS_NAME + "/" + OS_VERSION + ")");
        headerMap.put("User-Agent", userAgent.toString());

        if (config.getProxyHost() != null) {
            Properties systemSettings = System.getProperties();
            systemSettings.put("proxySet", "true");
            systemSettings.put("http.proxyHost", config.getProxyHost());
            systemSettings.put("http.proxyPort", config.getProxyPort());
            if (config.getProxyUsername() != null && config.getProxyPassword() != null) {
                String password = config.getProxyUsername() + ":" + config.getProxyPassword();
                byte[] encodedPassword = Base64.encodeBase64(password.getBytes());
                if (encodedPassword != null) {
                    headerMap.put("Proxy-Authorization", new String(encodedPassword));
                }
            }
        }
    }

    ResponseData response = Util.httpSendRequest(method, url, urlParameters, headerMap);
    return response;
}

From source file:it.geosolutions.unredd.StatsTests.java

private static Map<String, File> loadTestParams() {

    Properties defaultProperties = new Properties();
    defaultProperties.put(DATA, DEFAULT_DATA);
    defaultProperties.put(CLASSIFICATOR_PREFIX + "1", DEFAULT_CLASSIFICATOR);
    File propFile = loadFileFromResources(PROP_FILE);
    InputStream inStream = null;// w  w w .  j  ava2  s.c o m
    Properties prop = null;
    try {
        inStream = new FileInputStream(propFile);
        prop = new Properties(defaultProperties);
        prop.load(inStream);
    } catch (Exception e) {
        fail("Fail when loading layer path file...");
    }
    // Transform the file names into File objects
    Map<String, File> map = new HashMap<String, File>();
    Enumeration kEnumeration = prop.propertyNames();
    while (kEnumeration.hasMoreElements()) {
        String key = (String) kEnumeration.nextElement();
        if (prop.getProperty(key).startsWith("test-data")) {
            map.put(key, loadFileFromResources(prop.getProperty(key)));
        } else {
            map.put(key, new File(prop.getProperty(key)));
        }
    }
    return map;
}

From source file:com.metamx.tranquility.kafka.KafkaConsumerTest.java

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    tempDir = Files.createTempDir();
    zk = new TestingServer();
    kafka = new KafkaServerStartable(getKafkaTestConfig());
    kafka.startup();//from   w ww.ja v  a 2 s .  c o  m

    Properties props = new Properties();
    props.put("bootstrap.servers",
            String.format("%s:%s", kafka.serverConfig().hostName(), kafka.serverConfig().port()));
    producer = new KafkaProducer<>(props, new StringSerializer(), new StringSerializer());

    channel = new BlockingChannel(kafka.serverConfig().hostName(), kafka.serverConfig().port(),
            BlockingChannel.UseDefaultBufferSize(), BlockingChannel.UseDefaultBufferSize(), 5000);
    channel.connect();

    consumerProperties = new Properties();
    consumerProperties.setProperty("group.id", GROUP_ID);
    consumerProperties.setProperty("zookeeper.connect", zk.getConnectString());
    consumerProperties.setProperty("kafka.zookeeper.connect", zk.getConnectString());
    consumerProperties.setProperty("commit.periodMillis", "90000");
    consumerProperties.setProperty("auto.offset.reset", "smallest");

    zkUtils = ZkUtils.apply(zk.getConnectString(), 5000, 5000, false);
}

From source file:com.migo.utils.GenUtils.java

/**
 * ??//from   w w w .  j av a 2 s.c o  m
 */
public static void generatorCode(Map<String, String> table, List<Map<String, String>> columns,
        ZipOutputStream zip) {
    //??
    Configuration config = getConfig();

    //?
    TableEntity tableEntity = new TableEntity();
    tableEntity.setTableName(table.get("tableName"));
    tableEntity.setComments(table.get("tableComment"));
    //????Java??
    String className = tableToJava(tableEntity.getTableName(), config.getString("tablePrefix"));
    tableEntity.setClassName(className);
    tableEntity.setClassname(StringUtils.uncapitalize(className));

    //?
    List<ColumnEntity> columsList = new ArrayList<>();
    for (Map<String, String> column : columns) {
        ColumnEntity columnEntity = new ColumnEntity();
        columnEntity.setColumnName(column.get("columnName"));
        columnEntity.setDataType(column.get("dataType"));
        columnEntity.setComments(column.get("columnComment"));
        columnEntity.setExtra(column.get("extra"));

        //????Java??
        String attrName = columnToJava(columnEntity.getColumnName());
        columnEntity.setAttrName(attrName);
        columnEntity.setAttrname(StringUtils.uncapitalize(attrName));

        //???Java
        String attrType = config.getString(columnEntity.getDataType(), "unknowType");
        columnEntity.setAttrType(attrType);

        //?
        if ("PRI".equalsIgnoreCase(column.get("columnKey")) && tableEntity.getPk() == null) {
            tableEntity.setPk(columnEntity);
        }

        columsList.add(columnEntity);
    }
    tableEntity.setColumns(columsList);

    //
    if (tableEntity.getPk() == null) {
        tableEntity.setPk(tableEntity.getColumns().get(0));
    }

    //velocity?
    Properties prop = new Properties();
    prop.put("file.resource.loader.class",
            "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    Velocity.init(prop);

    //???
    Map<String, Object> map = new HashMap<>();
    map.put("tableName", tableEntity.getTableName());
    map.put("comments", tableEntity.getComments());
    map.put("pk", tableEntity.getPk());
    map.put("className", tableEntity.getClassName());
    map.put("classname", tableEntity.getClassname());
    map.put("pathName", tableEntity.getClassname().toLowerCase());
    map.put("columns", tableEntity.getColumns());
    map.put("package", config.getString("package"));
    map.put("author", config.getString("author"));
    map.put("email", config.getString("email"));
    map.put("datetime", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));
    VelocityContext context = new VelocityContext(map);

    //??
    List<String> templates = getTemplates();
    for (String template : templates) {
        //?
        StringWriter sw = new StringWriter();
        Template tpl = Velocity.getTemplate(template, "UTF-8");
        tpl.merge(context, sw);

        try {
            //zip
            zip.putNextEntry(new ZipEntry(
                    getFileName(template, tableEntity.getClassName(), config.getString("package"))));
            IOUtils.write(sw.toString(), zip, "UTF-8");
            IOUtils.closeQuietly(sw);
            zip.closeEntry();
        } catch (IOException e) {
            throw new RRException("???" + tableEntity.getTableName(), e);
        }
    }
}