Example usage for java.util Properties Properties

List of usage examples for java.util Properties Properties

Introduction

In this page you can find the example usage for java.util Properties Properties.

Prototype

public Properties() 

Source Link

Document

Creates an empty property list with no default values.

Usage

From source file:cn.vlabs.duckling.vwb.service.config.provider.PropertiesFileReader.java

private static Properties load(String configFile) {
    Properties props = new Properties();
    FileInputStream fis = null;/*from   www .  j  a v a 2  s  .  c o  m*/
    try {
        if (StringUtils.isEmpty(configFile)) {
            log.error("?");
        } else {
            fis = new FileInputStream(configFile);
            props.load(fis);
        }
    } catch (FileNotFoundException e) {
        log.error("?" + configFile + "");
    } catch (IOException e) {
        log.error(e);
    } finally {
        try {
            if (fis != null) {
                fis.close();
                fis = null;
            }
        } catch (IOException ioe) {
            log.error(ioe);
        }
    }
    return props;
}

From source file:Main.java

/**
 * Convenient call to load a properties file from the provided reader
 *///from  w  w  w. j a va 2s  .  c  om
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:com.uber.stream.kafka.mirrormaker.controller.utils.KafkaStarterUtils.java

public static Properties getDefaultKafkaConfiguration() {
    return new Properties();
}

From source file:com.trackplus.persist.TpEm.java

public static void initEntityManagerFactory(PropertiesConfiguration tcfg, String persistUnit) {
    Properties properties = new Properties();
    properties.put("javax.persistence.jdbc.driver",
            tcfg.getProperty("torque.dsfactory.track.connection.driver"));
    properties.put("javax.persistence.jdbc.url", tcfg.getProperty("torque.dsfactory.track.connection.url"));
    properties.put("javax.persistence.jdbc.user", tcfg.getProperty("torque.dsfactory.track.connection.user"));
    properties.put("javax.persistence.jdbc.password",
            tcfg.getProperty("torque.dsfactory.track.connection.password"));
    emf = Persistence.createEntityManagerFactory(persistUnit, properties);
}

From source file:com.github.dactiv.common.utils.PropertiesUtils.java

/**
 * properties, ???./*from  w  w  w . j  a  v a  2  s  .co m*/
 * Spring Resource?, ?UTF-8.
 * 
 * @param resourcesPaths Spring Resource path
 */
public static Properties loadProperties(String... resourcesPaths) {
    Properties props = new Properties();

    for (String location : resourcesPaths) {

        logger.debug("Loading properties file from:" + location);

        InputStream is = null;
        try {
            Resource resource = resourceLoader.getResource(location);
            is = resource.getInputStream();
            propertiesPersister.load(props, new InputStreamReader(is, DEFAULT_ENCODING));
        } catch (IOException ex) {
            logger.info("Could not load properties from classpath:" + location + ": " + ex.getMessage());
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
    return props;
}

From source file:ca.uhn.fhir.util.VersionUtil.java

private static void initialize() {
    InputStream is = null;//from www. j ava  2  s  . c  o m
    try {
        is = VersionUtil.class.getResourceAsStream("/ca/uhn/fhir/hapi-version.properties");
        Properties p = new Properties();
        p.load(is);
        ourVersion = p.getProperty("version");
        ourLog.info("HAPI FHIR version is: " + ourVersion);
    } catch (Exception e) {
        ourLog.warn("Unable to determine HAPI version information", e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:aot.util.IOUtil.java

public static Properties loadProperties(Class clazz, String name) {
    //        log.info("Load properties '{}/{}'", clazz.getPackage().getName(), name);
    try (InputStream input = clazz.getResourceAsStream(name)) {
        Properties properties = new Properties();
        properties.load(input);/*from w  w  w.j  a  v  a  2 s .c  o  m*/
        return properties;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:main.java.com.aosa.util.AOSAReadProperties.java

/**
 * Description<code>?Properties</code>      <br>
 * By mutou at 2012-1-12 ?05:48:25   <br>
 * String      <br>/* ww w.  jav a  2  s. c  om*/
 * @param profileName
 *       Properties ??ClassPath
 * @param key
 *       ?? 
 * @return
 * @throws
 */
public static String ReadValue(String profileName, String key) {
    String value = null;
    Properties properties = new Properties();
    FileInputStream input = null;
    try {
        input = new FileInputStream(
                Thread.currentThread().getContextClassLoader().getResource("").getPath() + profileName);
        properties.load(input);
        value = properties.getProperty(key);
    } catch (FileNotFoundException e) {
        logger.debug("Properties");
        throw new AOSARuntimeException("Properties", e);
    } catch (IOException e) {
        logger.debug("PropertiesIO");
        throw new AOSARuntimeException("PropertiesIO", e);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                logger.debug("IO?");
                throw new AOSARuntimeException("IO?", e);
            }
        }
    }
    return value;
}

From source file:com.hazelcast.qasonar.utils.PropertyReaderBuilder.java

private static PropertyReader fromPropertyFile(String propertyFileName) throws IOException {
    Properties props = new Properties();
    FileInputStream in = null;/*from   ww w  . j  a v a2 s  .co  m*/
    try {
        in = new FileInputStream(propertyFileName);
        props.load(in);
    } finally {
        closeQuietly(in);
    }

    return fromProperties(props);
}

From source file:dao.FetchEmailDAO.java

/**
 *
 * @return//from w  w w  . ja  v a2  s  .  c o  m
 */
public Message[] fetchEmail() {
    Properties props = new Properties();
    props.setProperty("mail.store.protocol", "imaps");
    //store inbox emails as Message object, store all into Message[] array.
    Message[] msgArr = null;
    try {
        Session session = Session.getInstance(props, null);
        Store store = session.getStore();
        store.connect("imap-mail.outlook.com", "joshymantou@outlook.com", "mcgrady11");
        Folder inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_ONLY);
        msgArr = inbox.getMessages();

        //System.out.println(msgArr.length);
        /*for (int i = 0; i < msgArr.length; i++) {
        Message msg = msgArr[i];
        Address[] in = msg.getFrom();
        for (Address address : in) {
            System.out.println("FROM:" + address.toString());
        }
                
        Multipart mp = (Multipart) msg.getContent();
        BodyPart bp = mp.getBodyPart(0);
        /*
        System.out.println("SENT DATE:" + msg.getSentDate());
        System.out.println("SUBJECT:" + msg.getSubject());
        System.out.println("CONTENT:" + bp.getContent());
                
        }*/
        ArrayUtils.reverse(msgArr);
        return msgArr;
    } catch (Exception mex) {
        mex.printStackTrace();
    }
    return msgArr;
}