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:com.intuit.tank.tools.debugger.AgentDebuggerFrame.java

/**
 * @param args//w w  w.ja  v  a 2s. c om
 */
public static void main(String[] args) {
    try {
        java.security.Security.setProperty("networkaddress.cache.ttl", "0");
    } catch (Throwable e1) {
        LOG.warn(LogUtil.getLogMessage("Error setting dns timeout: " + e1.toString(), LogEventType.System));
    }
    try {
        System.setProperty("jsse.enableSNIExtension", "false");
    } catch (Throwable e1) {
        LOG.warn(LogUtil.getLogMessage("Error disabling SNI extension: " + e1.toString(), LogEventType.System));
    }
    try {
        System.setProperty("jdk.certpath.disabledAlgorithms", "");
    } catch (Throwable e1) {
        System.err.println("Error setting property jdk.certpath.disabledAlgorithms: " + e1.toString());
        e1.printStackTrace();
    }
    String url = "";
    if (args.length > 0) {
        url = args[0];
    }
    Properties props = new Properties();
    try {
        InputStream configStream = AgentDebuggerFrame.class.getResourceAsStream("/log4j.properties");
        props.load(configStream);
        configStream.close();
    } catch (IOException e) {
        System.out.println("Error: Cannot laod configuration file ");
    }
    props.setProperty("log4j.appender.agent.File", "debugger.log");
    LogManager.resetConfiguration();
    PropertyConfigurator.configure(props);

    new AgentDebuggerFrame(true, url).setVisible(true);
}

From source file:edu.usc.goffish.gopher.impl.Main.java

public static void main(String[] args) {

    Properties properties = new Properties();
    try {/*from  w ww  . j  av a 2s .  c om*/
        properties.load(new FileInputStream(CONFIG_FILE));
    } catch (IOException e) {
        String message = "Error while loading Container Configuration from " + CONFIG_FILE + " Cause -"
                + e.getCause();
        log.warning(message);
    }

    if (args.length == 4) {

        PropertiesConfiguration propertiesConfiguration;
        String url = null;

        URI uri = URI.create(args[3]);

        String dataDir = uri.getPath();

        String currentHost = uri.getHost();
        try {

            propertiesConfiguration = new PropertiesConfiguration(dataDir + "/gofs.config");
            propertiesConfiguration.load();
            url = (String) propertiesConfiguration.getString(DataNode.DATANODE_NAMENODE_LOCATION_KEY);

        } catch (ConfigurationException e) {

            String message = " Error while reading gofs-config cause -" + e.getCause();
            handleException(message);
        }

        URI nameNodeUri = URI.create(url);

        INameNode nameNode = new RemoteNameNode(nameNodeUri);
        int partition = -1;
        try {
            for (URI u : nameNode.getDataNodes()) {
                if (URIHelper.isLocalURI(u)) {
                    IDataNode dataNode = DataNode.create(u);
                    IntCollection partitions = dataNode.getLocalPartitions(args[2]);
                    partition = partitions.iterator().nextInt();
                    break;
                }
            }

            if (partition == -1) {
                String message = "Partition not loaded from uri : " + nameNodeUri;
                handleException(message);
            }

            properties.setProperty(GopherInfraHandler.PARTITION, String.valueOf(partition));

        } catch (Exception e) {
            String message = "Error while loading Partitions from " + nameNodeUri + " Cause -" + e.getMessage();
            e.printStackTrace();
            handleException(message);
        }

        properties.setProperty(Constants.STATIC_PELLET_COUNT, String.valueOf(1));
        FloeRuntimeEnvironment environment = FloeRuntimeEnvironment.getEnvironment();
        environment.setSystemConfig(properties);
        properties.setProperty(Constants.CURRET_HOST, currentHost);
        String managerHost = args[0];
        int managerPort = Integer.parseInt(args[1]);

        Container container = environment.getContainer();
        container.setManager(managerHost, managerPort);

        DefaultClientConfig config = new DefaultClientConfig();
        config.getProperties().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true);
        config.getFeatures().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true);

        Client c = Client.create(config);

        if (managerHost == null || managerPort == 0) {
            handleException("Manager Host / Port have to be configured in " + args[0]);
        }

        WebResource r = c.resource("http://" + managerHost + ":" + managerPort
                + "/Manager/addContainerInfo/Container=" + container.getContainerInfo().getContainerId()
                + "/Host=" + container.getContainerInfo().getContainerHost());
        c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
        r.post();
        log.log(Level.INFO, "Container started  ");

    } else {

        String message = "Invalid arguments , arg[0]=Manager host, "
                + "arg[1] = mamanger port,arg[2]=graph id,arg[3]=partition uri";

        message += "\n Current Arguments...." + args.length + "\n";
        for (int i = 0; i < args.length; i++) {
            message += "arg " + i + " : " + args[i] + "\n";
        }

        handleException(message);

    }

}

