Example usage for java.util Properties size

List of usage examples for java.util Properties size

Introduction

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

Prototype

@Override
    public int size() 

Source Link

Usage

From source file:org.springframework.beans.ConcurrentBeanWrapperTests.java

private static void performSet() {
    TestBean bean = new TestBean();

    Properties p = (Properties) System.getProperties().clone();

    assertTrue("The System properties must not be empty", p.size() != 0);

    for (Iterator<?> i = p.entrySet().iterator(); i.hasNext();) {
        i.next();//from  w  ww.  j ava  2s. com
        if (Math.random() > 0.9) {
            i.remove();
        }
    }

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    try {
        p.store(buffer, null);
    } catch (IOException e) {
        // ByteArrayOutputStream does not throw
        // any IOException
    }
    String value = new String(buffer.toByteArray());

    BeanWrapperImpl wrapper = new BeanWrapperImpl(bean);
    wrapper.setPropertyValue("properties", value);
    assertEquals(p, bean.getProperties());
}

From source file:com.comcast.cats.domain.configuration.CatsHome.java

public static void displaySystemProperties() {
    Properties props = System.getProperties();
    logger.info("Found " + Integer.toString(props.size()) + " System Properties!");

    Iterator<Entry<Object, Object>> iterator = props.entrySet().iterator();
    Entry<Object, Object> entry;

    while (iterator.hasNext()) {
        entry = iterator.next();/*from   w  w  w  . java2 s .  c  o m*/
        logger.info(entry.getKey() + "=" + entry.getValue());
    }
}

From source file:org.ebayopensource.turmeric.eclipse.utils.io.PropertiesFileUtil.java

/**
 * Checks if is equal.//from w ww  .  j a v a2 s .  co  m
 *
 * @param firstProperties the first properties
 * @param secondProperties the second properties
 * @return assumes that the key/value are all strings can be enhanced later
 * if required
 */
public static boolean isEqual(Properties firstProperties, Properties secondProperties) {
    if (firstProperties.size() == secondProperties.size()) {
        for (Object key1 : firstProperties.keySet()) {
            if (key1 instanceof String) {
                String strKey1 = (String) key1;
                String value1 = String.valueOf(firstProperties.getProperty(strKey1));
                String value2 = String.valueOf(secondProperties.getProperty(strKey1));
                if (StringUtils.equals(value1, value2) == false) {
                    return false;
                }
            } else {
                return false;
            }
        }
        return true;
    }
    return false;
}

From source file:org.apache.jcs.auxiliary.remote.RemoteUtils.java

/**
 * Loads properties for the named props file.
 * <p>//ww w.j  a  v a  2s  .c om
 * @param propFile
 * @return The properties object for the file
 * @throws IOException
 */
public static Properties loadProps(String propFile) throws IOException {
    InputStream is = RemoteUtils.class.getResourceAsStream(propFile);
    Properties props = new Properties();
    try {
        props.load(is);
        if (log.isDebugEnabled()) {
            log.debug("props.size=" + props.size());
        }

        if (log.isDebugEnabled()) {
            if (props != null) {
                Enumeration en = props.keys();
                StringBuffer buf = new StringBuffer();
                while (en.hasMoreElements()) {
                    String key = (String) en.nextElement();
                    buf.append("\n" + key + " = " + props.getProperty(key));
                }
                log.debug(buf.toString());
            } else {
                log.debug("props is null");
            }
        }

    } catch (Exception ex) {
        log.error("Error loading remote properties, for file name [" + propFile + "]", ex);
    } finally {
        if (is != null) {
            is.close();
        }
    }
    return props;
}

From source file:ext.deployit.community.cli.plainarchive.config.ConfigParser.java

private static List<ConfigurationItemMatcher> parseRules(Properties config, RuleParser parser) {
    List<ConfigurationItemMatcher> matchers = newLinkedList();
    Map<String, String> configProperties = fromProperties(config);

    int maxNumRules = config.size() / MIN_PROPERTIES_PER_RULE;
    // rules are numbered beginning with 1
    for (int i = 1; i <= maxNumRules; i++) {
        Map<String, String> nthRuleProperties = new RulePropertiesCollector(i).apply(configProperties);
        if (nthRuleProperties.isEmpty()) {
            // only support consecutive numbering
            break;
        }//from   www .  j  ava 2s . c  o  m
        matchers.add(parser.apply(nthRuleProperties));
    }
    return matchers;
}

From source file:org.apache.maven.wagon.providers.http.ConfigurationUtils.java

public static Header[] asRequestHeaders(HttpMethodConfiguration config) {
    Properties headers = config.getHeaders();
    if (headers == null) {
        return new Header[0];
    }//from w ww .  jav a2s  .c  o m

    Header[] result = new Header[headers.size()];

    int index = 0;
    for (Map.Entry entry : headers.entrySet()) {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();

        Header header = new BasicHeader(key, value);
        result[index++] = header;
    }

    return result;
}

From source file:com.pactera.edg.am.metamanager.extractor.util.AdapterContextLoader.java

/**
 * /* ww w  . j av a 2  s.  c  o m*/
 * SpringClassPathXMLApplicationContext,????${var}
 * prop??? ??.properties??,??${var}
 * 
 * @param configLocations
 *            application context?
 * @param props
 *            ??application context????key/value
 * @return ApplicationContext Application
 *         Context,?,??,bean,null
 * @exception
 */
