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:org.rivetlogic.utils.IntegrationUtils.java

public static BeanFactory getBeanFactory() throws IOException {
    if (beanFactory == null) {
        synchronized (beanFactoryLockObj) {
            if (beanFactory == null) {
                PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
                AbstractApplicationContext context = new ClassPathXmlApplicationContext(
                        "application-context.xml");

                Resource resource = new FileSystemResource("cma-cfg.properties");
                Properties properties = new Properties();
                properties.load(resource.getInputStream());

                configurer.setProperties(properties);

                context.addBeanFactoryPostProcessor(configurer);
                context.refresh();/*w  w  w  . j a v  a 2  s.  c  o m*/

                beanFactory = context.getBeanFactory();
            }
        }
    }

    return beanFactory;
}

From source file:com.amazonaws.kinesis.dataviz.kinesisclient.KinesisApplication.java

/**
 * @param propertiesFile//from   w w  w.j a  v a 2  s  . co  m
 * @throws IOException Thrown when we run into issues reading properties
 */
private static void loadProperties(String propertiesFile) throws IOException {
    FileInputStream inputStream = new FileInputStream(propertiesFile);
    Properties properties = new Properties();
    try {
        properties.load(inputStream);
    } finally {
        inputStream.close();
    }

    String appNameOverride = properties.getProperty(ConfigKeys.APPLICATION_NAME_KEY);
    if (appNameOverride != null) {
        applicationName = appNameOverride;
    }
    LOG.info("Using application name " + applicationName);

    String streamNameOverride = properties.getProperty(ConfigKeys.STREAM_NAME_KEY);
    if (streamNameOverride != null) {
        streamName = streamNameOverride;
    }
    LOG.info("Using stream name " + streamName);

    String kinesisEndpointOverride = properties.getProperty(ConfigKeys.KINESIS_ENDPOINT_KEY);
    if (kinesisEndpointOverride != null) {
        kinesisEndpoint = kinesisEndpointOverride;
    }
    LOG.info("Using Kinesis endpoint " + kinesisEndpoint);

    String initialPositionOverride = properties.getProperty(ConfigKeys.INITIAL_POSITION_IN_STREAM_KEY);
    if (initialPositionOverride != null) {
        initialPositionInStream = InitialPositionInStream.valueOf(initialPositionOverride);
    }
    LOG.info("Using initial position " + initialPositionInStream.toString()
            + " (if a checkpoint is not found).");

    String redisEndpointOverride = properties.getProperty(ConfigKeys.REDIS_ENDPOINT);
    if (redisEndpointOverride != null) {
        redisEndpoint = redisEndpointOverride;
    }
    LOG.info("Using Redis endpoint " + redisEndpoint);

    String redisPortOverride = properties.getProperty(ConfigKeys.REDIS_PORT);
    if (redisPortOverride != null) {
        try {
            redisPort = Integer.parseInt(redisPortOverride);
        } catch (Exception e) {

        }
    }
    LOG.info("Using Redis port " + redisPort);

}

From source file:ch.entwine.weblounge.test.util.TestSiteUtils.java

/**
 * Loads the greetings from <code>/greetings.properties</code> into a
 * <code>Map</code> and returns them.
 * <p>/*from w w w .j a  va2 s.  co  m*/
 * Note that we need to do a conversion from the <code>ISO-LATIN-1</code>
 * (which is assumed by the <code>Properties</code> implementation) to
 * <code>utf-8</code>.
 * 
 * @return the greetings
 * @throws Exception
 *           if loading fails
 */
public static Map<String, String> loadGreetings() {
    Map<String, String> greetings = new HashMap<String, String>();
    InputStream is = TestSiteUtils.class.getResourceAsStream(GREETING_PROPS);
    try {
        Properties props = new Properties();
        props.load(is);
        for (Entry<Object, Object> entry : props.entrySet()) {
            try {
                String isoLatin1Value = entry.getValue().toString();
                String utf8Value = new String(isoLatin1Value.getBytes("ISO-8859-1"), "utf-8");
                greetings.put((String) entry.getKey(), utf8Value);
            } catch (UnsupportedEncodingException e) {
                logger.error("I can't believe the platform does not support encoding {}", e.getMessage());
            }
        }
    } catch (IOException e) {
        logger.error("Error reading greetings from " + GREETING_PROPS, e);
        return null;
    } finally {
        IOUtils.closeQuietly(is);
    }
    return greetings;
}

From source file:com.nextep.designer.headless.helpers.HeadlessHelper.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private static Map<String, String> loadConfigFile(String location) throws BatchException {
    File configFile = new File(location);
    if (!configFile.exists()) {
        throw new BatchException(
                MessageFormat.format(HeadlessMessages.getString("helper.configNotFound"), location)); //$NON-NLS-1$
    } else {//from  w w w. ja  va  2 s .c  o  m
        InputStream is = null;
        try {
            is = new FileInputStream(configFile);
            final Properties props = new Properties();
            props.load(is);
            return (Map) props;
        } catch (IOException e) {
            throw new BatchException(MessageFormat.format(HeadlessMessages.getString("helper.configReadError"), //$NON-NLS-1$
                    location, e.getMessage()), e);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    throw new BatchException(
                            MessageFormat.format(HeadlessMessages.getString("helper.configCloseError"), //$NON-NLS-1$
                                    location, e.getMessage()),
                            e);
                }
            }
        }
    }
}

