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:cd.go.authentication.ldap.utils.Util.java

public static String pluginId() {
    String s = readResource("/plugin.properties");
    try {/* w  w  w  .  j a va2 s.  c  o  m*/
        Properties properties = new Properties();
        properties.load(new StringReader(s));
        return (String) properties.get("pluginId");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.netpet.spools.spring.springcase.ActionFactory.java

public static Action getAction(String actionName) {
    Properties pro = new Properties();

    try {//from  ww w. j av a  2  s . c o m
        pro.load(new FileInputStream(System.getProperty("user.dir") + "/springTest/" + "config.properties"));
        String actionImplName = (String) pro.get(actionName);
        String actionMessage = (String) pro.get(actionName + "_msg");
        Object obj = Class.forName(actionImplName).newInstance();
        BeanUtils.setProperty(obj, "message", actionMessage);

        return (Action) obj;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.fingerprintsoft.vitunit.test.VitUnitTestCase.java

protected static DataSource loadDatasource(final Class<? extends VitUnitTestCase> clazz) {

    DataSourceConfiguration annotation = clazz.getAnnotation(DataSourceConfiguration.class);

    String jdbcPropertiesFile = annotation.jdbcPropertiesFile();
    InputStream resourceAsStream = clazz.getClassLoader().getResourceAsStream(jdbcPropertiesFile);
    Properties properties = new Properties();
    try {/*from   w w w .  j  av  a2 s .  c  o m*/
        properties.load(resourceAsStream);
    } catch (IOException e) {
        throw new SetupException("Could not load properties.", e);
    }

    try {
        return BasicDataSourceFactory.createDataSource(properties);
    } catch (Exception e) {
        throw new SetupException("Could not create datasource.", e);
    }
}

From source file:br.com.ingenieux.jenkins.plugins.awsebdeployment.Utils.java

public static String getVersion() {
    if (DEFAULT_VERSION.equals(VERSION)) {
        try (InputStream is = Utils.class.getResourceAsStream("version.properties")) {
            Properties p = new Properties();

            p.load(is);

            VERSION = p.getProperty("awseb-deployer-plugin.version");

        } catch (Exception exc) {
            throw new RuntimeException(exc);
        }/*  w ww . j  a v  a2 s.  co m*/
    }

    return VERSION;
}

From source file:com.amazonaws.devicefarm.DeviceFarmClientFactory.java

private static String readPluginVersion() {
    try {/*  w  ww  .j av  a2 s.  c  o  m*/

        final Properties props = new Properties();
        props.load(DeviceFarmServer.class.getResourceAsStream("/META-INF/gradle-plugins/version.properties"));
        return props.getProperty("version");

    } catch (IOException e) {
        throw new DeviceFarmException("Unable to read version", e);
    }
}

From source file:com.siemens.scr.avt.ad.io.BatchLoader.java

protected static void initLogging() {
    try {/*from www. j  a  v  a 2 s  .c  om*/
        Properties props = new Properties();
        props.load(ClassLoader.getSystemResource("log4j.properties").openStream());
        PropertyConfigurator.configure(props);
    } catch (Exception e) {
        System.err.println("unable to load log4j.properties");
    }
}

From source file:PropertiesUtils.java

/**
 * Loads properties by given file/*from www.ja  v a  2  s.  c  om*/
 * 
 * @param file
 *            filename
 * @return loaded properties
 * @throws java.io.IOException
 *             if can't load file
 */
public static Properties load(File file) throws IOException {

    FileInputStream fis = new FileInputStream(file);
    Properties p = new Properties();
    p.load(fis);
    fis.close();
    return p;
}

From source file:com.sap.prd.mobile.ios.mios.XCodeTest.java

private static String getMavenXcodePluginVersion() throws IOException {
    Properties properties = new Properties();
    properties.load(XCodeManagerTest.class.getResourceAsStream("/misc/project.properties"));
    final String xcodePluginVersion = properties.getProperty("xcode-plugin-version");

    if (xcodePluginVersion.equals("${project.version}"))
        throw new IllegalStateException(
                "Variable ${project.version} was not replaced. May be running \"mvn clean install\" beforehand might solve this issue.");
    return xcodePluginVersion;
}

From source file:Main.java

/** 
 * Read a set of properties from the received input stream, strip
 * off any excess white space that exists in those property values,
 * and then add those newly-read properties to the received
 * Properties object; not explicitly removing the whitespace here can
 * lead to problems./* ww  w . j  a v  a2 s  .  c om*/
 *
 * This method exists because of the manner in which the jvm reads
 * properties from file--extra spaces are ignored after a _key_, but
 * if they exist at the _end_ of a property decl line (i.e. as part
 * of a _value_), they are preserved, as outlined in the Java API:
 *
 * "Any whitespace after the key is skipped; if the first non-
 * whitespace character after the key is = or :, then it is ignored
 * and any whitespace characters after it are also skipped. All
 * remaining characters on the line become part of the associated
 * element string."
 *
 * @param iStr An input stream from which the new properties are to be
 *  loaded (should already be initialized).
 * @param prop A set of properties to which the properties from
 *  iStr will be added (should already be initialized).
 * properties loaded from 'iStr' (with the extra whitespace (if any)
 *  removed from all values), will be returned via the parameter.
 *
 **/
public static void loadWithTrimmedValues(InputStream iStr, Properties prop) throws IOException {

    if ((iStr == null) || (prop == null)) {
        // shouldn't happen; just ignore this call and return.
        return;
    }

    // Else, load the properties from the received input stream.
    Properties p = new Properties();
    p.load(iStr);

    // Now, trim off any excess whitespace, if any, and then
    // add the properties from file to the received Properties
    // set.
    for (Enumeration propKeys = p.propertyNames(); propKeys.hasMoreElements();) {
        // get the value, trim off the whitespace, then store it
        // in the received properties object.
        String tmpKey = (String) propKeys.nextElement();
        String tmpValue = p.getProperty(tmpKey);
        tmpValue = tmpValue.trim();
        prop.put(tmpKey, tmpValue);
    }

    return;

}

From source file:com.github.dbourdette.glass.job.util.JobDataMapUtils.java

public static JobDataMap fromProperties(String dataMap) {
    if (StringUtils.isEmpty(dataMap)) {
        return new JobDataMap();
    }/*from  w  ww .  ja v  a2  s .  c  o m*/

    Properties props = new Properties();

    try {
        props.load(new StringReader(dataMap));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    JobDataMap map = new JobDataMap();

    for (Object key : props.keySet()) {
        map.put(key, props.getProperty((String) key));
    }

    return map;
}