Example usage for java.util Properties load

List of usage examples for java.util Properties load

Introduction

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

Prototype

public synchronized void load(InputStream inStream) throws IOException 

Source Link

Document

Reads a property list (key and element pairs) from the input byte stream.

Usage

From source file:com.magnet.mmx.server.plugin.mmxmgmt.wakeup.WakeupProcessorTest.java

@BeforeClass
public static void setup() throws Exception {
    InputStream inputStream = DeviceDAOImplTest.class.getResourceAsStream("/test.properties");

    Properties testProperties = new Properties();
    testProperties.load(inputStream);

    String host = testProperties.getProperty("db.host");
    String port = testProperties.getProperty("db.port");
    String user = testProperties.getProperty("db.user");
    String password = testProperties.getProperty("db.password");
    String driver = testProperties.getProperty("db.driver");
    String schema = testProperties.getProperty("db.schema");

    String url = "jdbc:mysql://" + host + ":" + port + "/" + schema;

    ds = new BasicDataSource();
    ds.setDriverClassName(driver);/*from w  ww.  java  2  s  .co  m*/
    ds.setUsername(user);
    ds.setPassword(password);
    ds.setUrl(url);
    //clean any existing records and load some records into the database.
    FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
    builder.setColumnSensing(true);
    Connection setup = ds.getConnection();
    IDatabaseConnection con = new DatabaseConnection(setup);
    {
        InputStream xmlInput = DeviceDAOImplTest.class.getResourceAsStream("/data/wakeup-queue-1.xml");
        IDataSet dataSet = builder.build(xmlInput);
        DatabaseOperation.CLEAN_INSERT.execute(con, dataSet);
    }
    {
        InputStream xmlInput = DeviceDAOImplTest.class.getResourceAsStream("/data/message-data-1.xml");
        IDataSet dataSet = builder.build(xmlInput);
        DatabaseOperation.CLEAN_INSERT.execute(con, dataSet);
    }
}

From source file:com.willwinder.universalgcodesender.utils.SettingsFactory.java

public static Settings loadSettings() {
    // the defaults are now in the settings bean
    Settings out = new Settings();

    File settingsFile = getSettingsFile();

    // Localized setting not available here.
    //logger.info(Localization.getString("settings.log.loading"));
    logger.info("Loading settings.");
    try {/*  w w  w.j a  v a 2s.  co m*/
        if (settingsFile.getName().endsWith("json") && settingsFile.exists()) {
            //logger.log(Level.INFO, "{0}: {1}", new Object[]{Localization.getString("settings.log.location"), settingsFile});
            logger.log(Level.INFO, "Log location: {0}", settingsFile.getAbsolutePath());
            out = new Gson().fromJson(new FileReader(settingsFile), Settings.class);
        } else if (settingsFile.getName().endsWith("properties")) {
            //logger.log(Level.INFO, "{0}: {1}", new Object[]{Localization.getString("settings.log.location"), settingsFile});
            logger.log(Level.INFO, "Log location: {0}", settingsFile.getAbsolutePath());
            Properties properties = new Properties();
            properties.load(new FileInputStream(settingsFile));
            out.setLastOpenedFilename(properties.getProperty("last.dir", System.getProperty(USER_HOME)));
            out.setPort(properties.getProperty("port", ""));
            out.setPortRate(properties.getProperty("port.rate", "9600"));
            out.setManualModeEnabled(Boolean.valueOf(properties.getProperty("manualMode.enabled", FALSE)));
            out.setManualModeStepSize(Double.valueOf(properties.getProperty("manualMode.stepsize", "1")));
            out.setScrollWindowEnabled(Boolean.valueOf(properties.getProperty("scrollWindow.enabled", "true")));
            out.setVerboseOutputEnabled(
                    Boolean.valueOf(properties.getProperty("verboseOutput.enabled", FALSE)));
            out.setOverrideSpeedSelected(
                    Boolean.valueOf(properties.getProperty("overrideSpeed.enabled", FALSE)));
            out.setOverrideSpeedValue(Double.valueOf(properties.getProperty("overrideSpeed.value", "60")));
            out.setFirmwareVersion(properties.getProperty("firmwareVersion", "GRBL"));
            out.setSingleStepMode(Boolean.valueOf(properties.getProperty("singleStepMode", FALSE)));
            out.setMaxCommandLength(Integer.valueOf(properties.getProperty("maxCommandLength", "50")));
            out.setTruncateDecimalLength(Integer.valueOf(properties.getProperty("truncateDecimalLength", "4")));
            out.setRemoveAllWhitespace(Boolean.valueOf(properties.getProperty("removeAllWhitespace", "true")));
            out.setStatusUpdatesEnabled(
                    Boolean.valueOf(properties.getProperty("statusUpdatesEnabled", "true")));
            out.setStatusUpdateRate(Integer.valueOf(properties.getProperty("statusUpdateRate", "200")));
            out.setDisplayStateColor(Boolean.valueOf(properties.getProperty("displayStateColor", "true")));
            out.setConvertArcsToLines(Boolean.valueOf(properties.getProperty("convertArcsToLines", FALSE)));
            out.setSmallArcThreshold(Double.valueOf(properties.getProperty("smallArcThreshold", "2.0")));
            out.setSmallArcSegmentLength(
                    Double.valueOf(properties.getProperty("smallArcSegmentLength", "1.3")));
            out.updateMacro(1, null, null, properties.getProperty("customGcode1", "G0 X0 Y0;"));
            out.updateMacro(2, null, null, properties.getProperty("customGcode2", "G0 G91 X10;G0 G91 Y10;"));
            out.updateMacro(3, null, null, properties.getProperty("customGcode3", ""));
            out.updateMacro(4, null, null, properties.getProperty("customGcode4", ""));
            out.updateMacro(5, null, null, properties.getProperty("customGcode5", ""));
            out.setLanguage(properties.getProperty("language", "en_US"));
        }
        out.finalizeInitialization();
    } catch (Exception e) {
        //logger.warning(Localization.getString("settings.log.error"));
        logger.warning("Can't load settings, using defaults.");
    }

    if (out == null)
        return new Settings();
    return out;
}