public static ApplicationContext createApplicationContext(String[] configLocations, Properties props) {
    // :spring?system properties??.
    Properties bakProps = null;
    String logMsg = null;
    try {
        if (props != null && props.size() > 0) {
            // system properties
            bakProps = System.getProperties();

            for (Object key : props.keySet()) {
                System.setProperty((String) key, props.getProperty((String) key));
            }

            if (log.isDebugEnabled()) {
                StringBuffer sb = new StringBuffer();
                sb.append("??springxml?${var}prop:\n");
                for (Object key : props.keySet()) {
                    sb.append(key + "=" + System.getProperty((String) key));
                    sb.append("\n");
                }
                log.debug(sb.toString());
            }
        }
        return new ClassPathXmlApplicationContext(configLocations);
    } catch (BeanDefinitionStoreException bse) {
        // 
        logMsg = new StringBuilder("?spring,?")
                .append(Arrays.toString(configLocations)).append(bse.getMessage()).toString();
        log.error(logMsg, bse);
        AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR, logMsg);
        throw bse;
    } catch (BeanCreationException ce) {
        // BEAN,?RMI??
        logMsg = new StringBuilder("?spring,?BEAN,")
                .append(Arrays.toString(configLocations)).append(ce.getMessage()).toString();
        log.error(logMsg, ce);
        if (logMsg.indexOf("ORA-01017") > -1 || logMsg.indexOf("Invalid password") > -1) {
            // ORACLE????
            AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR,
                    "??/?,?,???????!");
        } else {
            AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR, logMsg);
        }
        throw ce;
    } finally {
        // system properties,???,??
        if (bakProps != null) {
            System.setProperties(bakProps);
        }
    }
}

From source file:com.mindcognition.mindraider.MindRaiderApplication.java

/**
 * Debug.//from   w  ww.  j  ava 2s .  c o  m
 */
public static void debug() {
    Properties properties = System.getProperties();
    Enumeration<Object> propertyNames = properties.keys();

    if (properties.size() > 0) {
        logger.debug(" Properties debug (" + properties.size() + "):"); //$NON-NLS-1$ //$NON-NLS-2$
        String element = null;
        while (propertyNames.hasMoreElements()) {
            element = (String) propertyNames.nextElement();
            if (element.startsWith(MindRaiderConstants.MR)) {
                logger.debug("  " + element + ": " //$NON-NLS-1$ //$NON-NLS-2$
                        + System.getProperty(element));
            }
        }
        logger.debug(" - done -"); //$NON-NLS-1$
    }
}

From source file:org.mousephenotype.dcc.utils.persistence.HibernateManagerTest.java

@BeforeClass
public static void testConfiguration() {
    try {/*from   www. j a  v a 2s . co m*/
        reader = new Reader(CONNECTION_PROPERTIES_FILENAME);
    } catch (ConfigurationException ex) {
        logger.error("", ex);
        Assert.fail();
    }
    Properties properties = reader.getProperties();

    Assert.assertTrue(properties.size() > 1);
    try {
        HibernateManagerTest.hibernateManager = new HibernateManager(properties, PERSISTENCE_UNITNAME);
    } catch (HibernateException ex) {
        logger.error("", ex);
        Assert.fail();
    }

    Assert.assertNotNull(HibernateManagerTest.hibernateManager);

    HibernateManagerTest.centreProcedureSubmissionSet = generateSubmissionSetExampleForCentreProcedure();
    HibernateManagerTest.centreSpecimenSubmissionSet = generateSubmissionSetExampleForCentreSpecimen();

    hibernateManager.persist(HibernateManagerTest.centreProcedureSubmissionSet);
    logger.info("centreProcedureSubmissionSet {} persisted",
            HibernateManagerTest.centreProcedureSubmissionSet.getHjid());

    hibernateManager.persist(HibernateManagerTest.centreSpecimenSubmissionSet);
    logger.info("centreSpecimenSubmissionSet {} persisted",
            HibernateManagerTest.centreSpecimenSubmissionSet.getHjid());

}

From source file:org.tinymediamanager.core.License.java

public static boolean encrypt(Properties props) {
    try {//w  w w .  j a  v a 2  s  .c  o m
        if (props == null || props.size() == 0) {
            return false;
        }

        String request = "https://script.google.com/macros/s/AKfycbz7gu6I046KesXCHJJe6OEPX2tx18RcfiMS5Id-7NXsNYYMnLvK/exec";
        String urlParameters = "mac=" + getMac();
        for (String key : props.stringPropertyNames()) {
            String value = props.getProperty(key);
            urlParameters += "&" + key + "=" + URLEncoder.encode(value, "UTF-8");
        }

        HttpURLConnection connection = new OkUrlFactory(TmmHttpClient.getHttpClient()).open(new URL(request));
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setInstanceFollowRedirects(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        connection.setRequestProperty("charset", "utf-8");
        connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
        connection.setUseCaches(false);

        OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
        writer.write(urlParameters);
        writer.flush();
        String response = IOUtils.toString(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        writer.close();
        if (response != null && response.isEmpty()) {
            LOGGER.warn("empty response at license generation; code " + connection.getResponseCode());
            return false;
        }

        // GET method
        // StringWriter writer = new StringWriter();
        // IOUtils.copy(url.getInputStream(), writer, "UTF-8");
        // String response = writer.toString();

        File f = new File(LICENSE_FILE);
        if (Globals.isRunningJavaWebStart()) {
            // when in webstart, put it in user home
            f = new File(System.getProperty("user.home") + File.separator + ".tmm", LICENSE_FILE);
            if (!f.getParentFile().exists()) {
                f.getParentFile().mkdir();
            }
        }
        FileUtils.writeStringToFile(f, response);

        return true;
    } catch (Exception e) {
        LOGGER.error("Error generating license", e);
        return false;
    }
}