List of usage examples for java.util Properties size
@Override public int size()
From source file:org.fuin.utils4j.Utils4JTest.java
/** * @testng.test//from w w w . j a va 2 s.c om */ public final void testLoadPropertiesURLString() throws MalformedURLException { final Properties props = Utils4J.loadProperties(TEST_PROPERTIES_FILE.getParentFile().toURI().toURL(), TEST_PROPERTIES_FILE.getName()); Assert.assertEquals(3, props.size()); Assert.assertEquals("1", props.get("one")); Assert.assertEquals("2", props.get("two")); Assert.assertEquals("3", props.get("three")); }
From source file:com.handpoint.headstart.client.ui.MainActivity.java
void handleIniFile(Intent intent) { if (intent.getData() == null) { Toast.makeText(getApplicationContext(), R.string.error_invalid_data, Toast.LENGTH_LONG).show(); logger.log(Level.SEVERE, "Import ss file failed: no URI in intent"); } else {//from w w w. ja v a2 s . com try { Properties ini = loadIniProperties(intent); if (null == ini || ini.size() == 0) { Toast.makeText(getApplicationContext(), R.string.error_invalid_data, Toast.LENGTH_LONG).show(); logger.log(Level.SEVERE, "Import ss file failed: properties are not loaded (probably invalid ss file format)"); return; } String ss = ini.getProperty("ss"); if (!TextUtils.isEmpty(ss)) { mPreferences.edit() .putString(HeadstartService.PREFERENCE_SS_KEY, SecurityUtil.encrypt(HeadstartService.getProperty("auth_token").getBytes(), HexFormat.hexToBytes(ss))) .commit(); } String merchantName = ini.getProperty("merchant.name"); if (!TextUtils.isEmpty(merchantName)) { mPreferences.edit().putString(HeadstartService.PREFERENCE_MERCHANT_NAME, merchantName).commit(); } Toast.makeText(this, R.string.ini_data_loaded, Toast.LENGTH_LONG).show(); mConnection.getService().refresh(); } catch (Exception e) { Toast.makeText(getApplicationContext(), R.string.ini_data_load_failed, Toast.LENGTH_LONG).show(); logger.log(Level.SEVERE, "Import ss file failed", e); } } }
From source file:voldemort.VoldemortAdminTool.java
private static void synchronizeMetadataVersion(AdminClient adminClient, int baseNodeId) { String valueObject = getMetadataVersionsForNode(adminClient, baseNodeId); Properties props = new Properties(); try {//from w ww.j a v a 2 s. com props.load(new ByteArrayInputStream(valueObject.getBytes())); if (props.size() == 0) { System.err.println("The specified node does not have any versions metadata ! Exiting ..."); System.exit(-1); } adminClient.metadataMgmtOps.setMetadataversion(props); System.out.println("Metadata versions synchronized successfully."); } catch (IOException e) { System.err.println( "Error while retrieving Metadata versions from node : " + baseNodeId + ". Exception = \n"); e.printStackTrace(); System.exit(-1); } }
From source file:org.fuin.utils4j.Utils4JTest.java
/** * @testng.test/*from w w w . ja va 2s .c o m*/ */ public final void testLoadPropertiesStringString() throws MalformedURLException { final Properties props = Utils4J.loadProperties( TEST_PROPERTIES_FILE.getParentFile().toURI().toURL().toExternalForm(), TEST_PROPERTIES_FILE.getName()); Assert.assertEquals(3, props.size()); Assert.assertEquals("1", props.get("one")); Assert.assertEquals("2", props.get("two")); Assert.assertEquals("3", props.get("three")); }
From source file:com.redhat.red.offliner.alist.PomArtifactListReader.java
public PomArtifactListReader(final File settingsXml, final String typeMappingFile, final CredentialsProvider creds) { this.settingsXml = settingsXml; this.creds = creds; Properties props = new Properties(); if (StringUtils.isEmpty(typeMappingFile)) { try (InputStream mappingStream = getClass().getClassLoader() .getResourceAsStream(DEFAULT_TYPE_MAPPING_RES)) { props.load(mappingStream);/* w ww. j av a 2 s. c om*/ } catch (IOException ex) { throw new IllegalStateException("Failed to load Maven type mapping from default properties", ex); } } else { try (InputStream mappingStream = new FileInputStream(typeMappingFile)) { props.load(mappingStream); } catch (IOException ex) { throw new IllegalStateException( "Failed to load Maven type mapping provided properties file " + typeMappingFile, ex); } } this.typeMapping = new HashMap<>(props.size()); Pattern p = Pattern.compile("([^:]+)(?::(.+))?"); for (Map.Entry<Object, Object> entry : props.entrySet()) { String type = (String) entry.getKey(); String value = (String) entry.getValue(); Matcher m = p.matcher(value); if (!m.matches()) { throw new IllegalArgumentException( "The type mapping string \"" + typeMappingFile + "\" has a wrong format."); } String extension = m.group(1); if (m.groupCount() == 2) { String classifier = m.group(2); this.typeMapping.put(type, new TypeMapping(extension, classifier)); } else { this.typeMapping.put(type, new TypeMapping(extension)); } } }
From source file:com.heliosapm.streams.collector.ds.pool.impls.JMXClientPoolBuilder.java
/** * Creates a new JMXClientPoolBuilder//from w w w .j av a2 s .co m * @param config The configuration properties */ public JMXClientPoolBuilder(final Properties config) { final String jmxUrl = config.getProperty(JMX_URL_KEY, "").trim(); if (jmxUrl.isEmpty()) throw new IllegalArgumentException("The passed JMXServiceURL was null or empty"); try { url = new JMXServiceURL(jmxUrl); } catch (Exception ex) { throw new IllegalArgumentException("The passed JMXServiceURL was invalid", ex); } final String user = config.getProperty(JMX_USER_KEY, "").trim(); final String password = config.getProperty(JMX_PW_KEY, "").trim(); if (!user.isEmpty() && !password.isEmpty()) { credentials = new String[] { user, password }; env.put(JMXConnector.CREDENTIALS, credentials); } else { credentials = null; } if (config.size() > 1) { for (final String key : config.stringPropertyNames()) { final String _key = key.trim(); if (_key.startsWith(JMX_ENVMAP_PREFIX)) { final String _envKey = _key.replace(JMX_ENVMAP_PREFIX, ""); if (_envKey.isEmpty()) continue; final String _rawValue = config.getProperty(key, "").trim(); if (_rawValue.isEmpty()) continue; final Object _convertedValue = StringHelper.convertTyped(_rawValue); env.put(_envKey, _convertedValue); } } } }
From source file:org.alfresco.reporting.processor.PropertyProcessor.java
/** * /*w w w . ja va 2s . c o m*/ * @param definition * @param nodeRef Current nodeRef to put all related and relevant property * values into the reporting database * @param defBacklist the Blacklist String * @return */ public Properties processPropertyDefinitions(final Properties definition, final NodeRef nodeRef) { if (logger.isDebugEnabled()) logger.debug( "enter processPropertyDefinitions #props=" + definition.size() + " and nodeRef " + nodeRef); try { Map<QName, Serializable> map = nodeService.getProperties(nodeRef); if (logger.isDebugEnabled()) logger.debug("processPropertyDefinitions: Size of map=" + map.size()); Iterator<QName> keys = map.keySet().iterator(); while (keys.hasNext()) { String key = ""; String type = ""; try { QName qname = keys.next(); //Serializable s = map.get(qname); if (qname != null) { key = qname.toString(); key = replaceNameSpaces(key); if (logger.isDebugEnabled()) logger.debug("processPropertyDefinitions: Processing key " + key); if (!key.startsWith("{urn:schemas_microsoft_com:}") && !definition.containsKey(key)) { type = ""; if (getReplacementDataType().containsKey(key)) { type = getReplacementDataType().getProperty(key, "-").trim(); } else { type = "-"; try { type = dictionaryService.getProperty(qname).getDataType().toString().trim(); type = type.substring(type.indexOf("}") + 1, type.length()); type = getClassToColumnType().getProperty(type, "-"); } catch (NullPointerException npe) { // ignore. cm_source and a few others have issues in their datatype?? logger.info("Silent drop of NullPointerException against " + key); } // if the key is not in the BlackList, add it to the prop object that // will update the table definition } if ((type != null) && !type.equals("-") && !type.equals("") && (key != null) && (!key.equals("")) && (!getBlacklist().toLowerCase().contains("," + key.toLowerCase() + ","))) { definition.setProperty(key, type); if (logger.isDebugEnabled()) logger.debug("processPropertyDefinitions: Adding column " + key + "=" + type); } else { if (logger.isDebugEnabled()) logger.debug("Ignoring column " + key + "=" + type); } } // end if containsKey } //end if key!=null } catch (Exception e) { logger.error("processPropertyDefinitions: Property not found! Property below..."); logger.error("processPropertyDefinitions: type=" + type + ", key=" + key); e.printStackTrace(); } if (logger.isDebugEnabled()) logger.debug("processPropertyDefinitions: end while"); } // end while } catch (Exception e) { e.printStackTrace(); logger.error("processPropertyDefinitions: Finally an EXCEPTION " + e.getMessage()); } //logger.debug("Exit processPropertyDefinitions"); return definition; }
From source file:stg.pr.engine.startstop.CStartEngine.java
/** * Reads messsage from PRE.//from ww w. jav a 2s .c o m * * @return Properties. */ private Properties getMessageFromPRE() { logger_.log(LogLevel.FINEST, "Reading message method start."); String strTmpDir = System.getProperty("java.io.tmpdir"); String strFileSeparator = System.getProperty("file.separator"); if (!strTmpDir.endsWith(strFileSeparator)) { strTmpDir = strTmpDir + strFileSeparator; } File file = new File(strTmpDir + "pre.ini"); FileInputStream fis = null; Properties properties = new Properties(); try { fis = new FileInputStream(file); properties.load(fis); } catch (FileNotFoundException e) { logger_.log(LogLevel.FINEST, "FNFE. Unable to read the message."); } catch (IOException e) { logger_.log(LogLevel.FINEST, "IOE. Unable to read the message."); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { // dummy } } } if (properties.size() == 0) { properties.setProperty("action", "Shutdown"); properties.setProperty("attempt", "0"); } if (!file.delete()) { logger_.log(LogLevel.FINEST, "Unable to delete file #" + file.getName()); } logger_.log(LogLevel.FINEST, "Reading message method end."); return properties; }
From source file:org.apache.hadoop.tools.rumen.TestRumenJobTraces.java
/** * Test if the {@link JobConfigurationParser} can correctly extract out * key-value pairs from the job configuration. *///from www.j a v a2s .c om @Test public void testJobConfigurationParsing() throws Exception { final FileSystem lfs = FileSystem.getLocal(new Configuration()); final Path rootTempDir = new Path(System.getProperty("test.build.data", "/tmp")).makeQualified(lfs.getUri(), lfs.getWorkingDirectory()); final Path tempDir = new Path(rootTempDir, "TestJobConfigurationParser"); lfs.delete(tempDir, true); // Add some configuration parameters to the conf JobConf jConf = new JobConf(false); String key = "test.data"; String value = "hello world"; jConf.set(key, value); // create the job conf file Path jobConfPath = new Path(tempDir.toString(), "job.xml"); lfs.delete(jobConfPath, false); DataOutputStream jobConfStream = lfs.create(jobConfPath); jConf.writeXml(jobConfStream); jobConfStream.close(); // now read the job conf file using the job configuration parser Properties properties = JobConfigurationParser.parse(lfs.open(jobConfPath)); // check if the required parameter is loaded assertEquals( "Total number of extracted properties (" + properties.size() + ") doesn't match the expected size of 1 [" + "JobConfigurationParser]", 1, properties.size()); // check if the key is present in the extracted configuration assertTrue("Key " + key + " is missing in the configuration extracted " + "[JobConfigurationParser]", properties.keySet().contains(key)); // check if the desired property has the correct value assertEquals("JobConfigurationParser couldn't recover the parameters" + " correctly", value, properties.get(key)); // Test ZombieJob LoggedJob job = new LoggedJob(); job.setJobProperties(properties); ZombieJob zjob = new ZombieJob(job, null); Configuration zconf = zjob.getJobConf(); // check if the required parameter is loaded assertEquals("ZombieJob couldn't recover the parameters correctly", value, zconf.get(key)); }
From source file:org.fuin.utils4j.Utils4JTest.java
/** * @testng.test/* ww w. j a va 2 s . c o m*/ */ public final void testSaveProperties() throws IOException { final File testFile = File.createTempFile("Utils4JTest-", ".properties"); try { // Write to file Properties props = new Properties(); props.put("eins", "1"); props.put("zwei", "2"); props.put("drei", "3"); Utils4J.saveProperties(testFile, props, "COMMENT"); // Read it props = Utils4J.loadProperties(testFile); Assert.assertEquals(3, props.size()); Assert.assertEquals("1", props.get("eins")); Assert.assertEquals("2", props.get("zwei")); Assert.assertEquals("3", props.get("drei")); } finally { testFile.delete(); } }