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:com.jdy.ddj.common.utils.PropertiesLoader.java

/**
 * , Spring Resource?.//from   ww  w .j  a v  a2s  . com
 */
public static Properties loadProperties(String... resourcesPaths) throws IOException {
    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();
            props.load(is);
        } catch (IOException ex) {
            logger.info("Could not load properties from path:" + location + ", " + ex.getMessage());
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
    return props;
}

From source file:com.u2apple.tool.service.IdentifyAnalyticsService.java

private static Map loadModels() {
    Map<String, String> map = new HashMap<>();
    Properties props = new Properties();
    try {//from w w w.j a va2s  .c om
        props.load(IdentifyAnalyticsService.class.getResourceAsStream(Constants.MODELS));
        props.forEach((Object key, Object value) -> {
            String productId = (String) key;
            String model = AndroidDeviceUtils.formatModel((String) value);
            if (model.contains(",")) {
                String[] models = model.split(",");
                for (String m : models) {
                    map.put(m.trim(), productId);
                }
            } else {
                map.put(model, productId);
            }
        });
    } catch (IOException ex) {
        Logger.getLogger(IdentifyAnalyticsService.class.getName()).log(Level.SEVERE, null, ex);
    }
    return map;
}

From source file:Main.java

/**
 * Converts XML {@code <property name=""></property>} tags to Properties
 * object.// ww  w.  ja  va2s  . c o  m
 * 
 * @see java.util.XmlUtils.importProperties()
 * 
 * @param entries
 *            List of property nodes in the DOM
 */
public static Properties importProperties(NodeList entries) {
    Properties props = new Properties();
    int numEntries = entries.getLength();
    for (int i = 0; i < numEntries; i++) {
        Element entry = (Element) entries.item(i);
        if (entry.hasAttribute("name")) {
            Node n = entry.getFirstChild();
            String val = (n == null) ? "" : n.getNodeValue();
            props.setProperty(entry.getAttribute("name"), val);
        }
    }
    return props;
}

From source file:Main.java