From source file:io.anserini.index.UserPostFrequencyDistribution.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(new Option(HELP_OPTION, "show help"));

    options.addOption(new Option(STORE_TERM_VECTORS_OPTION, "store term vectors"));

    options.addOption(OptionBuilder.withArgName("collection").hasArg()
            .withDescription("source collection directory").create(COLLECTION_OPTION));
    options.addOption(OptionBuilder.withArgName("property").hasArg()
            .withDescription("source collection directory").create("property"));
    options.addOption(OptionBuilder.withArgName("collection_pattern").hasArg()
            .withDescription("source collection directory").create("collection_pattern"));

    CommandLine cmdline = null;/*from w  w  w . j  av  a  2 s.  c o m*/
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (cmdline.hasOption(HELP_OPTION) || !cmdline.hasOption(COLLECTION_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(UserPostFrequencyDistribution.class.getName(), options);
        System.exit(-1);
    }

    String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION);

    final FieldType textOptions = new FieldType();
    textOptions.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
    textOptions.setStored(true);
    textOptions.setTokenized(true);
    textOptions.setStoreTermVectors(true);

    LOG.info("collection: " + collectionPath);
    LOG.info("collection_pattern " + cmdline.getOptionValue("collection_pattern"));
    LOG.info("property " + cmdline.getOptionValue("property"));
    LongOpenHashSet deletes = null;

    long startTime = System.currentTimeMillis();
    File file = new File(collectionPath);
    if (!file.exists()) {
        System.err.println("Error: " + file + " does not exist!");
        System.exit(-1);
    }

    final JsonStatusCorpusReader stream = new JsonStatusCorpusReader(file,
            cmdline.getOptionValue("collection_pattern"));

    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {

            try {

                stream.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            ;

            System.out.println("# of users indexed this round: " + userIndexedCount);

            System.out.println("Shutting down");

        }
    });
    Status status;
    boolean readerNotInitialized = true;

    try {
        Properties prop = new Properties();
        while ((status = stream.next()) != null) {

            // try{
            // status = DataObjectFactory.createStatus(s);
            // if (status==null||status.getText() == null) {
            // continue;
            // }}catch(Exception e){
            //
            // }
            //

            boolean pittsburghRelated = false;
            try {

                if (Math.abs(status.getLongitude() - pittsburghLongitude) < 0.05d
                        && Math.abs(status.getlatitude() - pittsburghLatitude) < 0.05d)
                    pittsburghRelated = true;
            } catch (Exception e) {

            }
            try {
                if (status.getPlace().contains("Pittsburgh, PA"))
                    pittsburghRelated = true;
            } catch (Exception e) {

            }
            try {
                if (status.getUserLocation().contains("Pittsburgh, PA"))
                    pittsburghRelated = true;
            } catch (Exception e) {

            }

            try {
                if (status.getText().contains("Pittsburgh"))
                    pittsburghRelated = true;
            } catch (Exception e) {

            }

            if (pittsburghRelated) {

                int previousPostCount = 0;

                if (prop.containsKey(String.valueOf(status.getUserid()))) {
                    previousPostCount = Integer
                            .valueOf(prop.getProperty(String.valueOf(status.getUserid())).split(" ")[1]);
                }

                prop.setProperty(String.valueOf(status.getUserid()),
                        String.valueOf(status.getStatusesCount()) + " " + (1 + previousPostCount));
                if (prop.size() > 0 && prop.size() % 1000 == 0) {
                    Runtime runtime = Runtime.getRuntime();
                    runtime.gc();
                    System.out.println("Property size " + prop.size() + "Memory used:  "
                            + ((runtime.totalMemory() - runtime.freeMemory()) / (1024L * 1024L)) + " MB\n");
                }
                OutputStream output = new FileOutputStream(cmdline.getOptionValue("property"), false);
                prop.store(output, null);
                output.close();

            }
        }
        //         prop.store(output, null);
        LOG.info(String.format("Total of %s statuses added", userIndexedCount));
        LOG.info("Total elapsed time: " + (System.currentTimeMillis() - startTime) + "ms");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {

        stream.close();
    }
}

