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:de.mfo.jsurf.grid.RotationGrid.java

public static void loadFromFile(URL url) throws IOException, Exception {
    Properties props = new Properties();
    props.load(url.openStream());
    loadFromProperties(props);/*from  w  w  w. ja  va 2s  .  c om*/
}

From source file:com.xwiki.authentication.guanxi.GuanxiShibConfigurator.java

/**
 *   /*w w  w.j a  va2 s. c  om*/
 *   Load the config from file 
 */
public static GuanxiShibConfig getGuanxiShibConfig() {

    if (log.isDebugEnabled()) {
        log.debug("Loading GuanxiShibConfig using " + GuanxiShibConstants.PROPERTIES_FILE
                + " for GX-Auth values");
    }

    GuanxiShibConfig config = new GuanxiShibConfig();

    try {
        // load the config from file
        InputStream propertiesIn = null;
        propertiesIn = GuanxiShibAuthenticator.class.getResourceAsStream(GuanxiShibConstants.PROPERTIES_FILE);

        Properties configProperties = new Properties();
        configProperties.load(propertiesIn);

        // set properties file
        config.setPropertiesFile(configProperties.getProperty(GuanxiShibConstants.PROPERTIES_FILE));

        if (log.isDebugEnabled()) {
            log.debug("GuanxiAuthenticator Properties file set to: " + config.getPropertiesFile());
        }

        // set create users
        config.setCreateUsers(
                Boolean.valueOf(configProperties.getProperty(GuanxiShibConstants.CREATE_USERS)).booleanValue());

        if (log.isDebugEnabled()) {
            log.debug("GuanxiAuthenticator set to create users: " + config.isCreateUsers());
        }

        // set update info 
        config.setUpdateInfo(
                Boolean.valueOf(configProperties.getProperty(GuanxiShibConstants.UPDATE_INFO)).booleanValue());

        if (log.isDebugEnabled()) {
            log.debug("GuanxiAuthenticator set to update info: " + config.isUpdateInfo());
        }

        // set default groups 
        List defaultGroups = new ArrayList();

        String groups = configProperties.getProperty(GuanxiShibConstants.DEFAULT_XWIKI_GROUPS);

        if (groups != null) {
            defaultGroups.addAll(StringUtils.toListDelimitedByComma(groups));

            if (log.isDebugEnabled()) {
                for (Iterator i = defaultGroups.iterator(); i.hasNext();) {
                    log.debug("Adding group " + i.next().toString() + " to list of groups");
                }
            }
        }

        config.setDefaultGroups(defaultGroups);

        // set default user space 
        config.setDefaultUserSpace(configProperties.getProperty(GuanxiShibConstants.DEFAULT_XWIKI_USER_SPACE));

        if (log.isDebugEnabled()) {
            log.debug("GuanxiAuthenticator using " + config.getDefaultUserSpace() + " as user space");
        }

        // set userid header 
        config.setHeaderUserid(configProperties.getProperty(GuanxiShibConstants.HEADER_USERID));

        if (log.isDebugEnabled()) {
            log.debug("GuanxiAuthenticator userid header set to " + config.getHeaderUserid());
        }

        // set header mail
        config.setHeaderMail(configProperties.getProperty(GuanxiShibConstants.HEADER_MAIL));

        if (log.isDebugEnabled()) {
            log.debug("GuanxiAuthenticator mail header set to " + config.getHeaderMail());
        }

        // set header fullname
        config.setHeaderFullname(configProperties.getProperty(GuanxiShibConstants.HEADER_FULLNAME));

        if (log.isDebugEnabled()) {
            log.debug("GuanxiAuthenticator fullname header set to " + config.getHeaderFullname());
        }

        // set 
        config.setReplacementChar(configProperties.getProperty(GuanxiShibConstants.REPLACEMENT_CHAR));

        if (log.isDebugEnabled()) {
            log.debug("GuanxiAuthenticator replacement character set to " + config.getReplacementChar());
        }

    } catch (IOException e) {
        log.warn("Unable to read properties from file, defaulting", e);
    }

    return config;

}

From source file:net.ontopia.utils.PropertyUtils.java

public static Properties loadPropertiesFromClassPath(String resource) throws IOException {
    // Load properties from classpath
    ClassLoader cloader = PropertyUtils.class.getClassLoader();
    Properties properties = new Properties();
    InputStream istream = cloader.getResourceAsStream(resource);
    if (istream == null)
        return null;
    properties.load(istream);
    return properties;
}

From source file:com.hadoop.compression.lzo.LzoCodec.java

public static String getRevisionHash() {
    try {/*  w  w  w  .j  a  v a 2 s  .  c om*/
        Properties p = new Properties();
        p.load(LzoCodec.class.getResourceAsStream("/build.properties"));
        return p.getProperty("build_revision");
    } catch (IOException e) {
        LOG.error("Could not find build properties file with revision hash");
        return "UNKNOWN";
    }
}

From source file:org.apache.jmeter.protocol.http.sampler.HttpClientDefaultParameters.java

