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:Main.java

public static String getProperty(String key, Context context) throws IOException {
    Properties properties = new Properties();
    AssetManager assetManager = context.getAssets();
    InputStream inputStream = assetManager.open("marvel.properties");
    properties.load(inputStream);
    return properties.getProperty(key);
}

From source file:Main.java

public static String getProperty(Context context, String key) {
    try {/*  www .  java2  s. c  om*/
        Properties props = new Properties();
        InputStream input = context.getAssets().open("config.properties");
        if (input != null) {
            props.load(input);
            return props.getProperty(key);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:ar.com.zauber.garfio.config.impl.PropertiesConfiguration.java

/**
 * @param filename/*from   w w  w.  jav  a  2 s. c  o  m*/
 * @throws  IOException on error
 */
private static Properties getProperties(final String filename) throws IOException {
    Validate.notEmpty(filename);
    final Properties config = new Properties();
    config.load(new FileInputStream(filename));
    return config;
}

From source file:com.microsoft.windowsazure.Configuration.java

public static Configuration load() throws IOException {
    final Configuration config = new Configuration();

    final InputStream stream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("META-INF/com.microsoft.windowsazure.properties");
    if (stream != null) {
        final Properties properties = new Properties();
        properties.load(stream);
        for (Map.Entry<Object, Object> key : properties.entrySet()) {
            config.setProperty(key.getKey().toString(), key.getValue());
        }//from w  w  w .j a  v  a  2 s .co  m
    }

    return config;
}

From source file:eu.scidipes.toolkits.pawebapp.util.FrameworkUtils.java

/**
 * Returns a map that holds an inner map per FormType (e.g. Document, Software etc) of user friendly type-names
 * (e.g. 'PDF') to actual RILs//from   w  ww .j a  va 2  s .  c  o m
 * 
 * @return a map of type 'groups' to 'friendly' type names to RILs
 * @throws IOException
 */
public static Map<FormType, Map<String, CurationPersistentIdentifier>> getRILsByType() throws IOException {

    /* The return Map, e.g. "DOC" -> "PDF" - RIL1 */
    final Map<FormType, Map<String, CurationPersistentIdentifier>> rilMap = new HashMap<>();

    final Properties props = new Properties();
    props.load(FrameworkUtils.class.getResourceAsStream("/rin/doc_type_rilcpids.properties"));
    populateMapFromRILProps(props, rilMap, FormType.DOCUMENT);

    props.clear();
    props.load(FrameworkUtils.class.getResourceAsStream("/rin/software_langs_rilcpids.properties"));
    populateMapFromRILProps(props, rilMap, FormType.SOFTWARE);

    props.clear();
    props.load(FrameworkUtils.class.getResourceAsStream("/rin/data_type_rilcpids.properties"));
    populateMapFromRILProps(props, rilMap, FormType.DATA);

    if (LOG.isTraceEnabled()) {
        for (final Entry<FormType, Map<String, CurationPersistentIdentifier>> outerMap : rilMap.entrySet()) {
            for (final Entry<String, CurationPersistentIdentifier> innerMap : outerMap.getValue().entrySet()) {
                LOG.trace(innerMap.getKey() + ": " + innerMap.getValue());
            }
        }
    }
    return rilMap;
}

From source file:Main.java

public static String getBuildProp(String propertyName) {
    Properties buildProps = new Properties();
    try {/*  w  w w  .  j  a  v  a  2s . c om*/
        FileInputStream is = new FileInputStream(new File(BUILD_PROP));
        buildProps.load(is);
        is.close();
        return buildProps.getProperty(propertyName, "");
    } catch (IOException e) {
        logError(e);
    }
    return "";
}

From source file:edu.sampleu.common.FreemarkerUtil.java

protected static Properties loadProperties(InputStream inputStream) throws IOException {
    Properties props = new Properties();

    if (inputStream != null) {
        props.load(inputStream);
    }/*from w ww  .  j av  a2s. com*/

    return props;
}

From source file:edu.usc.polar.NLTKNERRecogniser.java

public static String readRestUrl() throws IOException {
    Properties nltkProperties = new Properties();
    nltkProperties.load(NLTKNERRecogniser.class.getResourceAsStream("NLTKServer.properties"));

    return nltkProperties.getProperty("nltk.server.url");
}

From source file:br.com.riselabs.cotonet.model.db.Database.java

public static Connection getConnection() {
    Thread currentThread = Thread.currentThread();
    ClassLoader classloader = currentThread.getContextClassLoader();
    InputStream input = classloader.getResourceAsStream("db.properties");
    Properties prop = new Properties();
    try {//w  ww  .ja  v a  2s. c  o m
        if (input != null) {
            prop.load(input);
            input.close();
        } else {
            Logger.logStackTrace(new FileNotFoundException("The file 'db.properties was not found."));
        }
    } catch (IOException e) {
        Logger.logStackTrace(e);
    }
    String db = prop.getProperty("database.name");
    String user = prop.getProperty("database.user");
    String pass = prop.getProperty("database.password");
    return getConnection(db, user, pass);
}

From source file:com.alibaba.rocketmq.storm.internal.tools.ConfigUtils.java

/**
 * Reads configuration from a classpath resource stream obtained from the
 * current thread's class loader through
 * {@link ClassLoader#getSystemResourceAsStream(String)}.
 *
 * @param resource The resource to be read.
 * @return A {@link java.util.Properties} object read from the specified
 * resource./*from  w  ww.j  a va  2  s.co m*/
 * @throws IllegalArgumentException When the configuration file could not be
 *                                  found or another I/O error occurs.
 */
public static Properties getResource(final String resource) {
    InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
    if (input == null) {
        throw new IllegalArgumentException("configuration file '" + resource + "' not found on classpath");
    }

    final Properties config = new Properties();
    try {
        config.load(input);
    } catch (final IOException e) {
        throw new IllegalArgumentException("reading configuration from '" + resource + "' failed", e);
    }
    return config;
}