From source file:me.mast3rplan.phantombot.PhantomBot.java

public static void main(String[] args) throws IOException {
    /* List of properties that must exist. */
    String requiredProperties[] = new String[] { "oauth", "channel", "owner", "user" };
    String requiredPropertiesErrorMessage = "";

    /* Properties configuration */
    Properties startProperties = new Properties();

    /* Indicates that the botlogin.txt file should be overwritten/created. */
    Boolean changed = false;//ww  w.ja va 2  s  . c  o m

    /* Print the user dir */
    com.gmt2001.Console.out.println("The working directory is: " + System.getProperty("user.dir"));

    /* Load up the bot info from the bot login file */
    try {
        if (new File("./botlogin.txt").exists()) {
            try {
                FileInputStream inputStream = new FileInputStream("botlogin.txt");
                startProperties.load(inputStream);
                inputStream.close();

                if (startProperties.getProperty("debugon", "false").equals("true")) {
                    com.gmt2001.Console.out.println("Debug Mode Enabled via botlogin.txt");
                    PhantomBot.enableDebugging = true;
                }

                if (startProperties.getProperty("debuglog", "false").equals("true")) {
                    com.gmt2001.Console.out.println("Debug Log Only Mode Enabled via botlogin.txt");
                    PhantomBot.enableDebugging = true;
                    PhantomBot.enableDebuggingLogOnly = true;
                }

                if (startProperties.getProperty("reloadscripts", "false").equals("true")) {
                    com.gmt2001.Console.out.println("Enabling Script Reloading");
                    PhantomBot.reloadScripts = true;
                }
                if (startProperties.getProperty("rhinodebugger", "false").equals("true")) {
                    com.gmt2001.Console.out.println("Rhino Debugger will be launched if system supports it.");
                    PhantomBot.enableRhinoDebugger = true;
                }
            } catch (IOException ex) {
                com.gmt2001.Console.err.printStackTrace(ex);
            }
        } else {

            /* Fill in the Properties object with some default values. Note that some values are left 
             * unset to be caught in the upcoming logic to enforce settings.
             */
            startProperties.setProperty("baseport", "25000");
            startProperties.setProperty("usehttps", "false");
            startProperties.setProperty("webenable", "true");
            startProperties.setProperty("msglimit30", "18.75");
            startProperties.setProperty("musicenable", "true");
            startProperties.setProperty("whisperlimit60", "60.0");
        }
    } catch (Exception ex) {
        com.gmt2001.Console.err.printStackTrace(ex);
    }

    /* Check to see if there's a webOauth set */
    if (startProperties.getProperty("webauth") == null) {
        startProperties.setProperty("webauth", generateWebAuth());
        com.gmt2001.Console.debug.println("New webauth key has been generated for botlogin.txt");
        changed = true;
    }
    /* Check to see if there's a webOAuthRO set */
    if (startProperties.getProperty("webauthro") == null) {
        startProperties.setProperty("webauthro", generateWebAuth());
        com.gmt2001.Console.debug.println("New webauth read-only key has been generated for botlogin.txt");
        changed = true;
    }
    /* Check to see if there's a panelUsername set */
    if (startProperties.getProperty("paneluser") == null) {
        com.gmt2001.Console.debug.println(
                "No Panel Username, using default value of 'panel' for Control Panel and YouTube Player");
        startProperties.setProperty("paneluser", "panel");
        changed = true;
    }
    /* Check to see if there's a panelPassword set */
    if (startProperties.getProperty("panelpassword") == null) {
        com.gmt2001.Console.debug.println(
                "No Panel Password, using default value of 'panel' for Control Panel and YouTube Player");
        startProperties.setProperty("panelpassword", "panel");
        changed = true;
    }
    /* Check to see if there's a youtubeOAuth set */
    if (startProperties.getProperty("ytauth") == null) {
        startProperties.setProperty("ytauth", generateWebAuth());
        com.gmt2001.Console.debug.println("New YouTube websocket key has been generated for botlogin.txt");
        changed = true;
    }
    /* Check to see if there's a youtubeOAuthThro set */
    if (startProperties.getProperty("ytauthro") == null) {
        startProperties.setProperty("ytauthro", generateWebAuth());
        com.gmt2001.Console.debug
                .println("New YouTube read-only websocket key has been generated for botlogin.txt");
        changed = true;
    }

    /* Make a new botlogin with the botName, oauth or channel is not found */
    if (startProperties.getProperty("user") == null || startProperties.getProperty("oauth") == null
            || startProperties.getProperty("channel") == null) {
        try {
            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out.print("Welcome to the PhantomBot setup process!\r\n");
            com.gmt2001.Console.out
                    .print("If you have any issues please report them on our forum or Tweet at us!\r\n");
            com.gmt2001.Console.out.print("Forum: https://community.phantombot.tv/\r\n");
            com.gmt2001.Console.out.print("Twitter: https://twitter.com/phantombotapp/\r\n");
            com.gmt2001.Console.out.print("PhantomBot Knowledgebase: https://docs.phantombot.tv/\r\n");
            com.gmt2001.Console.out.print("PhantomBot WebPanel: https://docs.phantombot.tv/kb/panel/\r\n");
            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out.print("\r\n");

            com.gmt2001.Console.out.print("1. Please enter the bot's Twitch username: ");
            startProperties.setProperty("user", System.console().readLine().trim());

            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out
                    .print("2. You will now need a OAuth token for the bot to be able to chat.\r\n");
            com.gmt2001.Console.out.print(
                    "Please note, this OAuth token needs to be generated while you're logged in into the bot's Twitch account.\r\n");
            com.gmt2001.Console.out.print(
                    "If you're not logged in as the bot, please go to https://twitch.tv/ and login as the bot.\r\n");
            com.gmt2001.Console.out.print("Get the bot's OAuth token here: https://twitchapps.com/tmi/\r\n");
            com.gmt2001.Console.out.print("Please enter the bot's OAuth token: ");
            startProperties.setProperty("oauth", System.console().readLine().trim());

            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out.print(
                    "3. You will now need your channel OAuth token for the bot to be able to change your title and game.\r\n");
            com.gmt2001.Console.out.print(
                    "Please note, this OAuth token needs to be generated while you're logged in into your caster account.\r\n");
            com.gmt2001.Console.out.print(
                    "If you're not logged in as the caster, please go to https://twitch.tv/ and login as the caster.\r\n");
            com.gmt2001.Console.out.print("Get the your OAuth token here: https://phantombot.tv/oauth/\r\n");
            com.gmt2001.Console.out.print("Please enter your OAuth token: ");
            startProperties.setProperty("apioauth", System.console().readLine().trim());

            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out
                    .print("4. Please enter the name of the Twitch channel the bot should join: ");
            startProperties.setProperty("channel", System.console().readLine().trim());

            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out.print("5. Please enter a custom username for the web panel: ");
            startProperties.setProperty("paneluser", System.console().readLine().trim());

            com.gmt2001.Console.out.print("\r\n");
            com.gmt2001.Console.out.print("6. Please enter a custom password for the web panel: ");
            startProperties.setProperty("panelpassword", System.console().readLine().trim());

            changed = true;
            newSetup = true;
        } catch (NullPointerException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
            com.gmt2001.Console.out.println("[ERROR] Failed to setup PhantomBot. Now exiting...");
            System.exit(0);
        }
    }

    /* Make sure the oauth has been set correctly */
    if (startProperties.getProperty("oauth") != null) {
        if (!startProperties.getProperty("oauth").startsWith("oauth")
                && !startProperties.getProperty("oauth").isEmpty()) {
            startProperties.setProperty("oauth", "oauth:" + startProperties.getProperty("oauth"));
            changed = true;
        }
    }

    /* Make sure the apiOAuth has been set correctly */
    if (startProperties.getProperty("apioauth") != null) {
        if (!startProperties.getProperty("apioauth").startsWith("oauth")
                && !startProperties.getProperty("apioauth").isEmpty()) {
            startProperties.setProperty("apioauth", "oauth:" + startProperties.getProperty("apioauth"));
            changed = true;
        }
    }

    /* Make sure the channelName does not have a # */
    if (startProperties.getProperty("channel").startsWith("#")) {
        startProperties.setProperty("channel", startProperties.getProperty("channel").substring(1));
        changed = true;
    } else if (startProperties.getProperty("channel").contains(".tv")) {
        startProperties.setProperty("channel", startProperties.getProperty("channel")
                .substring(startProperties.getProperty("channel").indexOf(".tv/") + 4).replaceAll("/", ""));
        changed = true;
    }

    /* Check for the owner after the channel check is done. */
    if (startProperties.getProperty("owner") == null) {
        if (startProperties.getProperty("channel") != null) {
            if (!startProperties.getProperty("channel").isEmpty()) {
                startProperties.setProperty("owner", startProperties.getProperty("channel"));
                changed = true;
            }
        }
    }

    /* Iterate the properties and delete entries for anything that does not have a 
     * value.
     */
    for (String propertyKey : startProperties.stringPropertyNames()) {
        if (startProperties.getProperty(propertyKey).isEmpty()) {
            changed = true;
            startProperties.remove(propertyKey);
        }
    }

    /* 
     * Check for required settings.
     */
    for (String requiredProperty : requiredProperties) {
        if (startProperties.getProperty(requiredProperty) == null) {
            requiredPropertiesErrorMessage += requiredProperty + " ";
        }
    }

    if (!requiredPropertiesErrorMessage.isEmpty()) {
        com.gmt2001.Console.err.println();
        com.gmt2001.Console.err.println("Missing Required Properties: " + requiredPropertiesErrorMessage);
        com.gmt2001.Console.err.println("Exiting PhantomBot");
        System.exit(0);
    }

    /* Check to see if anything changed */
    if (changed) {
        Properties outputProperties = new Properties() {
            @Override
            public synchronized Enumeration<Object> keys() {
                return Collections.enumeration(new TreeSet<>(super.keySet()));
            }
        };

        try {
            try (FileOutputStream outputStream = new FileOutputStream("botlogin.txt")) {
                outputProperties.putAll(startProperties);
                outputProperties.store(outputStream, "PhantomBot Configuration File");
            }
        } catch (IOException ex) {
            com.gmt2001.Console.err.printStackTrace(ex);
        }
    }

    /* Start PhantomBot */
    PhantomBot.instance = new PhantomBot(startProperties);
}

