List of usage examples for java.util Properties size
@Override public int size()
From source file:org.sakaiproject.kernel.util.PropertiesLoader.java
/** * @param classLoader//from ww w.ja v a 2 s. c o m * @param defaultProperties * @return */ public static Properties load(ClassLoader classLoader, String defaultPropertiesLocation) { InputStream is = null; Properties properties; try { is = ResourceLoader.openResource(defaultPropertiesLocation, classLoader); properties = new Properties(); properties.load(is); LOG.info("Loaded " + properties.size() + " properties from " + defaultPropertiesLocation); } catch (IOException e) { throw new CreationException( Arrays.asList(new Message("Unable to load properties: " + defaultPropertiesLocation))); } finally { try { if (is != null) { is.close(); } } catch (IOException e) { // dont care about this. } } return properties; }
From source file:org.springframework.cloud.dataflow.rest.util.DeploymentPropertiesUtils.java
/** * Convert Properties to a Map with String keys and String values. * * @param properties the properties object * @return the equivalent {@code Map<String,String>} *//* www. ja v a 2 s. c o m*/ public static Map<String, String> convert(Properties properties) { Map<String, String> result = new HashMap<>(properties.size()); for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); result.put(key, properties.getProperty(key)); } return result; }
From source file:org.rdv.ConfigurationManager.java
/** * Inspect if the given DataPanel is detached from the DataPanelContainer * @param dataPanel to check//w ww.j a va2 s.c o m * @param properties properties for the DataPanel * @return flag indicating detached */ private static boolean isPanelDetached(DataPanel dataPanel, Properties properties) { if (properties.size() == 0) { return false; } String key, value; for (Enumeration<?> keys = properties.propertyNames(); keys.hasMoreElements();) { key = (String) keys.nextElement(); if (key == "attached") { value = properties.getProperty(key); if (value == "false") return true; } } return false; }
From source file:org.sakaiproject.kernel.util.PropertiesLoader.java
/** * @param classLoader/*from w ww. ja va 2s . c o m*/ * the classloader where the properties are to be loaded from. * @param defaultPropertiesLocation * the default location in above name where the property will come * from * @param localPropertiesName * the name of the environment varaible that stores the local * properties * @param sysPropertiesName * the name of the java system property that contains local * properties. * @return a properties set. */ public static Properties load(ClassLoader classLoader, String defaultPropertiesLocation, String localPropertiesName, String sysPropertiesName) { InputStream is = null; Properties properties; try { is = ResourceLoader.openResource(defaultPropertiesLocation, classLoader); properties = new Properties(); properties.load(is); LOG.info("Loaded " + properties.size() + " default properties from: " + defaultPropertiesLocation); } catch (IOException e) { throw new CreationException( Arrays.asList(new Message("Unable to load properties: " + defaultPropertiesLocation))); } finally { try { if (is != null) { is.close(); } } catch (IOException e) { // dont care about this. } } // load local properties if specified as a system property String localPropertiesLocation = System.getenv(localPropertiesName); String sysLocalPropertiesLocation = System.getProperty(sysPropertiesName); if (sysLocalPropertiesLocation != null) { localPropertiesLocation = sysLocalPropertiesLocation; } try { if (localPropertiesLocation != null && localPropertiesLocation.trim().length() > 0) { is = ResourceLoader.openResource(localPropertiesLocation, classLoader); Properties localProperties = new Properties(); localProperties.load(is); for (Entry<Object, Object> o : localProperties.entrySet()) { String k = o.getKey().toString(); if (k.startsWith("+")) { String p = properties.getProperty(k.substring(1)); if (p != null) { properties.put(k.substring(1), p + o.getValue()); } else { properties.put(o.getKey(), o.getValue()); } } else { properties.put(o.getKey(), o.getValue()); } } LOG.info("Loaded " + localProperties.size() + " local properties from " + localPropertiesLocation); } else { LOG.info("No Local Properties Override, set system property " + localPropertiesName + " to a resource location to override kernel properties"); } StringBuilder sb = new StringBuilder(); sb.append("Merged Property Set includes keys: "); for (Entry<?, ?> e : properties.entrySet()) { sb.append("\"").append(e.getKey()).append("\"").append("; "); } LOG.info("Loaded " + properties.size() + " properties into merged property set"); LOG.debug(sb.toString()); } catch (IOException e) { LOG.info("Failed to startup ", e); throw new CreationException( Arrays.asList(new Message("Unable to load properties: " + localPropertiesLocation))); } finally { try { if (is != null) { is.close(); } } catch (IOException e) { // dont care about this. } } return properties; }
From source file:eu.medsea.mimeutil.detector.ExtensionMimeDetector.java
private static void initMimeTypes() { InputStream is = null;//from www. j ava2s . co m extMimeTypes = new Properties(); try { // Load the file extension mappings from the internal property file and // then // from the custom property files if they can be found try { // Load the default supplied mime types is = MimeUtil.class.getClassLoader() .getResourceAsStream("eu/medsea/mimeutil/mime-types.properties"); if (is != null) { ((Properties) extMimeTypes).load(is); } } catch (Exception e) { // log the error but don't throw the exception up the stack log.error("Error loading internal mime-types.properties", e); } finally { is = closeStream(is); } // Load any .mime-types.properties from the users home directory try { File f = new File(System.getProperty("user.home") + File.separator + ".mime-types.properties"); if (f.exists()) { is = new FileInputStream(f); if (is != null) { log.debug("Found a custom .mime-types.properties file in the users home directory."); Properties props = new Properties(); props.load(is); if (props.size() > 0) { extMimeTypes.putAll(props); } log.debug("Successfully parsed .mime-types.properties from users home directory."); } } } catch (Exception e) { log.error("Failed to parse .magic.mime file from users home directory. File will be ignored.", e); } finally { is = closeStream(is); } // Load any classpath provided mime types that either extend or // override the default mime type entries. Could also be in jar files. // Get an enumeration of all files on the classpath with this name. They could be in jar files as well try { Enumeration e = MimeUtil.class.getClassLoader().getResources("mime-types.properties"); while (e.hasMoreElements()) { URL url = (URL) e.nextElement(); if (log.isDebugEnabled()) { log.debug("Found custom mime-types.properties file on the classpath [" + url + "]."); } Properties props = new Properties(); try { is = url.openStream(); if (is != null) { props.load(is); if (props.size() > 0) { extMimeTypes.putAll(props); if (log.isDebugEnabled()) { log.debug("Successfully loaded custome mime-type.properties file [" + url + "] from classpath."); } } } } catch (Exception ex) { log.error("Failed while loading custom mime-type.properties file [" + url + "] from classpath. File will be ignored."); } } } catch (Exception e) { log.error( "Problem while processing mime-types.properties files(s) from classpath. Files will be ignored.", e); } finally { is = closeStream(is); } try { // Load any mime extension mappings file defined with the JVM // property -Dmime-mappings=../my/custom/mappings.properties String fname = System.getProperty("mime-mappings"); if (fname != null && fname.length() != 0) { is = new FileInputStream(fname); if (is != null) { if (log.isDebugEnabled()) { log.debug( "Found a custom mime-mappings property defined by the property -Dmime-mappings [" + System.getProperty("mime-mappings") + "]."); } Properties props = new Properties(); props.load(is); if (props.size() > 0) { extMimeTypes.putAll(props); } log.debug("Successfully loaded the mime mappings file from property -Dmime-mappings [" + System.getProperty("mime-mappings") + "]."); } } } catch (Exception ex) { log.error("Failed to load the mime-mappings file defined by the property -Dmime-mappings [" + System.getProperty("mime-mappings") + "]."); } finally { is = closeStream(is); } } finally { // Load the mime types into the known mime types map of MimeUtil Iterator it = extMimeTypes.values().iterator(); while (it.hasNext()) { String[] types = ((String) it.next()).split(","); for (int i = 0; i < types.length; i++) { MimeUtil.addKnownMimeType(types[i]); } } } }
From source file:org.esgf.web.FacetFileController.java
/** * New helper method for extracting facet info from the facets.properties file in /esg/config * /* www .ja v a 2 s . com*/ * @return */ private static String[] getFacetInfo() { String[] facetTokens = null; Properties properties = new Properties(); String propertiesFile = FACET_PROPERTIES_FILE; boolean createDefault = false; try { properties.load(new FileInputStream(propertiesFile)); facetTokens = new String[properties.size()]; for (Object key : properties.keySet()) { String value = (String) properties.get(key); String[] valueTokens = value.split(":"); try { int index = Integer.parseInt(valueTokens[0]); if (index > -1) { if (index < properties.size()) { String facetInfo = (String) key + ":" + valueTokens[1] + ":" + valueTokens[2]; facetTokens[index] = facetInfo; } } } //Note: need to fix this. This will only work if ALL facet readings are wrong catch (Exception e) { System.out.println("COULD NOT INDEX: " + key); createDefault = true; } } List<String> fixedFacetTokens = new ArrayList<String>(); //"fix" the array here (for any index collisions for (int i = 0; i < facetTokens.length; i++) { if (facetTokens[i] != null) { fixedFacetTokens.add(facetTokens[i]); } } facetTokens = (String[]) fixedFacetTokens.toArray(new String[fixedFacetTokens.size()]); } catch (FileNotFoundException f) { System.out.println("Using default facet list"); facetTokens = getDefaultFacets(); } catch (Exception e) { e.printStackTrace(); } if (createDefault) { System.out.println("Using default facet list"); facetTokens = getDefaultFacets(); } return facetTokens; }
From source file:org.apache.sqoop.connector.jdbc.oracle.util.OracleConnectionFactory.java
private static Connection createConnection(String jdbcUrl, String username, String password, Properties additionalProps) throws SQLException { Properties props = new Properties(); if (username != null) { props.put("user", username); }//from ww w .j a va 2s . co m if (password != null) { props.put("password", password); } if (additionalProps != null && additionalProps.size() > 0) { props.putAll(additionalProps); } OracleUtilities.checkJavaSecurityEgd(); try { Connection result = DriverManager.getConnection(jdbcUrl, props); result.setAutoCommit(false); return result; } catch (SQLException ex) { String errorMsg = String.format("Unable to obtain a JDBC connection to the URL \"%s\" as user \"%s\": ", jdbcUrl, (username != null) ? username : "[null]"); LOG.error(errorMsg, ex); throw ex; } }
From source file:com.savy3.util.DBConfiguration.java
/** * Converts connection properties to a String to be passed to the mappers. * @param properties JDBC connection parameters * @return String to be passed to configuration *//*www .j a va 2 s . com*/ protected static String propertiesToString(Properties properties) { List<String> propertiesList = new ArrayList<String>(properties.size()); for (Entry<Object, Object> property : properties.entrySet()) { String key = StringEscapeUtils.escapeCsv(property.getKey().toString()); if (key.equals(property.getKey().toString()) && key.contains("=")) { key = "\"" + key + "\""; } String val = StringEscapeUtils.escapeCsv(property.getValue().toString()); if (val.equals(property.getValue().toString()) && val.contains("=")) { val = "\"" + val + "\""; } propertiesList.add(StringEscapeUtils.escapeCsv(key + "=" + val)); } return StringUtils.join(propertiesList, ','); }
From source file:org.openecomp.sdnc.sli.aai.AAIRequest.java
public static void setProperties(Properties props, AAIService aaiService) { AAIRequest.configProperties = props; AAIRequest.aaiService = aaiService;// ww w .j a va 2 s. com try { URL url = null; Bundle bundle = FrameworkUtil.getBundle(AAIServiceActivator.class); if (bundle != null) { BundleContext ctx = bundle.getBundleContext(); if (ctx == null) return; url = ctx.getBundle().getResource(AAIService.PATH_PROPERTIES); } else { url = aaiService.getClass().getResource("/aai-path.properties"); } InputStream in = url.openStream(); Reader reader = new InputStreamReader(in, "UTF-8"); Properties properties = new Properties(); properties.load(reader); LOG.info("loaded " + properties.size()); Set<String> keys = properties.stringPropertyNames(); int index = 0; Set<String> resourceNames = new TreeSet<String>(); for (String key : keys) { String[] tags = key.split("\\|"); for (String tag : tags) { if (!resourceNames.contains(tag)) { resourceNames.add(tag); tagValues.put(tag, Integer.toString(++index)); } } BitSet bs = new BitSet(256); for (String tag : tags) { String value = tagValues.get(tag); Integer bitIndex = Integer.parseInt(value); bs.set(bitIndex); } String path = properties.getProperty(key); LOG.info(String.format("bitset %s\t\t%s", bs.toString(), path)); bitsetPaths.put(bs, path); } LOG.info("loaded " + resourceNames.toString()); } catch (Exception e) { LOG.error("Caught exception", e); } }
From source file:org.opennms.tools.jmxconfiggenerator.helper.NameTools.java
public static void loadExtermalDictionary(String dictionaryFile) { Properties properties = new Properties(); try {/* w ww . ja va2 s .c o 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()) { dictionary.put(key.toString(), properties.get(key).toString()); } logger.info("Dictionary entries loaded: '{}'", dictionary.size()); }