public void init() {
    Properties p = new Properties();
    try {/*from   w  w w.  j  a va 2s.co m*/
        p.load((new URL(getCodeBase(), "user.props")).openStream());
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.sarm.lonelyplanet.process.LPUnMarshallerTest.java

@BeforeClass
public static void setUpClass() {

    Properties prop = new Properties();
    logger.info("LPUnMarshallerTest : Commencing loading test properties ...");
    String propFileName = LonelyConstants.testPropertyFile;

    try (InputStream input = new FileInputStream(propFileName)) {

        if (input == null) {
            logger.debug("input Stream for test.properties file : is Null  ");
            throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
        }//from  ww  w.j  a  va  2s  . c  o m
        prop.load(input);

    } catch (FileNotFoundException ex) {
        logger.debug("FileNotFoundException ");
        ex.printStackTrace();
    } catch (IOException ex) {
        logger.debug(" IOException");
        ex.printStackTrace();
    }
    taxonomyFileName = prop.getProperty(LonelyConstants.propertyTaxonomy);
    targetLocation = prop.getProperty(LonelyConstants.propertyHtmlTarget);
    destinationFileName = prop.getProperty(LonelyConstants.propertyDestination);
    lp = new LPUnMarshaller(taxonomyFileName, destinationFileName, targetLocation, null);

}

From source file:Main.java

/** Extract all of the child nodes as a Properties object from a node in an XML document */
public static Properties extractChildNodes(Document document) {
    try {//from w w w  .j av  a2 s. co m
        Properties props = new Properties();
        Element top = document.getDocumentElement();
        NodeList children = top.getChildNodes();
        Node child;
        String name;
        String value;
        for (int i = 0; i < children.getLength(); i++) {
            child = children.item(i);
            name = child.getNodeName();
            value = child.getTextContent().trim();
            props.setProperty(name, value);
        }
        return props;
    } catch (Exception e) {
        return new Properties();
    }
}

From source file:com.google.gwt.benchmark.compileserver.server.runners.settings.Settings.java

public static Settings parseSettings(File settingsFile) throws Exception {
    Settings settings = new Settings();
    Properties prop = new Properties();
    FileInputStream stream = null;
    try {/*from www  .j a va  2s.  co m*/
        stream = new FileInputStream(settingsFile);
        // load a properties file from class path, inside static method
        prop.load(stream);

        // get the property value and print it out
        settings.benchmarkRootDirectory = new File(prop.getProperty("benchmarksDirectory"));

        settings.moduleTemplate = loadModuleTemplate(prop.getProperty("moduleTemplate"));
        settings.hubUrl = new URL(prop.getProperty("seleniumHubUrl"));
        settings.benchmarkCompileOutputDir = new File(prop.getProperty("compileOutputDir"));
        settings.threadPoolSize = Integer.parseInt(prop.getProperty("threadPoolSize"));
        settings.servletContainerPort = Integer.parseInt(prop.getProperty("servletContainerPort"));
        settings.ipAddress = Util.getFirstNonLoopbackAddress().getHostAddress();
        settings.reportResults = prop.getProperty("reportResuts").equals("true");
        settings.reporterUrl = prop.getProperty("reporterUrl");
        settings.reporterSecret = prop.getProperty("reporterSecret");
        settings.mode = prop.getProperty("mode").equals("server") ? ManagerMode.SERVER : ManagerMode.LOCAL;
        settings.persistenceDir = new File(prop.getProperty("persistenceDir"));
        settings.gwtSourceLocation = new File(prop.getProperty("gwtSourceLocation"));

        String mailTo = prop.getProperty("mail.to");
        String mailFrom = prop.getProperty("mail.from");
        String mailHost = prop.getProperty("mail.host");
        String mailUsername = prop.getProperty("mail.username");
        String mailPassword = prop.getProperty("mail.password");

        settings.mailSettings = new MailSettings(mailFrom, mailTo, mailHost, mailUsername, mailPassword);
    } finally {
        IOUtils.closeQuietly(stream);
    }
    return settings;
}

From source file:com.gs.obevo.api.platform.ToolVersion.java

public static synchronized String getToolVersion() {
    if (TOOL_VERSION == null) {

        Properties props = new Properties();
        try {//www  .j  a va  2s. c o  m
            URL resource = Validate.notNull(ToolVersion.class.getClassLoader().getResource(PROPERTY_PATH),
                    "Could not read the required propertyPath: " + PROPERTY_PATH);
            props.load(resource.openStream());
        } catch (IOException e) {
            throw new RuntimeException("Could not open the required propertyPath: " + PROPERTY_PATH, e);
        }
        TOOL_VERSION = props.getProperty("tool.version");
    }

    return TOOL_VERSION;
}

From source file:com.hzc.framework.util.PropertiesUtil.java

public static void init(String configPath) {
    Properties p1 = new Properties();
    InputStream is = PropertiesUtil.class.getResourceAsStream(configPath);
    try {// ww w  .ja  va 2 s .  c  o  m
        p1.load(is);
        p.putAll(p1);
    } catch (IOException ex) {
        log.error(ex);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ex) {
                log.error(ex);
            }
            is = null;
        }
    }
}

From source file:Log4jPropertyHelper.java

public static void updateLog4jConfiguration(Class<?> targetClass, String log4jPath) throws Exception {
    Properties customProperties = new Properties();
    FileInputStream fs = null;/* ww  w  .  j  a  v a  2  s. co  m*/
    InputStream is = null;
    try {
        fs = new FileInputStream(log4jPath);
        is = targetClass.getResourceAsStream("/log4j.properties");
        customProperties.load(fs);
        Properties originalProperties = new Properties();
        originalProperties.load(is);
        for (Entry<Object, Object> entry : customProperties.entrySet()) {
            originalProperties.setProperty(entry.getKey().toString(), entry.getValue().toString());
        }
        LogManager.resetConfiguration();
        PropertyConfigurator.configure(originalProperties);
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(fs);
    }
}