From source file:jamm.tools.JammCleaner.java

/**
 * Load properties from jammCleaner.properties in the classpath.
 * Command line options override this./* w  w  w. j  ava  2 s  .  c  om*/
 */
private static void loadProperties() {
    ClassLoader classLoader = JammCleaner.class.getClassLoader();
    InputStream is = classLoader.getResourceAsStream("jammCleaner.properties");
    if (is == null) {
        return;
    }

    Properties prop = new Properties();
    try {
        prop.load(is);
    } catch (IOException e) {
        LOG.error("Error reading properties file", e);
    }

    String tmp = prop.getProperty("jammCleaner.ldap.search_base");
    if (tmp != null) {
        JammCleanerOptions.setBaseDn(tmp);
    }

    tmp = prop.getProperty("jammCleaner.ldap.bind_dn");
    if (tmp != null) {
        JammCleanerOptions.setBindDn(tmp);
    }

    tmp = prop.getProperty("jammCleaner.ldap.password");
    if (tmp != null) {
        JammCleanerOptions.setPassword(tmp);
    }

    tmp = prop.getProperty("jammCleaner.ldap.host");
    if (tmp != null) {
        JammCleanerOptions.setHost(tmp);
    }

    tmp = prop.getProperty("jammCleaner.ldap.port");
    if (tmp != null) {
        JammCleanerOptions.setPort(Integer.parseInt(tmp));
    }

    tmp = prop.getProperty("jammCleaner.backup_dir");
    if (tmp != null) {
        JammCleanerOptions.setBackupDirectory(tmp);
    }

}

From source file:controllers.ConfigurationController.java

