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:com.magnet.mmx.server.plugin.mmxmgmt.api.user.MMXUsersResourceTest.java

public static void setupDatabase() throws Exception {
    InputStream inputStream = DeviceDAOImplTest.class.getResourceAsStream("/test.properties");

    Properties testProperties = new Properties();
    testProperties.load(inputStream);

    String host = testProperties.getProperty("db.host");
    String port = testProperties.getProperty("db.port");
    String user = testProperties.getProperty("db.user");
    String password = testProperties.getProperty("db.password");
    String driver = testProperties.getProperty("db.driver");
    String schema = testProperties.getProperty("db.schema");

    String url = "jdbc:mysql://" + host + ":" + port + "/" + schema;

    ds = new BasicDataSource();
    ds.setDriverClassName(driver);/*  w  w  w.j  a v  a 2 s.c  o  m*/
    ds.setUsername(user);
    ds.setPassword(password);
    ds.setUrl(url);

    DBTestUtil.setBasicDataSource(ds);
    new MockUp<AppDAOImpl>() {
        @Mock
        protected String getEncrypted(String value) {
            return value;
        }
    };
    new MockUp<DefaultOpenfireEncryptor>() {
        @Mock
        public String getDecrypted(String value) {
            return value;
        }

        @Mock
        public String getEncrypted(String value) {
            return value;
        }
    };
    DBTestUtil.setupMockDBUtil();
    MMXUsersResourceTest.appEntity = createRandomApp();
    for (int i = 0; i < 10; i++) {
        userEntityList.add(createRandomUser(appEntity, i));
    }
}

From source file:net.sf.ehcache.util.PropertyUtil.java

/**
 * Parse properties supplied as a comma separated list into a <code>Properties</code> object
 * @param propertiesString a comma separated list such as <code>"propertyA=s, propertyB=t"</code>
 * @return a newly constructed properties object
 *//*from ww  w.  j av  a 2  s  . co  m*/
public static Properties parseProperties(String propertiesString, String propertySeparator) {
    String propertySeparatorLocal = propertySeparator;
    if (propertiesString == null) {
        LOG.debug("propertiesString is null.");
        return null;
    }
    if (propertySeparator == null) {
        propertySeparatorLocal = DEFAULT_PROPERTY_SEPARATOR;
    }
    Properties properties = new Properties();
    String propertyLines = propertiesString.trim();
    propertyLines = propertyLines.replaceAll(propertySeparatorLocal, "\n");
    try {
        properties.load(new ByteArrayInputStream(propertyLines.getBytes()));
    } catch (IOException e) {
        LOG.error("Cannot load properties from " + propertiesString);
    }
    return properties;
}

From source file:io.hawkcd.agent.AgentConfiguration.java

