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.tinymediamanager.core.License.java

public static Properties decrypt() {
    try {/*from   www. j  ava  2 s .  c o m*/
        FileInputStream input = new FileInputStream(getLicenseFile());
        byte[] fileData = new byte[input.available()];
        input.read(fileData);
        input.close();
        String lic = new String(fileData, "UTF-8");

        String iv = "F27D5C9927726BCEFE7510B1BDD3D137";
        String salt = "3FF2EC019C627B945225DEBAD71A01B6985FE84C95A70EB132882F88C0A59A55";
        AesUtil util = new AesUtil(128, 100);

        Properties prop = new Properties();
        try {
            // try to decrypt with new/correct MAC implementation
            String decrypt = util.decrypt(salt, iv, getMac(), lic);
            StringReader reader = new StringReader(decrypt);
            prop.load(reader);
        } catch (Exception e) {
            // didn't work? try it with all our found MACs (+ an empty one of an old impl)
            for (String mac : getAllMacAddresses()) {
                try {
                    String decrypt = util.decrypt(salt, iv, mac, lic);
                    StringReader reader = new StringReader(decrypt);
                    prop.load(reader);
                } catch (Exception e2) {
                }
            }
        }
        return prop.size() > 0 ? prop : null; // return NULL when properties are empty
    } catch (Exception e) {
        // file not found or whatever
        LOGGER.error("Error decrypting license file", e);
        return null;
    }
}

From source file:gobblin.data.management.conversion.hive.query.HiveAvroORCQueryGenerator.java

private static Properties getTableProperties(Properties tableProperties) {
    if (null == tableProperties || tableProperties.size() == 0) {
        return DEFAULT_TBL_PROPERTIES;
    }//  www . ja  v  a  2 s  .c o m

    for (String property : DEFAULT_TBL_PROPERTIES.stringPropertyNames()) {
        if (!tableProperties.containsKey(property)) {
            tableProperties.put(property, DEFAULT_TBL_PROPERTIES.get(property));
        }
    }

    return tableProperties;
}

From source file:org.dspace.globus.Globus.java

public static void loadMetadataMap(Properties map) {
    String fname = getGlobusConfigProperty(GLOBUS_METADATA_MAPPING_PROP);
    logger.info("Loading metadata map from file " + fname);
    InputStream input = null;/*  w  w  w  .  j a v a  2 s.  c  om*/
    try {
        input = new FileInputStream(fname);
        map.load(input);
        logger.info("Loaded " + map.size() + " mappings from file");
    } catch (Exception e) {
        logger.error("Exception reading metadata mapping file " + fname);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (Exception ex) {
                logger.error("Exception closing input stream");
            }
        }
    }
}

From source file:ar.com.zauber.commons.web.proxy.impl.dao.properties.PropertiesChainedRegexURLRequestMapperDAOTest.java

/** @throws Exception on error */
public final void testSave() throws Exception {
    final URLRequestMapper c = new ChainedURLRequestMapper(Arrays.asList(new URLRequestMapper[] {
            new RegexURLRequestMapper(Pattern.compile("^/nexus/(.*)$"), "http://localhost:9095/nexus/$1"),
            new RegexURLRequestMapper(Pattern.compile("^/([^/]+)/([^/]+)/([^/]+)/(.*)$"),
                    "http://localhost:9095/nexus/content/repositories/$1-$2-$3/$4"),

    }));// ww  w .  java2 s.co  m
    new PropertiesChainedRegexURLRequestMapperDAO(new SimplePropertiesProvider(), new PropertiesPersister() {
        public void save(final Properties properties) {
            assertEquals(2, properties.size());
            assertEquals("^/nexus/(.*)$=http://localhost:9095/nexus/$1", properties.get("0"));
            assertEquals("^/([^/]+)/([^/]+)/([^/]+)/(.*)$=http://"
                    + "localhost:9095/nexus/content/repositories/$1-$2-$3/$4", properties.get("1"));
        }
    }).save(c);
}

From source file:org.openinfinity.core.spring.JdbcPropertyPlaceholderConfigurerTests.java

@Test
public void givenDataSourceWhenAccessingSharedPropertiesThenMustReadKeysAndValuesFromDataSourceToProperties() {
    Properties properties = jdbcPropertyPlaceholderConfigurer.readPropertiesFromDataSource();
    assertEquals(6, properties.size());
}

From source file:org.apache.pig.Main.java

