List of usage examples for java.util Properties size
@Override public int size()
From source file:org.webdavaccess.LocalFileSystemStorage.java
/** * Set custom properties for given resource * /* w w w . jav a2 s . co m*/ * @param resourceUri URI of the resource * @param properties to set */ public void setCustomProperties(String resourceUri, Properties newProperties) { if (newProperties == null || newProperties.size() == 0) return; resourceUri = normalize(resourceUri); if (resourceUri.endsWith("/" + CUSTOM_PROPERTIES_STORAGE)) return; Properties props = (Properties) mPropertiesCache.get(resourceUri); if (props == null) { // Get them from persistent storage props = getPropertiesFor(resourceUri); if (props == null) props = new Properties(); } props.putAll(newProperties); // Save in cache try { mPropertiesCache.put(resourceUri, props); } catch (Exception e) { log.warn("Failed to put properties into cache for " + resourceUri); } // Write them to the persistent storage saveCustomProperties(props, resourceUri); }
From source file:com.mnxfst.testing.client.TestTSClient.java
@Test public void testExtractAdditionalProperties() throws TSClientConfigurationException, ParseException { TSClient client = new TSClient(); try {/*from w ww . j a va2 s .co m*/ client.extractAdditionalProperties(null); Assert.fail("No such file"); } catch (TSClientConfigurationException e) { // } try { client.extractAdditionalProperties(""); Assert.fail("No such file"); } catch (TSClientConfigurationException e) { // } try { client.extractAdditionalProperties(" "); Assert.fail("No such file"); } catch (TSClientConfigurationException e) { // } try { client.extractAdditionalProperties("src/test/resource/noSuchFile.properties"); Assert.fail("No such file"); } catch (TSClientConfigurationException e) { // } try { client.extractAdditionalProperties("src/test/resources/sampleTestPlan.xml"); } catch (TSClientConfigurationException e) { e.printStackTrace(); } Properties props = client.extractAdditionalProperties("src/test/resources/tsclient.properties"); Assert.assertNotNull("The result must not be null", props); Assert.assertEquals("The size of the properties set must be 9", 9, props.size()); Assert.assertEquals("The property value must be equal", "001", props.get("scenarioId")); Assert.assertEquals("The property value must be equal", "001", props.get("productId")); Assert.assertEquals("The property value must be equal", "0001", props.get("runId")); Assert.assertEquals("The property value must be equal", "999", props.get("waitTime")); Assert.assertEquals("The property value must be equal", "100", props.get("waitTimeDecrement")); Assert.assertEquals("The property value must be equal", "vhost0103", props.get("localhostName")); Assert.assertEquals("The property value must be equal", "TCO", props.get("measuringPointOutId")); Assert.assertEquals("The property value must be equal", "TCI", props.get("measuringPointInId")); Assert.assertEquals("The property value must be equal", "lzenener strae", props.get("umlautTest")); // // // String[] args = new String[]{"-addPropsFile", "file123"}; // Assert.assertEquals("The name of the file must be file123", "file123", client.extractStringValue(client.parseCommandline(options, args), TSClient.CMD_OPT_PTEST_SERVER_ADDITIONAL_PROPERTIES_FILE, TSClient.CMD_OPT_PTEST_SERVER_ADDITIONAL_PROPERTIES_FILE_SHORT)); // }
From source file:org.opennms.features.jmxconfiggenerator.Starter.java
private Map<String, String> loadExternalDictionary(String dictionaryFile) { Map<String, String> externalDictionary = new HashMap<String, String>(); Properties properties = new Properties(); try {//ww w . j a v a2 s . com BufferedInputStream stream = new BufferedInputStream(new FileInputStream(dictionaryFile)); properties.load(stream); stream.close(); } catch (FileNotFoundException ex) { logger.error("'{}'", ex.getMessage()); } catch (IOException ex) { logger.error("'{}'", ex.getMessage()); } logger.info("Loaded '{}' external dictionary entries from '{}'", properties.size(), dictionaryFile); for (final Entry<?, ?> entry : properties.entrySet()) { final Object key = entry.getKey(); final Object value = entry.getValue(); externalDictionary.put(key.toString(), value == null ? null : value.toString()); } logger.info("Dictionary entries loaded: '{}'", externalDictionary.size()); return externalDictionary; }
From source file:org.openmrs.module.diagnosiscapturerwanda.MetadataDictionary.java
private MetadataDictionary() { String gpString = Context.getAdministrationService().getGlobalProperty("diagnosisCaptureRwanda.constants"); List<String> unfoundItems = new ArrayList<String>(); if (gpString != null) { Reader reader = new StringReader(gpString); Properties props = new Properties(); try {//from ww w.j a v a 2 s. c o m props.load(reader); } catch (Exception ex) { throw new RuntimeException( "invalid values found in global property rwandahivflowsheet.constants, please correct and try again."); } finally { reader = null; } if (props.size() > 0) { for (Map.Entry<Object, Object> entry : props.entrySet()) { if (((String) entry.getKey()).contains("CONCEPT_")) setupConcept((String) entry.getKey(), ((String) entry.getValue()).trim(), unfoundItems); else if (((String) entry.getKey()).contains("ENCOUNTER_TYPE")) setupEncounterType((String) entry.getKey(), ((String) entry.getValue()).trim(), unfoundItems); else if (((String) entry.getKey()).contains("IDENTIFIER_TYPE")) setupIdentifierType((String) entry.getKey(), ((String) entry.getValue()).trim(), unfoundItems); else if (((String) entry.getKey()).contains("VISIT_TYPE_")) setupVisitType((String) entry.getKey(), ((String) entry.getValue()).trim(), unfoundItems); } for (String str : unfoundItems) log.error("ERROR: diagnosisCaptureRwanda module could not load the folowing item: " + str + ". Check the gp diagnosisCaptureRwanda.constants."); } } else throw new RuntimeException("The global property diagnosisCaptureRwanda.constants was not found."); }
From source file:org.apache.jmeter.JMeterReport.java
/** {@inheritDoc} */ @Override/*from ww w . ja v a 2s . com*/ public String[][] getIconMappings() { String iconProp = JMeterUtils.getPropDefault("jmeter.icons", "org/apache/jmeter/images/icon.properties"); Properties p = JMeterUtils.loadProperties(iconProp); if (p == null) { log.info(iconProp + " not found - using default icon set"); return DEFAULT_ICONS; } log.info("Loaded icon properties from " + iconProp); String[][] iconlist = new String[p.size()][3]; Enumeration<Object> pe = p.keys(); int i = 0; while (pe.hasMoreElements()) { String key = (String) pe.nextElement(); String icons[] = JOrphanUtils.split(p.getProperty(key), " "); iconlist[i][0] = key; iconlist[i][1] = icons[0]; if (icons.length > 1) { iconlist[i][2] = icons[1]; } i++; } return iconlist; }
From source file:org.webdavaccess.LocalFileSystemStorage.java
private void saveCustomProperties(Properties newProperties, String resourceUri) { if (newProperties == null || newProperties.size() == 0) return;//w w w. ja va 2 s .c o m resourceUri = normalize(resourceUri); File file = getPropertiesFile(resourceUri); if (file == null) return; Properties persisted = new Properties(); // Properties file exists, load it so we can add new properties if (file.exists()) { InputStream in = null; try { in = new FileInputStream(file); persisted.loadFromXML(in); } catch (Exception e) { log.warn("Failed to get properties from cache for " + resourceUri); return; } finally { if (in != null) try { in.close(); } catch (Exception e) { } } } // Add new properties with key format of: resourceUri + "|" + key Enumeration en = newProperties.keys(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); persisted.setProperty(getResourcePropertyKey(resourceUri, key), newProperties.getProperty(key)); } // Store the updates properties OutputStream os = null; try { os = new FileOutputStream(file); persisted.storeToXML(os, ""); } catch (Exception e) { log.warn("Failed to store properties for " + resourceUri); } finally { if (os != null) try { os.close(); } catch (Exception e) { } } }
From source file:org.plukh.fluffymeow.config.S3Properties.java
private Properties downloadFromS3(String bucket, String key, Properties defaultProperties) throws IOException { Properties properties = new Properties(defaultProperties); try (S3Object object = amazonS3.getObject(bucket, key)) { try (InputStream in = object.getObjectContent()) { if (log.isTraceEnabled()) log.trace("Downloading from " + bucket + ":" + key + ", size: " + object.getObjectMetadata().getInstanceLength()); properties.load(in);//from w w w. j av a2 s. co m if (log.isTraceEnabled()) log.trace("Downloaded " + properties.size() + " properties"); } } catch (AmazonS3Exception e) { if (isObjectNotFound(e)) { //Not found is ok, just means the file is not present if (log.isDebugEnabled()) log.debug("Object " + bucket + ":" + key + " not found"); } else { //Some other exception throw e; } } return properties; }
From source file:cucumber.templates.PerRepositoryTemplatesTest.java
/** * Checks whether the generated properties file is valid. * @param outputName the output name./*from ww w . j a v a 2 s .c o m*/ * @param outputFiles the output files. * @param tableNames the table names. * @param vendor the vendor. * @param grammarUtils the {@link EnglishGrammarUtils} instance. */ protected void checkPropertiesIsValid(@NotNull final String outputName, @NotNull final Map<String, File> outputFiles, @NotNull final List<String> tableNames, @NotNull final String vendor, @NotNull final EnglishGrammarUtils grammarUtils, @NotNull final StringUtils stringUtils) { checkPropertiesFiles(outputName, outputFiles); @Nullable final File file = retrieveOutputFile(outputName.concat(Literals.QUERYJ_PROPERTIES)); if (file != null) { @Nullable final Properties properties = readPropertiesFile(file); Assert.assertNotNull("Invalid properties file : " + file.getAbsolutePath(), properties); Assert.assertEquals("Invalid number of entries in " + file.getAbsolutePath(), tableNames.size(), properties.size()); for (@Nullable final String tableName : tableNames) { Assert.assertNotNull(tableName); @NotNull final String singularTableName = toSingular(tableName, grammarUtils); @NotNull final String key = getRepositoryName() + "." + singularTableName + ".dao"; Assert.assertTrue("Missing entry in " + file.getAbsolutePath(), properties.containsKey(key)); Assert.assertEquals("Invalid entry " + key + " in " + file.getAbsolutePath(), DAO_PACKAGE_NAME + ".rdb." + vendor.toLowerCase(Locale.getDefault()) + "." + vendor + capitalize(singularTableName, stringUtils) + "DAOFactory", properties.getProperty(key)); } } }
From source file:org.dspace.servicemanager.config.DSpaceConfigurationService.java
@Override public String toString() { // Get the size of the generated Properties Properties props = getProperties(); int size = props != null ? props.size() : 0; // Return the configuration directory and number of configs loaded return "ConfigDir=" + configuration.getString(DSPACE_HOME) + File.separatorChar + DEFAULT_CONFIG_DIR + ", Size=" + size; }