private static Properties fetchConfigFileProperties() {
    File configFile = new File(ConfigConstants.AGENT_CONFIG_FILE_LOCATION);
    if (!configFile.exists()) {
        createConfigFile(configFile);//from  w ww .  ja va2  s  .c  om
    }

    Properties properties = new Properties();
    try {
        InputStream inputStream = new FileInputStream(configFile);
        properties.load(inputStream);
        inputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return properties;
}

From source file:com.attilax.zip.FileUtil.java

/**
 * ??Map/*  w  w w.  ja  v  a  2 s  .  co m*/
 * 
 * @param inputStream
 * @return
 * @throws Exception
 */
public static final Map<String, String> getPropertiesMap(InputStream inputStream) throws Exception {
    Properties properties = new Properties();
    properties.load(inputStream);
    Map<String, String> map = new HashMap<String, String>();
    Set<Object> keySet = properties.keySet();
    for (Object key : keySet) {
        map.put((String) key, properties.getProperty((String) key));
    }
    return map;
}

From source file:de.snertlab.xdccBee.ui.Application.java

private static Properties loadVersionProperties() {
    try {//from w w w .  ja va 2s .  c om
        Properties properties = new Properties();
        properties.load(Application.class.getResourceAsStream("version.properties")); //$NON-NLS-1$
        return properties;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:application.gen.gen.java

public static void genMybatisFile(List<Table> tableList, ConnObj obj) {
    Properties pros = new Properties();
    String configPath = "";
    try {//from  w w  w.  j  av a 2 s. c  o m
        pros.load(new FileInputStream("RelicConfig" + File.separator + "velocity.properties"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("cant found the velocity.properties");
        e.printStackTrace();
    }
    Velocity.init(pros);

    VelocityContext context = new VelocityContext();
    for (application.bean.Template tem : Context.templateList.getTemplates()) {
        if (tableList.get(0).getDbType().equalsIgnoreCase(tem.getDbType()) && tem.getType() == 2) {
            context.put("driver", obj.getDbConfiguration().getDriver());
            context.put("tableList", tableList);
            context.put("cDir", Context.cDir);
            context.put("schema", obj.getSchema());
            context.put("dbConfiguration", obj.getDbConfiguration());
            context.put("url", obj.getDbConfiguration().getUrl()
                    + (obj.getCatalog() == null ? "" : "/" + obj.getCatalog()));
            configPath = tem.getGenDir() + tem.getNamePre() + "generatorConfigMyBatis" + tem.getNameSuf();
            gen(context, tem.getTemplatePath(), configPath);
        }
    }
    MybatisUtil.genMybatis(configPath);
}

From source file:com.dotmarketing.util.UpdateUtil.java

/**
 * Loads the update.properties file// w ww. j  a  va2  s  . c  om
 *
 * @return the update.properties properties
 */
private static Properties loadUpdateProperties() {

    Properties props = new Properties();

    ClassLoader cl = UpdateUtil.class.getClassLoader();
    InputStream is = cl.getResourceAsStream(Constants.PROPERTIES_UPDATE_FILE_LOCATION);
    try {
        props.load(is);
    } catch (IOException e) {
        Logger.debug(UpdateUtil.class, "IOException: " + e.getMessage(), e);
    }

    return props;
}

From source file:it.scoppelletti.programmerpower.spring.config.BeanConfigUtils.java

/**
 * Restituisce la sorgente per la sostituzione dei riferimenti alle
 * propriet&agrave; nelle risorse di definizione dei bean.
 * /*from   w w w. ja  va2 s .  co  m*/
 * @return Collezione. Se la sorgente delle propriet&agrave; non &egrave;
 *         rilevata, restituisce {@code null}.
 * @see    #CONFIG_FILE
 * @see    it.scoppelletti.programmerpower.console.spring.ConsoleApplicationRunner
 * @see    it.scoppelletti.programmerpower.web.spring.config.WebApplicationContextInitializer
 * @see    <A HREF="{@docRoot}/../reference/setup/envprops.html"
 *         TARGET="_top">Propriet&agrave; di ambiente</A>
 */
public static PropertySource<?> loadPropertySource() {
    InputStream in = null;
    Properties props;

    in = ReflectionUtils.getResourceAsStream(BeanConfigUtils.CONFIG_FILE);
    if (in == null) {
        return null;
    }

    props = new Properties();
    try {
        props.load(in);
    } catch (IOException ex) {
        myLogger.error(String.format("Failed to load %1$s.", BeanConfigUtils.CONFIG_FILE), ex);
        return null;
    } finally {
        if (in != null) {
            IOUtils.close(in);
            in = null;
        }
    }

    return new PropertiesPropertySource(BeanConfigUtils.CONFIG_FILE, props);
}

From source file:org.killbill.billing.plugin.TestUtils.java

public static Properties loadProperties(final String fileName) throws IOException {
    final String propertiesAsString = toString(fileName);
    final Properties properties = new Properties();
    properties.load(new StringReader(propertiesAsString));
    return properties;
}