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:cu.uci.uengine.utils.FileUtils.java

public static boolean dos2unixFileFixer(String filePath) throws IOException, InterruptedException {
    // bash es muy sensible a los cambios de linea \r\n de Windows. Para
    // prevenir que esto cause Runtime Errors, es necesario convertirlos a
    // un sistema comprensible por ubuntu: \n normal en linux. El comando
    // dos2unix hace esto.
    // se lo dejamos a todos los codigos para evitar que algun otro lenguaje
    // tambien padezca de esto

    Properties langProps = new Properties();
    langProps.load(ClassLoader.getSystemResourceAsStream("uengine.properties"));

    String dos2unixPath = langProps.getProperty("dos2unix.path");

    ProcessBuilder pb = new ProcessBuilder(dos2unixPath, filePath);
    Process process = pb.start();
    process.waitFor();/*from ww  w .j av  a2s.c om*/

    return process.exitValue() == 0;
}

From source file:com.splunk.shuttl.archiver.filesystem.hadoop.HdfsProperties.java

private static Properties loadProperties(File hdfsProperties) {
    try {//from w ww.  j  a va  2 s. c om
        Properties properties = new Properties();
        properties.load(FileUtils.openInputStream(hdfsProperties));
        return properties;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:fedora.utilities.Log4J.java

/**
 * Initializes Log4J from a properties file.
 * /* w w  w  . j  a v a  2s.  c o  m*/
 * @param propFile the Log4J properties file.
 * @param options a set of name-value pairs to use while expanding any
 *                replacement variables (e.g. ${some.name}) in the 
 *                properties file.  These may also be specified in
 *                the properties file itself.  If found, the value
 *                in the properties file will take precendence.
 * @throws IOException if configuration fails due to problems with the file.
 */
public static void initFromPropFile(File propFile, Map<String, String> options) throws IOException {
    Properties props = new Properties();
    props.load(new FileInputStream(propFile));
    if (options != null) {
        for (String name : options.keySet()) {
            String value = options.get(name);
            if (!props.containsKey(name)) {
                props.setProperty(name, value);
            }
        }
    }
    PropertyConfigurator.configure(props);
}

From source file:org.excalibur.core.util.Properties2.java

public static Properties load(InputStream inStream) {
    Properties properties = new Properties();

    try {//from  w  w  w . ja  va2  s.co  m
        properties.load(inStream);
    } catch (IOException e) {
        LOGGER.error("Error on loading the properties. Error message: {}", e.getMessage());
        AnyThrow.throwUncheked(e);
    }

    return properties;
}

From source file:org.lambdamatic.elasticsearch.BaseIntegrationTest.java

protected static Client client() {
    final InputStream portsStream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("ports.properties");
    if (portsStream != null) {
        final Properties properties = new Properties();
        try {//from  w  ww  . j a  v  a  2s.c  o  m
            properties.load(portsStream);
        } catch (IOException e) {
            fail("Failed to load port properties from file", e);
        }
        return Client.connectTo(new HttpHost("localhost", Integer.parseInt(properties.getProperty("es.9200"))));
    }
    return Client.connectTo(new HttpHost("localhost", 9200));
}

From source file:com.gistlabs.mechanize.impl.MechanizeInitializer.java

protected static void loadProperties() throws Exception {
    Properties properties = new Properties();
    properties.load(MechanizeInitializer.class.getResourceAsStream("/mechanize.properties"));
    MechanizeAgent.setVersion(properties.getProperty("mechanize.version"));
}

From source file:com.thoughtworks.go.util.OperatingSystem.java

private static String readFromOsRelease() throws Exception {
    try (FileReader fileReader = new FileReader(new File("/etc/os-release"))) {
        Properties properties = new Properties();
        properties.load(fileReader);
        return unQuote(properties.getProperty("PRETTY_NAME"));
    }/*from  w w w .j a v a  2s .c o m*/
}

From source file:com.googlecode.wmbutil.cache.LookupDataSourceFactory.java

public static synchronized LookupDataSource getDataSource() throws CacheRefreshException {
    if (dataSource == null) {
        try {/* ww w .  j  a v a 2 s.  co  m*/
            Properties config = new Properties();
            config.load(new FileInputStream("lookup-connection.properties"));

            BasicDataSource ds = new BasicDataSource();
            ds.setDriverClassName(config.getProperty("lookup.class"));
            ds.setUrl(config.getProperty("lookup.url"));
            ds.setUsername(config.getProperty("lookup.username"));
            ds.setPassword(config.getProperty("lookup.password"));
            ds.setDefaultReadOnly(false);

            dataSource = new JdbcLookupDataSource(ds);
        } catch (FileNotFoundException e) {
            throw new CacheRefreshException("Could not find lookup-connection.properties file", e);
        } catch (IOException e) {
            throw new CacheRefreshException("Found, but could not read from lookup-connection.properties file",
                    e);
        } catch (RuntimeException e) {
            throw new CacheRefreshException("Could not create data source", e);
        }
    }

    return dataSource;
}

From source file:net.erdfelt.android.sdkfido.Build.java

public static String getVersion() {
    if (version == null) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        String resource = String.format("META-INF/maven/%s/%s/pom.properties", GROUP_ID, ARTIFACT_ID);
        URL url = cl.getResource(resource);
        if (url == null) {
            version = "[DEV]";
        } else {//from   www .  j a v a  2 s. c  o  m
            InputStream in = null;
            try {
                in = url.openStream();
                Properties props = new Properties();
                props.load(in);
                version = props.getProperty("version");
            } catch (IOException e) {
                LOG.log(Level.WARNING, "Unable to read: " + url, e);
                version = "[UNKNOWN]";
            } finally {
                IOUtils.closeQuietly(in);
            }
        }
    }
    return version;
}

From source file:com.alibaba.cobar.manager.qa.modle.CobarFactory.java

public static CobarAdapter getCobarAdapter(String cobarNodeName) throws IOException {
    CobarAdapter cAdapter = new CobarAdapter();
    Properties prop = new Properties();
    prop.load(CobarFactory.class.getClassLoader().getResourceAsStream("cobarNode.properties"));
    BasicDataSource ds = new BasicDataSource();
    String user = prop.getProperty(cobarNodeName + ".user").trim();
    String password = prop.getProperty(cobarNodeName + ".password").trim();
    String ip = prop.getProperty(cobarNodeName + ".ip").trim();
    int managerPort = Integer.parseInt(prop.getProperty(cobarNodeName + ".manager.port").trim());
    int maxActive = -1;
    int minIdle = 0;
    long timeBetweenEvictionRunsMillis = 10 * 60 * 1000;
    int numTestsPerEvictionRun = Integer.MAX_VALUE;
    long minEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
    ds.setUsername(user);//from   w  ww  .  j  ava2 s .  co  m
    ds.setPassword(password);
    ds.setUrl(new StringBuilder().append("jdbc:mysql://").append(ip).append(":").append(managerPort).append("/")
            .toString());
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setMaxActive(maxActive);
    ds.setMinIdle(minIdle);
    ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    ds.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    ds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

    cAdapter.setDataSource(ds);
    return cAdapter;
}