From source file:Main.java

/**
 * Set the culvert table to use as input.
 * //from w  w w . j av a2  s .c om
 * @param props The configuration to set the table name on.
 * @return The culvert table name.
 */
public static void setCulvertInputTable(Properties props, String table) {
    props.setProperty(CULVERT_HIVE_CTABLE_NAME_CONF_KEY, table);
}

From source file:test.gov.nih.nci.logging.api.persistence.TestSpringLocationSessionFactoryBean.java

private static Properties getJDBCProperties() {
    Properties props = new Properties();
    props.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
    props.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/clm");
    props.setProperty("hibernate.connection.username", "root");
    props.setProperty("hibernate.connection.password", "admin");
    props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
    props.setProperty("jdbc.batch_size", "30");
    return props;
}

From source file:Main.java

/**
 * Set weather or not this properties object can be translated into a culvert
 * configuration./*  ww  w .  jav  a  2s .com*/
 * 
 * @param props The properties to change.
 * @param embedded Weather or not the culvert configuration is embedded in
 *        these properties.
 */
public static void setCulvertConfigurationIsEmbedded(Properties props, boolean embedded) {
    props.setProperty(CULVERT_HIVE_CONF_IS_EMBEDDED_CONF_KEY, embedded ? "true" : "false");
}

From source file:gov.nih.nci.ncicb.cadsr.bulkloader.ui.CommandLineProcessor.java

