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 Properties getConfigProperties(Context context) {
    Properties properties = new Properties();
    try {//from   w  w w . j  a va  2  s  .  co m
        properties.load(context.getAssets().open("config.properties"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return properties;
}

From source file:Main.java

/** Read a properties file from /assets.  Returns null if it does not exist. */
public static Properties getProperties(String name, Context context) {
    Resources resources = context.getResources();
    AssetManager assetManager = resources.getAssets();

    // Read from the /assets directory
    try {/*  w  ww  .  ja v  a  2  s .c o  m*/
        InputStream inputStream = assetManager.open(name);
        Properties properties = new Properties();
        properties.load(inputStream);
        return properties;
    } catch (IOException e) {
        Log.i("ChatSecure", "no chatsecure.properties available");
        return null;
    }
}

From source file:Main.java

static String getDataDir(final Context c) {
    final String defaultDataDir = String.format("%s/.bitcoin", getDir(c).getAbsolutePath());
    try {// w  w  w  . j  a  va  2 s  . com
        final Properties p = new Properties();
        p.load(new BufferedInputStream(new FileInputStream(getBitcoinConf(c))));
        return p.getProperty("datadir", defaultDataDir);
    } catch (final IOException e) {
        return defaultDataDir;
    }
}

From source file:io.apiman.servers.gateway_es.Starter.java

/**
 * Loads properties from a file and puts them into system properties.
 *//*from  ww w.  ja va 2s.  c  om*/
@SuppressWarnings({ "nls", "unchecked" })
protected static void loadProperties() {
    URL configUrl = Starter.class.getClassLoader().getResource("gateway_es-apiman.properties");
    if (configUrl == null) {
        throw new RuntimeException(
                "Failed to find properties file (see README.md): gateway_es-apiman.properties");
    }
    InputStream is = null;
    try {
        is = configUrl.openStream();
        Properties props = new Properties();
        props.load(is);
        Enumeration<String> names = (Enumeration<String>) props.propertyNames();
        while (names.hasMoreElements()) {
            String name = names.nextElement();
            String value = props.getProperty(name);
            System.setProperty(name, value);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:Main.java

public static String findBuildPropValueOf(String prop) {
    String mBuildPath = "/system/build.prop";
    String DISABLE = "disable";
    String value = null;/*from  ww w  . j a va2  s  .  c om*/
    try {
        //create properties construct and load build.prop
        Properties mProps = new Properties();
        mProps.load(new FileInputStream(mBuildPath));
        //get the property
        value = mProps.getProperty(prop, DISABLE);
        Log.d("TAG", String.format("Helpers:findBuildPropValueOf found {%s} with the value (%s)", prop, value));
    } catch (IOException ioe) {
        Log.d("TAG", "failed to load input stream");
    } catch (NullPointerException npe) {
        //swallowed thrown by ill formatted requests
    }

    if (value != null) {
        return value;
    } else {
        return DISABLE;
    }
}

From source file:org.psidnell.omnifocus.ApplicationContextFactory.java

public static Properties getConfigProperties() throws IOException {
    try (InputStream in = ApplicationContextFactory.class.getResourceAsStream(CONFIG_PROPERTIES)) {
        if (in == null) {
            throw new IOException("config not found");
        }//w ww  .  j  a v  a  2  s  .  c o m
        Properties config = new Properties();
        config.load(in);
        return config;
    }
}

From source file:Main.java

public static String findBuildPropValueOf(String prop) {
    String mBuildPath = "/system/build.prop";
    String DISABLE = "disable";
    String value = null;//  w  ww.jav a2s  . c o  m
    try {
        //create properties construct and load build.prop
        Properties mProps = new Properties();
        mProps.load(new FileInputStream(mBuildPath));
        //get the property
        value = mProps.getProperty(prop, DISABLE);
        Log.d(TAG, String.format("Helpers:findBuildPropValueOf found {%s} with the value (%s)", prop, value));
    } catch (IOException ioe) {
        Log.d(TAG, "failed to load input stream");
    } catch (NullPointerException npe) {
        //swallowed thrown by ill formatted requests
    }

    if (value != null) {
        return value;
    } else {
        return DISABLE;
    }
}

From source file:Main.java

/**
 * Convenient call to load a properties file from the provided reader
 *//* w w w .  j a va  2s  .com*/
public static Properties loadProperties(Reader reader) throws IOException {
    if (reader == null)
        return null;

    Properties properties = new Properties();
    properties.load(reader);
    return properties;
}

From source file:Main.java

/**
 * Reads a property list using the {@link Properties#load(InputStream)} method. The
 * properties are stored in a map./*w  ww  . j  a  v a2 s  .  com*/
 * @param stream The stream to read from
 * @return The resulting map
 * @throws IOException propagated from the load method.
 */
public static Map<String, String> loadProperties(InputStream stream) throws IOException {
    Properties properties = new Properties();
    properties.load(stream);
    return toMap(properties);
}

From source file:com.googlecode.fascinator.DBIntegrationTestSuite.java

@AfterClass
public static void tearDown() throws IOException, BeansException, SQLException {
    Properties prop = new Properties();
    prop.load(new FileInputStream("src/test/resources/database.properties"));
    String dbString = prop.getProperty("jdbc.databaseurl");
    try {/*w  w  w  .j  a v  a2  s.  c o m*/
        DriverManager.getConnection(dbString + ";shutdown=true");
    } catch (SQLNonTransientConnectionException exception) {
    } catch (SQLException e) {
    }

    FileUtils.deleteDirectory(new File("target/database"));
}