public static DBConfig getConfig(HttpServletRequest request) {
    try {/* w w w.j  a  va  2s.  c o  m*/
        String path = Utility.getPath("dbconfig", request);
        path += "config.properties";

        Properties p = new Properties();
        FileInputStream file = new FileInputStream(path);
        p.load(file);
        file.close();

        DBConfig config = new DBConfig();
        String db = p.getProperty("prop.db");

        if (db.equals("SQLServer"))
            config.setDb_type(DB_TYPE.SQLServer);
        if (db.equals("MySQL"))
            config.setDb_type(DB_TYPE.MySQL);
        if (db.equals("FirebirdSQL"))
            config.setDb_type(DB_TYPE.FirebirdSQL);
        if (db.equals("PostgreSQL"))
            config.setDb_type(DB_TYPE.PostgreSQL);
        if (db.equals("ORACLE"))
            config.setDb_type(DB_TYPE.ORACLE);

        config.setHost(p.getProperty("prop.server"));
        config.setPort(Integer.parseInt(p.getProperty("prop.port")));
        config.setUser(p.getProperty("prop.user"));
        config.setPassword(p.getProperty("prop.passwd"));
        config.setDatabase(p.getProperty("prop.database"));

        return config;
    } catch (Exception ex) {
        System.err.println(ex.getMessage());
    }
    return new DBConfig();
}

From source file:io.cloudslang.lang.tools.build.ArgumentProcessorUtils.java

/**
 * Returns the properties entries inside that file as a java.util.Properties object.
 *
 * @param propertiesAbsolutePath the absolute path to the run configuration properties file
 * @return get the property from file/*from   w  w  w.java 2  s. c om*/
 */
public static Properties getPropertiesFromFile(String propertiesAbsolutePath) {
    try (FileInputStream fileInputStream = new FileInputStream(new File(propertiesAbsolutePath))) {
        Properties properties = new Properties();
        properties.load(fileInputStream);
        return properties;
    } catch (IOException ioEx) {
        throw new RuntimeException("Failed to read from properties file '" + propertiesAbsolutePath + "': ",
                ioEx);
    }
}

From source file:de.fiz.ddb.aas.util.AasConfiguration.java

/**
 * Get the properties from a file./*from  w  ww.  j  a  va  2  s  . c om*/
 *
 * @param filename The name of the properties file.
 * @return The properties.
 * @throws IOException If access to the specified file fails.
 * @throws java.io.FileNotFoundException
 */
private static Properties getProperties(final String filename) throws IOException, FileNotFoundException {

    final Properties result = new Properties();
    final InputStream propertiesStream = getInputStream(filename);
    result.load(propertiesStream);
    return result;
}

From source file:com.netflix.config.ClasspathPropertiesConfiguration.java

private static Properties loadProperties(URL from) throws IOException {
    Properties into = new Properties();
    InputStream in = from.openStream();
    try {//  ww w . j a v a 2 s .  com
        into.load(in);
    } catch (Exception e) {
        log.error("Exception while loading properties from URL:" + from);
    } finally {
        in.close();
    }
    return into;
}

From source file:de.hypoport.ep2.support.configuration.properties.PropertiesLoader.java

private static Properties loadPropertiesFromInputStream(InputStream inputStream) throws IOException {
    Properties properties = new Properties();

    if (inputStream != null) {
        properties.load(inputStream);
    }/*from   ww  w  .  j a  v a  2  s.c o  m*/

    return properties;
}

From source file:io.apicurio.hub.api.bitbucket.BitbucketSourceConnectorTest.java

@BeforeClass
public static void globalSetUp() {
    File credsFile = new File(".bitbucket");
    if (!credsFile.isFile()) {
        return;// w  ww  .ja  v a 2  s.  c o m
    }
    System.out.println("Loading Bitbucket credentials from: " + credsFile.getAbsolutePath());
    try (Reader reader = new FileReader(credsFile)) {
        Properties props = new Properties();
        props.load(reader);
        String userPass = props.getProperty("username") + ":" + props.getProperty("password");
        basicAuth = Base64.encodeBase64String(userPass.getBytes(StandardCharsets.UTF_8));
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}

From source file:com.haulmont.cuba.core.entity.LocaleHelper.java

protected static Properties loadProperties(String localeBundle) {
    StringReader reader = new StringReader(localeBundle);
    Properties localeProperties = null;
    try {//from  ww w  .ja  v  a2s . co m
        localeProperties = new Properties();
        localeProperties.load(reader);
    } catch (IOException e) {
        log.debug("Unable to load properties: {}", localeBundle, e);
    }
    return localeProperties;
}