private static void initializeSpringCtx(UserInput userInput) {
    Properties props = new Properties();
    props.setProperty("db.url", userInput.getDbURL());
    props.setProperty("db.username", userInput.getDbUser());
    props.setProperty("db.password", userInput.getDbPassword());

    SpringBeansUtil.getInstance().initialize(props);
}

From source file:com.github.ferstl.spring.jdbc.oracle.dsconfig.PoolProperties.java

public static Properties createFromEnvironment(Environment env) {
    Properties props = new Properties();
    props.setProperty("url", env.getProperty("db.url"));
    props.setProperty("username", env.getProperty("db.username"));
    props.setProperty("password", env.getProperty("db.password"));
    props.setProperty("defaultAutoCommit ", env.getProperty("db.defaultAutoCommit"));

    props.setProperty("driverClassName", env.getProperty("driverClassName"));
    props.setProperty("maxActive", env.getProperty("maxActive"));
    props.setProperty("maxIdle", env.getProperty("maxIdle"));
    props.setProperty("minIdle", env.getProperty("minIdle"));
    props.setProperty("initialSize", env.getProperty("initialSize"));

    return props;
}

From source file:com.qpark.eip.core.sftp.SftpSessionFactoryProvider.java

/**
 * Get the {@link DefaultSftpSessionFactory} according to the
 * {@link ConnectionDetails}./*  ww w . j  av  a 2s.  c o  m*/
 *
 * @param connectionDetails
 *            the {@link ConnectionDetails}.
 * @return the {@link DefaultSftpSessionFactory}.
 */
public static DefaultSftpSessionFactory getSessionFactory(final ConnectionDetails connectionDetails) {
    Properties sessionConfig = new Properties();
    sessionConfig.setProperty("compression.s2c", "zlib@openssh.com,none");
    sessionConfig.setProperty("compression.c2s", "zlib@openssh.com,none");
    sessionConfig.setProperty("compression_level", "9");
    DefaultSftpSessionFactory sessionFactory = new DefaultSftpSessionFactory();
    sessionFactory.setHost(connectionDetails.getHostName());
    sessionFactory.setPort(connectionDetails.getPort());
    sessionFactory.setUser(connectionDetails.getUserName());
    sessionFactory.setPassword(new String(connectionDetails.getPassword()));
    sessionFactory.setSessionConfig(sessionConfig);
    return sessionFactory;
}