List of usage examples for java.util Properties size
@Override public int size()
From source file:org.accada.reader.hal.ControllerProperties.java
/** * Gets the names of the configurable parameters. * //from w ww . ja v a 2s. com * @return The parameter names. * * @throws Exception */ public String[] getParameterNames() throws Exception { String[] names = null; InputStream in; Properties props = new Properties(); log.debug("Trying to get Parameters"); //possible Errors are propageted and further processed as HardwareExceptions in = this.getClass().getResourceAsStream("/props/" + propsFile); //possible Errors are propageted and further processed as HardwareExceptions props.load(in); in.close(); Enumeration propNames = props.propertyNames(); names = new String[props.size()]; int i = 0; while (propNames.hasMoreElements()) { names[i] = (String) propNames.nextElement(); i++; } return names; }
From source file:fr.landel.utils.commons.StringUtils.java
/** * Injects all arguments in the specified char sequence. The arguments are * injected by replacement of keys between braces. To exclude keys, just * double braces (like {{key}} will return {key}). If some keys aren't * found, they are ignored./* www .jav a2 s . c o m*/ * * <p> * precondition: {@code charSequence} cannot be {@code null} * </p> * * <pre> * Properties properties = new Properties(); * properties.setProperty("where", "beach"); * properties.setProperty("when", "afternoon"); * * StringUtils.injectKeys(Pair.of("${", "}"), Pair.of("${{", "}}"), "", properties); * // => "" * * StringUtils.injectKeys(Pair.of("${", "}"), Pair.of("${{", "}}"), "I'll go to the ${where} this ${when}", properties); * // => "I'll go to the beach this afternoon" * * StringUtils.injectKeys(Pair.of("${", "}"), Pair.of("${{", "}}"), "I'll go to ${where}${{where}}${where}", properties); * // => "I'll go to beach${where}beach" * </pre> * * @param include * the characters that surround the property key to replace * @param exclude * the characters that surround the property key to exclude of * replacement * @param charSequence * the input char sequence * @param properties * the properties to inject * @return the result with replacements */ public static String injectKeys(final Pair<String, String> include, final Pair<String, String> exclude, final CharSequence charSequence, final Properties properties) { if (charSequence == null) { throw new IllegalArgumentException("The input char sequence cannot be null"); } else if (isEmpty(charSequence) || properties == null || properties.isEmpty()) { return charSequence.toString(); } return injectKeys(include, exclude, charSequence, properties.entrySet().toArray(CastUtils.cast(new Map.Entry[properties.size()]))); }
From source file:org.apache.geode.internal.util.CollectionUtilsJUnitTest.java
@Test public void testCreateMultipleProperties() { Map<String, String> map = new HashMap<>(3); map.put("one", "A"); map.put("two", "B"); map.put("six", "C"); Properties properties = CollectionUtils.createProperties(map); assertNotNull(properties);/*w ww. j a v a 2 s . c om*/ assertFalse(properties.isEmpty()); assertEquals(map.size(), properties.size()); for (Entry<String, String> entry : map.entrySet()) { assertTrue(properties.containsKey(entry.getKey())); assertEquals(entry.getValue(), properties.get(entry.getKey())); } }
From source file:org.opennms.jmxconfiggenerator.Starter.java
private Map<String, String> loadExtermalDictionary(String dictionaryFile) { Map<String, String> externalDictionary = new HashMap<String, String>(); Properties properties = new Properties(); try {//from ww w . j av a2 s . co m 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 entiers from '{}'", properties.size(), dictionaryFile); for (Object key : properties.keySet()) { externalDictionary.put(key.toString(), properties.get(key).toString()); } logger.info("Dictionary entries loaded: '{}'", externalDictionary.size()); return externalDictionary; }
From source file:org.apache.falcon.workflow.engine.FalconWorkflowEngine.java
private InstancesResult.Instance performAction(String cluster, Entity entity, JobAction action, ExecutionInstance instance) throws FalconException { EntityExecutor executor = EXECUTION_SERVICE.getEntityExecutor(entity, cluster); InstancesResult.Instance instanceInfo = null; LOG.debug("Retrieving information for {} for action {}", instance.getId(), action); if (StringUtils.isNotEmpty(instance.getExternalID())) { instanceInfo = DAGEngineFactory.getDAGEngine(cluster).info(instance.getExternalID()); } else {//w w w.ja v a2 s . c o m instanceInfo = new InstancesResult.Instance(); } switch (action) { case KILL: executor.kill(instance); instanceInfo.status = InstancesResult.WorkflowStatus.KILLED; break; case SUSPEND: executor.suspend(instance); instanceInfo.status = InstancesResult.WorkflowStatus.SUSPENDED; break; case RESUME: executor.resume(instance); instanceInfo.status = InstancesResult.WorkflowStatus .valueOf(STATE_STORE.getExecutionInstance(instance.getId()).getCurrentState().name()); break; case RERUN: break; case STATUS: if (StringUtils.isNotEmpty(instance.getExternalID())) { List<InstancesResult.InstanceAction> instanceActions = DAGEngineFactory.getDAGEngine(cluster) .getJobDetails(instance.getExternalID()); instanceInfo.actions = instanceActions .toArray(new InstancesResult.InstanceAction[instanceActions.size()]); } break; case PARAMS: // Mask details, log instanceInfo.details = null; instanceInfo.logFile = null; Properties props = DAGEngineFactory.getDAGEngine(cluster).getConfiguration(instance.getExternalID()); InstancesResult.KeyValuePair[] keyValuePairs = new InstancesResult.KeyValuePair[props.size()]; int i = 0; for (String name : props.stringPropertyNames()) { keyValuePairs[i++] = new InstancesResult.KeyValuePair(name, props.getProperty(name)); } break; default: throw new IllegalArgumentException("Unhandled action " + action); } return instanceInfo; }
From source file:org.webdavaccess.LocalFileSystemStorage.java
public void removeCustomProperties(String resourceUri, Properties properties) { if (properties == null || properties.size() == 0) return;/*from w ww . j a v a 2 s .co m*/ deleteProperties(resourceUri, properties); }
From source file:com.opengamma.transport.TaxonomyGatheringFudgeMessageSenderTest.java
@Test(timeOut = 10000) public void taxonomyGathering() throws IOException, InterruptedException { File tmpFile = File.createTempFile("TaxonomyGatheringFudgeMessageSenderTest_taxonomyGathering", ".properties"); FileUtils.forceDelete(tmpFile);// w w w . ja va 2 s. com FileUtils.forceDeleteOnExit(tmpFile); FudgeContext context = new FudgeContext(); CollectingFudgeMessageReceiver collectingReceiver = new CollectingFudgeMessageReceiver(); ByteArrayFudgeMessageReceiver fudgeReceiver = new ByteArrayFudgeMessageReceiver(collectingReceiver); DirectInvocationByteArrayMessageSender byteArraySender = new DirectInvocationByteArrayMessageSender( fudgeReceiver); ByteArrayFudgeMessageSender fudgeSender = new ByteArrayFudgeMessageSender(byteArraySender, context); TaxonomyGatheringFudgeMessageSender gatheringSender = new TaxonomyGatheringFudgeMessageSender(fudgeSender, tmpFile.getAbsolutePath(), context, 1000L); MutableFudgeMsg msg1 = context.newMessage(); msg1.add("name1", 1); msg1.add("name2", 1); msg1.add("name3", 1); msg1.add("name1", 1); MutableFudgeMsg msg2 = context.newMessage(); msg1.add("name4", msg2); msg2.add(14, 1); msg2.add("name5", "foo"); gatheringSender.send(msg1); assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name1")); assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name2")); assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name3")); assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name4")); assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name5")); assertEquals(5, gatheringSender.getCurrentTaxonomy().size()); Properties props = new Properties(); gatheringSender.waitForNextWrite(); InputStream is = new FileInputStream(tmpFile); props.load(new BufferedInputStream(is)); is.close(); for (Map.Entry<Object, Object> propEntry : props.entrySet()) { Integer ordinal = gatheringSender.getCurrentTaxonomy().get(propEntry.getValue()); assertEquals(ordinal.intValue(), Integer.parseInt((String) propEntry.getKey())); } assertEquals(5, props.size()); }
From source file:org.opennms.jmxconfiggenerator.Starter.java
private Map<String, String> loadInternalDictionary() { Map<String, String> internalDictionary = new HashMap<String, String>(); Properties properties = new Properties(); try {//from w ww .ja v a 2 s. c om BufferedInputStream stream = new BufferedInputStream( Starter.class.getClassLoader().getResourceAsStream("dictionary.properties")); properties.load(stream); stream.close(); } catch (IOException ex) { logger.error("Load dictionary entires from internal properties files error: '{}'", ex.getMessage()); } logger.info("Loaded '{}' internal dictionary entiers", properties.size()); for (Object key : properties.keySet()) { internalDictionary.put(key.toString(), properties.get(key).toString()); } logger.info("Dictionary entries loaded: '{}'", internalDictionary.size()); return internalDictionary; }
From source file:hudson.UtilTest.java
@Test public void loadProperties() throws IOException { assertEquals(0, Util.loadProperties("").size()); Properties p = Util.loadProperties("k.e.y=va.l.ue"); assertEquals(p.toString(), "va.l.ue", p.get("k.e.y")); assertEquals(p.toString(), 1, p.size()); }
From source file:com.sfwl.framework.web.casclient.AbstractTicketValidationFilter.java
/** * Gets the ssl config to use for HTTPS connections * if one is configured for this filter. * @param filterConfig Servlet filter configuration. * @return Properties that can contains key/trust info for Client Side Certificates *///from w w w . j av a 2s .co m protected Properties getSSLConfig(final FilterConfig filterConfig) { final Properties properties = new Properties(); final String fileName = getPropertyFromInitParams(filterConfig, "sslConfigFile", null); if (fileName != null) { FileInputStream fis = null; try { fis = new FileInputStream(fileName); properties.load(fis); logger.trace("Loaded {} entries from {}", properties.size(), fileName); } catch (final IOException ioe) { logger.error(ioe.getMessage(), ioe); } finally { CommonUtils.closeQuietly(fis); } } return properties; }