private static void configureLog4J(Properties properties, PigContext pigContext) {
    // TODO Add a file appender for the logs
    // TODO Need to create a property in the properties file for it.
    // sgroschupf, 25Feb2008: this method will be obsolete with PIG-115.

    String log4jconf = properties.getProperty(LOG4J_CONF);
    String trueString = "true";
    boolean brief = trueString.equalsIgnoreCase(properties.getProperty(BRIEF));
    Level logLevel = Level.INFO;

    String logLevelString = properties.getProperty(DEBUG);
    if (logLevelString != null) {
        logLevel = Level.toLevel(logLevelString, Level.INFO);
    }/*from www  .ja  va  2 s.  c  o  m*/

    final Properties props = log4jConfAsProperties(log4jconf);
    if (props.size() == 0) {
        props.setProperty("log4j.logger.org.apache.pig", logLevel.toString());
        if ((logLevelString = System.getProperty("pig.logfile.level")) == null) {
            props.setProperty("log4j.rootLogger", "INFO, PIGCONSOLE");
        } else {
            logLevel = Level.toLevel(logLevelString, Level.INFO);
            props.setProperty("log4j.logger.org.apache.pig", logLevel.toString());
            props.setProperty("log4j.rootLogger", "INFO, PIGCONSOLE, F");
            props.setProperty("log4j.appender.F", "org.apache.log4j.RollingFileAppender");
            props.setProperty("log4j.appender.F.File", properties.getProperty("pig.logfile"));
            props.setProperty("log4j.appender.F.layout", "org.apache.log4j.PatternLayout");
            props.setProperty("log4j.appender.F.layout.ConversionPattern",
                    brief ? "%m%n" : "%d [%t] %-5p %c - %m%n");
        }

        props.setProperty("log4j.appender.PIGCONSOLE", "org.apache.log4j.ConsoleAppender");
        props.setProperty("log4j.appender.PIGCONSOLE.target", "System.err");
        props.setProperty("log4j.appender.PIGCONSOLE.layout", "org.apache.log4j.PatternLayout");
        props.setProperty("log4j.appender.PIGCONSOLE.layout.ConversionPattern",
                brief ? "%m%n" : "%d [%t] %-5p %c - %m%n");
    }

    PropertyConfigurator.configure(props);
    logLevel = Logger.getLogger("org.apache.pig").getLevel();
    if (logLevel == null) {
        logLevel = Logger.getLogger("org.apache.pig").getEffectiveLevel();
    }
    Properties backendProps = pigContext.getLog4jProperties();
    backendProps.setProperty("log4j.logger.org.apache.pig", logLevel.toString());
    pigContext.setLog4jProperties(backendProps);
    pigContext.setDefaultLogLevel(logLevel);
}

From source file:nl.tudelft.stocktrader.derby.DerbyConnectionProvider.java

private String getConnectionString(Properties prop) {
    if (connection == null) {
        if (prop == null || prop.size() <= 0) {
            connection = "jdbc:derby://localhost:1527/stocktraderdb?user=trade&password=yyy";
        } else {//w  ww.  ja va 2 s  . c om
            StringBuffer buf = new StringBuffer();
            buf.append("jdbc:derby://");
            buf.append(prop.getProperty(PROP_DB_HOST));
            buf.append(":" + prop.getProperty(PROP_DB_PORT));
            buf.append("/" + prop.getProperty(PROP_DB_NAME));
            //buf.append("?user=" + prop.getProperty(PROP_DB_USER));
            //buf.append("&password=" + prop.getProperty(PROP_DB_PASSWORD));
            connection = buf.toString();
        }
    }

    if (logger.isDebugEnabled()) {
        logger.debug("DerbyDAOFactory.getConnectionString()\nConnection :" + connection);
    }
    return connection;
}

From source file:nl.tudelft.stocktrader.mysql.MySQLConnectionProvider.java

private String getConnectionString(Properties prop) {
    if (connection == null) {
        if (prop == null || prop.size() <= 0) {
            connection = "jdbc:mysql://localhost:3306/stocktraderdb?user=trade&password=yyy";
        } else {//from w ww. jav a  2 s  . c  o m
            StringBuffer buf = new StringBuffer();
            buf.append("jdbc:mysql://");
            buf.append(prop.getProperty(PROP_DB_HOST));
            buf.append(":" + prop.getProperty(PROP_DB_PORT));
            buf.append("/" + prop.getProperty(PROP_DB_NAME));
            buf.append("?user=" + prop.getProperty(PROP_DB_USER));
            buf.append("&password=" + prop.getProperty(PROP_DB_PASSWORD));
            connection = buf.toString();
        }
    }

    if (logger.isDebugEnabled()) {
        logger.debug("MySQLDAOFactory.getConnectionString()\nConnection :" + connection);
    }
    return connection;
}

From source file:org.slc.sli.ingestion.util.ExposedPropertyPlaceholderConfigurer.java

@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
        throws BeansException {
    Map<String, String> tmpProperties = new HashMap<String, String>(props.size());
    super.processProperties(beanFactoryToProcess, props);
    for (Entry<Object, Object> entry : props.entrySet()) {
        tmpProperties.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
    }/* w  w w  .j a v  a 2 s .  c o  m*/
    this.properties = Collections.unmodifiableMap(tmpProperties);
}

From source file:org.ldp4j.server.utils.spring.MonitorizedPropertyPlaceholderConfigurerTest.java

@Test
public void testMergeProperties$dontShow() throws Exception {
    MonitorizedPropertyPlaceholderConfigurer sut = new MonitorizedPropertyPlaceholderConfigurer();
    sut.setIgnoreResourceNotFound(true);
    sut.setLocations(this.locations);
    Properties mergeProperties = sut.mergeProperties();
    assertThat(mergeProperties.size(), is(4));
}