From source file:de.egore911.versioning.deployer.performer.PerformReplacement.java

static void perform(File directory, List<String> wildcards, List<ReplacementPair> replacementsIn,
        List<File> replacementfiles) {
    List<ReplacementPair> replacements = new ArrayList<>(replacementsIn);
    for (File replacementfile : replacementfiles) {
        if (replacementfile.exists()) {
            Properties properties = new Properties();
            try {
                properties.load(new FileInputStream(replacementfile));
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
                return;
            }//from ww w.ja  va2s . c om
            for (Entry<Object, Object> x : properties.entrySet()) {
                replacements
                        .add(new ReplacementPair(((String) x.getKey()).trim(), ((String) x.getValue()).trim()));
            }
        } else {
            LOG.warn("Replacement file {} not found", replacementfile);
        }
    }
    perform(directory, wildcards, replacements);
}

From source file:org.edgexfoundry.EdgeXConfigWatcherApplication.java

private static boolean loadProperties() {
    Properties properties = new Properties();
    try (final InputStream inputStream = new FileInputStream(APP_PROPERTIES)) {
        properties.load(inputStream);
        serviceName = properties.getProperty("service.name");
        globalPrefix = properties.getProperty("global.prefix");
        servicePrefix = properties.getProperty("service.prefix");
        consulProtocol = properties.getProperty("consul.protocol");
        consulHost = properties.getProperty("consul.host");
        consulPort = Integer.parseInt(properties.getProperty("consul.port", "8500"));
        notificationPathKey = properties.getProperty("notification.path.key");
        notificationProtocol = properties.getProperty("notification.protocol");
        if (serviceName == null || globalPrefix == null || servicePrefix == null || consulProtocol == null
                || consulHost == null || consulPort == 0 || notificationPathKey == null
                || notificationProtocol == null) {
            LOGGER.error(/*from   w  ww  . ja  va 2 s  .c om*/
                    "Application configuration did not load properly or is missing elements.  Cannot create watcher.");
            System.exit(1);
            return false;
        }
    } catch (IOException ex) {
        LOGGER.error("IO Exception getting application properties: " + ex.getMessage());
        System.exit(1);
        return false;
    }
    return true;
}

From source file:com.mgmtp.jfunk.core.config.ModulesLoader.java

private static Properties loadProperties(final String propsFileName) throws IOException {
    Properties props = new Properties();
    InputStream is = null;/*  w w w.  j a v  a  2  s . co m*/
    try {
        is = ResourceLoader.getConfigInputStream(propsFileName);
        props.load(is);
    } finally {
        IOUtils.closeQuietly(is);
    }
    return props;
}

From source file:com.egt.core.util.VelocityEngineer.java

private static Properties getProperties(String propsFilename) throws Exception {
    Bitacora.trace(VelocityEngineer.class, "getProperties", propsFilename);
    Properties p = new Properties();
    try (FileInputStream inStream = new FileInputStream(propsFilename)) {
        p.load(inStream);
    }// www.j  a  v  a2  s .  c  om
    String comma = System.getProperties().getProperty("path.separator");
    String slash = System.getProperties().getProperty("file.separator");
    String VFRLP = "$" + EAC.VELOCITY_FILE_RESOURCE_LOADER_PATH;
    String vfrlp = EA.getString(EAC.VELOCITY_FILE_RESOURCE_LOADER_PATH);
    vfrlp = vfrlp.replace(comma, ", ");
    vfrlp = vfrlp.replace(slash, "/");
    String key;
    String value;
    for (Enumeration e = p.propertyNames(); e.hasMoreElements();) {
        key = (String) e.nextElement();
        value = p.getProperty(key);
        if (StringUtils.isNotBlank(value) && value.contains(VFRLP)) {
            value = value.replace(VFRLP, vfrlp);
            p.setProperty(key, value);
        }
        Bitacora.trace(key + "=" + value);
    }
    return p;
}

From source file:com.salas.bb.utils.xml.XmlReaderFactory.java

/**
 * Reads properties from the resource into the map. Each key in properties resource
 * is a value for comma-delimetered list of keys.
 *
 * @param propertiesName    name of properties resource.
 *
 * @return map.//w  w w.  j a  va  2  s.c o  m
 *
 * @throws IOException in case of I/O error.
 */
static Map readPropsToMap(String propertiesName) throws IOException {
    Properties props = new Properties();
    props.load(XmlReaderFactory.class.getClassLoader().getResourceAsStream(propertiesName));

    Map map = new HashMap();

    Enumeration propEnumeration = props.propertyNames();
    while (propEnumeration.hasMoreElements()) {
        String readerClassName = ((String) propEnumeration.nextElement()).trim();
        String[] encodings = StringUtils.split(props.getProperty(readerClassName), ",");

        putKeysInMap(map, encodings, readerClassName);
    }

    return map;
}

From source file:com.u2apple.tool.dao.DeviceI18nDaoImpl.java

private static Properties loadProperties(String key) throws IOException {
    String path = Configuration.getProperty(key);
    Properties properties = new Properties();
    properties.load(new FileInputStream(path));
    return properties;
}