List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:com.liferay.ide.server.util.ServerUtil.java
public static Properties getAllCategories(IPath portalDir) { Properties retval = null;//from w w w. j av a 2s .co m File implJar = portalDir.append("WEB-INF/lib/portal-impl.jar").toFile(); //$NON-NLS-1$ if (implJar.exists()) { try { JarFile jar = new JarFile(implJar); Properties categories = new Properties(); Properties props = new Properties(); props.load(jar.getInputStream(jar.getEntry("content/Language.properties"))); //$NON-NLS-1$ Enumeration<?> names = props.propertyNames(); while (names.hasMoreElements()) { String name = names.nextElement().toString(); if (name.startsWith("category.")) //$NON-NLS-1$ { categories.put(name, props.getProperty(name)); } } retval = categories; jar.close(); } catch (IOException e) { LiferayServerCore.logError(e); } } return retval; }
From source file:Manifest.java
/** * This method verifies the digital signature of the named manifest file, if * it has one, and if that verification succeeds, it verifies the message * digest of each file in filelist that is also named in the manifest. This * method can throw a bunch of exceptions *///from ww w. java 2s. com public static void verify(String manifestfile, KeyStore keystore) throws NoSuchAlgorithmException, SignatureException, InvalidKeyException, KeyStoreException, IOException { Properties manifest = new Properties(); manifest.load(new FileInputStream(manifestfile)); String digestAlgorithm = manifest.getProperty("__META.DIGESTALGORITHM"); String signername = manifest.getProperty("__META.SIGNER"); String signatureAlgorithm = manifest.getProperty("__META.SIGNATUREALGORITHM"); String hexsignature = manifest.getProperty("__META.SIGNATURE"); // Get a list of filenames in the manifest. List files = new ArrayList(); Enumeration names = manifest.propertyNames(); while (names.hasMoreElements()) { String s = (String) names.nextElement(); if (!s.startsWith("__META")) files.add(s); } int numfiles = files.size(); // If we've got a signature but no keystore, warn the user if (signername != null && keystore == null) System.out.println("Can't verify digital signature without " + "a keystore."); // If the manifest contained metadata about a digital signature, then // verify that signature first if (signername != null && keystore != null) { System.out.print("Verifying digital signature..."); System.out.flush(); // To verify the signature, we must process the files in exactly // the same order we did when we created the signature. We // guarantee this order by sorting the filenames. Collections.sort(files); // Create a Signature object to do signature verification with. // Initialize it with the signer's public key from the keystore Signature signature = Signature.getInstance(signatureAlgorithm); PublicKey publickey = keystore.getCertificate(signername).getPublicKey(); signature.initVerify(publickey); // Now loop through these files in their known sorted order For // each one, send the bytes of the filename and of the digest to // the signature object for use in computing the signature. It is // important that this be done in exactly the same order when // verifying the signature as it was done when creating the // signature. for (int i = 0; i < numfiles; i++) { String filename = (String) files.get(i); signature.update(filename.getBytes()); signature.update(hexDecode(manifest.getProperty(filename))); } // Now decode the signature read from the manifest file and pass // it to the verify() method of the signature object. If the // signature is not verified, print an error message and exit. if (!signature.verify(hexDecode(hexsignature))) { System.out.println("\nManifest has an invalid signature"); System.exit(0); } // Tell the user we're done with this lengthy computation System.out.println("verified."); } // Tell the user we're starting the next phase of verification System.out.print("Verifying file message digests"); System.out.flush(); // Get a MessageDigest object to compute digests MessageDigest md = MessageDigest.getInstance(digestAlgorithm); // Loop through all files for (int i = 0; i < numfiles; i++) { String filename = (String) files.get(i); // Look up the encoded digest from the manifest file String hexdigest = manifest.getProperty(filename); // Compute the digest for the file. byte[] digest; try { digest = getFileDigest(filename, md); } catch (IOException e) { System.out.println("\nSkipping " + filename + ": " + e); continue; } // Encode the computed digest and compare it to the encoded digest // from the manifest. If they are not equal, print an error // message. if (!hexdigest.equals(hexEncode(digest))) System.out.println("\nFile '" + filename + "' failed verification."); // Send one dot of output for each file we process. Since // computing message digests takes some time, this lets the user // know that the program is functioning and making progress System.out.print("."); System.out.flush(); } // And tell the user we're done with verification. System.out.println("done."); }
From source file:org.lnicholls.galleon.gui.Galleon.java
private static void printSystemProperties() { Properties properties = System.getProperties(); Enumeration Enumeration = properties.propertyNames(); for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) { String propertyName = (String) e.nextElement(); log.info(propertyName + "=" + System.getProperty(propertyName)); }// w w w . j a v a 2 s . c o m Runtime runtime = Runtime.getRuntime(); log.info("Max Memory: " + runtime.maxMemory()); log.info("Total Memory: " + runtime.totalMemory()); log.info("Free Memory: " + runtime.freeMemory()); }
From source file:org.intermine.web.logic.config.WebConfig.java
/** * Get all the files configured in a properties file with a certain prefix. * @param prefix The prefix to use to get the list of values. *///from w w w .ja v a 2 s .c o m private static List<String> getMappingFileNames(final Properties props, final String prefix) { final List<String> returnVal = new ArrayList<String>(); for (@SuppressWarnings("rawtypes") final Enumeration e = props.propertyNames(); e.hasMoreElements();) { final String key = (String) e.nextElement(); if (key.startsWith(prefix)) { returnVal.add(props.getProperty(key)); } } return returnVal; }
From source file:org.intermine.bio.util.OrganismRepository.java
/** * Return an OrganismRepository created from a properties file in the class path. * @return the OrganismRepository//from ww w . j av a 2 s . c om */ @SuppressWarnings("unchecked") public static OrganismRepository getOrganismRepository() { if (or == null) { Properties props = new Properties(); try { InputStream propsResource = OrganismRepository.class.getClassLoader() .getResourceAsStream(PROP_FILE); if (propsResource == null) { throw new RuntimeException("can't find " + PROP_FILE + " in class path"); } props.load(propsResource); } catch (IOException e) { throw new RuntimeException("Problem loading properties '" + PROP_FILE + "'", e); } or = new OrganismRepository(); Enumeration<String> propNames = (Enumeration<String>) props.propertyNames(); Pattern pattern = Pattern.compile(REGULAR_EXPRESSION); while (propNames.hasMoreElements()) { String name = propNames.nextElement(); if (name.startsWith(PREFIX)) { Matcher matcher = pattern.matcher(name); if (matcher.matches()) { String taxonIdString = matcher.group(1); int taxonId = Integer.valueOf(taxonIdString).intValue(); String fieldName = matcher.group(2); OrganismData od = or.getOrganismDataByTaxonInternal(taxonId); final String attributeValue = props.getProperty(name); if (fieldName.equals(ABBREVIATION)) { od.setAbbreviation(attributeValue); or.abbreviationMap.put(attributeValue.toLowerCase(), od); } else if (fieldName.equals(STRAINS)) { String[] strains = attributeValue.split(" "); for (String strain : strains) { try { or.strains.put(Integer.valueOf(strain), od); or.organismsWithStrains.put(taxonIdString, strain); } catch (NumberFormatException e) { throw new NumberFormatException("taxon ID must be a number"); } } } else if (fieldName.equals(ENSEMBL)) { od.setEnsemblPrefix(attributeValue); } else if (fieldName.equals(UNIPROT)) { od.setUniprot(attributeValue); uniprotToTaxon.put(attributeValue, od); } else { if (fieldName.equals(SPECIES)) { od.setSpecies(attributeValue); } else { if (fieldName.equals(GENUS)) { od.setGenus(attributeValue); } else { throw new RuntimeException("internal error didn't match: " + fieldName); } } } } else { throw new RuntimeException("unable to parse organism property key: " + name); } } else { throw new RuntimeException("properties in " + PROP_FILE + " must start with " + PREFIX + "."); } } for (OrganismData od : or.taxonMap.values()) { or.genusSpeciesMap.put(new MultiKey(od.getGenus(), od.getSpecies()), od); // we have some organisms from uniprot that don't have a short name if (od.getShortName() != null) { or.shortNameMap.put(od.getShortName(), od); } } } return or; }
From source file:gov.jgi.meta.MetaUtils.java
/** * same as {@link #loadConfiguration(Configuration, String[]) loadConfiguration()} but loads from * a specified file instead of the default filename. * * @param conf the job configuration to add the defaults to * @param configurationFileName the cluster defaults file to load * @param args the commandline args/*ww w. j av a2 s . co m*/ * @return modifies conf * @throws IOException */ public static String[] loadConfiguration(Configuration conf, String configurationFileName, String[] args) throws IOException { /* * first load the configuration from the build properties (typically packaged in the jar) */ System.out.println("loading build.properties ..."); try { Properties buildProperties = new Properties(); buildProperties.load(MetaUtils.class.getResourceAsStream("/build.properties")); for (Enumeration e = buildProperties.propertyNames(); e.hasMoreElements();) { String k = (String) e.nextElement(); System.out.println("setting " + k + " to " + buildProperties.getProperty(k)); System.setProperty(k, buildProperties.getProperty(k)); conf.set(k, buildProperties.getProperty(k)); } } catch (Exception e) { System.out.println("unable to find build.properties ... skipping"); } /* * override properties with the deployment descriptor */ if (configurationFileName == null) { String appName = System.getProperty("application.name"); String appVersion = System.getProperty("application.version"); configurationFileName = appName + "-" + appVersion + "-conf.xml"; } System.out.println("loading application configuration from " + configurationFileName); try { URL u = ClassLoader.getSystemResource(configurationFileName); if (u == null) { System.err.println("unable to find " + configurationFileName + " ... skipping"); } else { conf.addResource(configurationFileName); } } catch (Exception e) { System.err.println("unable to find " + configurationFileName + " ... skipping"); } /* * override properties from user's preferences defined in ~/.meta-prefs */ try { java.io.FileInputStream fis = new java.io.FileInputStream( new java.io.File(System.getenv("HOME") + "/.meta-prefs")); Properties props = new Properties(); props.load(fis); System.out.println("loading preferences from ~/.meta-prefs"); for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { String k = (String) e.nextElement(); System.out.println("overriding property: " + k); conf.set(k, props.getProperty(k)); } } catch (Exception e) { System.out.println("unable to find ~/.meta-prefs ... skipping"); } /* * finally, allow user to override from commandline */ return (new GenericOptionsParser(conf, args).getRemainingArgs()); }
From source file:org.wisdom.maven.utils.BundlePackager.java
private static boolean readInstructionsFromBndFiles(Properties properties, File basedir) throws IOException { Properties props = new Properties(); File instructionFile = new File(basedir, INSTRUCTIONS_FILE); if (instructionFile.isFile()) { InputStream is = null;//w ww. j av a 2 s. com try { is = new FileInputStream(instructionFile); props.load(is); } finally { IOUtils.closeQuietly(is); } } else { return false; } // Insert in the given properties to the list of properties. @SuppressWarnings("unchecked") Enumeration<String> names = (Enumeration<String>) props.propertyNames(); while (names.hasMoreElements()) { String key = names.nextElement(); properties.put(key, props.getProperty(key)); } return true; }
From source file:lucee.runtime.net.smtp.SMTPClient.java
private static String hash(Properties props) { Enumeration<?> e = props.propertyNames(); java.util.List<String> names = new ArrayList<String>(); String str;//from w w w . j a va 2s. co m while (e.hasMoreElements()) { str = Caster.toString(e.nextElement(), null); if (!StringUtil.isEmpty(str) && str.startsWith("mail.smtp.")) names.add(str); } Collections.sort(names); StringBuilder sb = new StringBuilder(); Iterator<String> it = names.iterator(); while (it.hasNext()) { str = it.next(); sb.append(str).append(':').append(props.getProperty(str)).append(';'); } str = sb.toString(); return MD5.getDigestAsString(str, str); }
From source file:org.apache.hadoop.mapred.UtilsForTests.java
static void setUpConfigFile(Properties confProps, File configFile) throws IOException { Configuration config = new Configuration(false); FileOutputStream fos = new FileOutputStream(configFile); for (Enumeration<?> e = confProps.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); config.set(key, confProps.getProperty(key)); }/*from w w w.j av a 2 s .co m*/ config.writeXml(fos); fos.close(); }
From source file:org.onecmdb.core.internal.storage.DataSourceWrapper.java
synchronized public void setConnectionProperties(final Properties props) { for (Enumeration<?> names = props.propertyNames(); names.hasMoreElements();) { String name = (String) names.nextElement(); String value = props.getProperty(name); super.addConnectionProperty(name, value); }/*from w w w .j a va2 s. com*/ }