private static void load(String file, GenericHttpParams params) {
    log.info("Trying httpclient parameters from " + file);
    File f = new File(file);
    if (!(f.exists() && f.canRead())) {
        f = new File(NewDriver.getJMeterDir() + File.separator + "bin" + File.separator + file); // $NON-NLS-1$
        log.info(file + " httpclient parameters does not exist, trying " + f.getAbsolutePath());
        if (!(f.exists() && f.canRead())) {
            log.error("Cannot read parameters file for HttpClient: " + file);
            return;
        }//from   w ww.ja v a2 s.  co m
    }
    log.info("Reading httpclient parameters from " + f.getAbsolutePath());
    InputStream is = null;
    Properties props = new Properties();
    try {
        is = new FileInputStream(f);
        props.load(is);
        for (Map.Entry<Object, Object> me : props.entrySet()) {
            String key = (String) me.getKey();
            String value = (String) me.getValue();
            int typeSep = key.indexOf('$'); // $NON-NLS-1$
            try {
                if (typeSep > 0) {
                    String type = key.substring(typeSep + 1);// get past separator
                    String name = key.substring(0, typeSep);
                    log.info("Defining " + name + " as " + value + " (" + type + ")");
                    if (type.equals("Integer")) {
                        params.setParameter(name, Integer.valueOf(value));
                    } else if (type.equals("Long")) {
                        params.setParameter(name, Long.valueOf(value));
                    } else if (type.equals("Boolean")) {
                        params.setParameter(name, Boolean.valueOf(value));
                    } else if (type.equals("HttpVersion")) { // Commons HttpClient only
                        params.setVersion(name, value);
                    } else {
                        log.warn("Unexpected type: " + type + " for name " + name);
                    }
                } else {
                    log.info("Defining " + key + " as " + value);
                    params.setParameter(key, value);
                }
            } catch (Exception e) {
                log.error("Error in property: " + key + "=" + value + " " + e.toString());
            }
        }
    } catch (IOException e) {
        log.error("Problem loading properties " + e.toString());
    } finally {
        JOrphanUtils.closeQuietly(is);
    }
}

From source file:com.github.tddts.jet.util.Util.java

/**
 * Load property with given key from given property file.
 *
 * @param fileName property file path/*from   w ww  .  ja  va2s.  c o m*/
 * @param key      property key
 * @return property value
 */
public static String loadProperty(String fileName, String key) {
    try {
        File file = new File(fileName);

        if (!file.exists())
            return null;

        Properties properties = new Properties();

        try (InputStream in = FileUtils.openInputStream(file)) {
            properties.load(in);
        }

        return properties.getProperty(key);

    } catch (IOException e) {
        throw new ApplicationException(e);
    }
}

From source file:com.groupdocs.ui.ViewerUtils.java

public static Path getProjectBaseDir() {
    Properties props = new Properties();
    try {//  ww  w. ja  va2 s . c  o m
        InputStream i = ViewerUtils.class.getResourceAsStream("/project.properties");
        props.load(i);
    } catch (IOException x) {
        throw new RuntimeException(x);
    }
    return FileSystems.getDefault().getPath(props.getProperty("project.basedir"));
}

From source file:io.fabric8.vertx.maven.plugin.components.impl.GroovyExtensionCombiner.java

private static Properties asProperties(List<String> lines) {
    byte[] content = read(lines);
    Properties properties = new Properties();

    if (content.length != 0) {
        ByteArrayInputStream stream = new ByteArrayInputStream(content);
        try {// w  w w  .  j a v a 2s  . c  om
            properties.load(stream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(stream);
        }
    }
    return properties;
}

From source file:io.fabric8.vertx.maven.plugin.utils.GroovyExtensionCombiner.java

private static Properties asProperties(Set<String> lines) {
    byte[] content = read(lines);
    Properties properties = new Properties();

    if (content.length != 0) {
        ByteArrayInputStream stream = new ByteArrayInputStream(content);
        try {/*from   ww  w .ja v a  2 s  .  c  o m*/
            properties.load(stream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(stream);
        }
    }
    return properties;
}

From source file:com.dicksoft.ocr.Temp.java

private static void setupLog() {
    System.getProperties().setProperty("org.apache.commons.logging.Log",
            "org.apache.commons.logging.impl.Log4JLogger");
    Properties properties = new Properties();
    InputStream input;//from  w  ww . jav  a  2s . c om
    try {
        input = new FileInputStream(LOG4JPROPERTIES);
        properties.load(input);
    } catch (FileNotFoundException e) {
        System.err.println("Log4J properties file not found at " + LOG4JPROPERTIES);
    } catch (Exception e) {
        System.err.println("Log4J properties file read error.");
    }
    File logDir = new File(LOG4JLOCATION + StringUtil.FS);
    if (!logDir.exists()) {
        logDir.mkdirs();
    }
    properties.setProperty("log4j.appender.FILE.File", logDir.getAbsolutePath() + StringUtil.FS + "main.log");
    PropertyConfigurator.configure(properties);
    LOG = LogFactory.getLog(Temp.class);
}