List of usage examples for java.util Properties getProperty
public String getProperty(String key)
From source file:de.tudarmstadt.ukp.dkpro.core.api.lexmorph.TagsetMappingFactory.java
public static Map<String, String> loadProperties(URL aUrl) { InputStream is = null;//w w w.j a va 2s.co m try { is = aUrl.openStream(); Properties mappingProperties = new Properties(); mappingProperties.load(is); Map<String, String> mapping = new HashMap<String, String>(); for (String key : mappingProperties.stringPropertyNames()) { mapping.put(key.trim(), mappingProperties.getProperty(key).trim()); } return mapping; } catch (IOException e) { throw new RuntimeException(e); } finally { closeQuietly(is); } }
From source file:de.pawlidi.openaletheia.utils.PropertiesUtils.java
public static Long getLongProperty(Properties properties, final String key) { if (PropertiesUtils.isEmpty(properties) || StringUtils.isBlank(key)) { return null; }/*from w w w . ja v a 2s .c om*/ final String property = properties.getProperty(key); if (property == null) { return null; } try { return Long.valueOf(property); } catch (NumberFormatException e) { return null; } }
From source file:edu.ku.brc.util.XMLChecksumUtil.java
/** * Returns whether the checksum in the file matched the checksum of the file. * @param checksumProps the mapping of files to their checksum * @param file the File object to be checked * @return true if check sum matches, false if not. *///from w w w . j ava 2 s . co m protected static boolean checkSignature(final Properties checksumProps, final File file) throws IOException { String relativeName = getRelativeName(file); if (StringUtils.isNotEmpty(relativeName)) { String checksumStr = checksumProps.getProperty(relativeName); if (StringUtils.isNotEmpty(checksumStr)) { long checkSum = checksumCRC32(file); long newCheckSum = Long.parseLong(checksumStr); //System.out.println(file.getName()+" ["+checkSum+"]["+newCheckSum+"]"); return checkSum == newCheckSum; } } else { throw new RuntimeException("The file isn't in the config directory [" + file.getAbsolutePath() + "]"); } return false; }
From source file:games.strategy.engine.random.PropertiesDiceRoller.java
/** * Loads the property dice rollers from the properties file * // www .j a va 2 s . c o m * @return the collection of available dice rollers */ public static Collection<PropertiesDiceRoller> loadFromFile() { final List<PropertiesDiceRoller> rollers = new ArrayList<PropertiesDiceRoller>(); final File f = new File(GameRunner2.getRootFolder(), "dice_servers"); if (!f.exists()) { throw new IllegalStateException("No dice server folder:" + f); } final java.util.List<Properties> propFiles = new ArrayList<Properties>(); final File[] files = f.listFiles(); for (final File file : files) { if (!file.isDirectory() && file.getName().endsWith(".properties")) { try { final Properties props = new Properties(); final FileInputStream fin = new FileInputStream(file); try { props.load(fin); propFiles.add(props); } finally { fin.close(); } } catch (final IOException e) { System.out.println("error reading file:" + file); e.printStackTrace(); } } } Collections.sort(propFiles, new Comparator<Properties>() { public int compare(final Properties o1, final Properties o2) { final int n1 = Integer.parseInt(o1.getProperty("order")); final int n2 = Integer.parseInt(o2.getProperty("order")); return n1 - n2; } }); for (final Properties prop : propFiles) { rollers.add(new PropertiesDiceRoller(prop)); } return rollers; }
From source file:ca.sparkera.adapters.mainframe.CobolSerdeUtils.java
/** * Determine the layout to that's been provided for cobol serde work. * /*from www . ja v a 2s .c om*/ * @param properties * containing a key pointing to the layout, one way or another * @return layout to use while serdeing the avro file * @throws IOException * if error while trying to read the layout from another * location * @throws CobolSerdeException * if unable to find a layout or pointer to it in the properties */ public static String determineLayoutOrThrowException(Configuration conf, Properties properties) throws IOException, CobolSerdeException { //For fixed length record get length of the file String fixedRecordLength = properties.getProperty(CobolTableProperties.FB_LENGTH.getPropName()); if (fixedRecordLength != null) { conf.setInt(FixedLengthInputFormat.FIXED_RECORD_LENGTH, Integer.parseInt(fixedRecordLength)); } String layoutString = properties.getProperty(CobolTableProperties.LAYOUT_LITERAL.getPropName()); if (layoutString != null && !layoutString.equals(LAYOUT_NONE)) return CobolSerdeUtils.getLayoutFor(layoutString); //For testing purpose layoutString = properties.getProperty(CobolTableProperties.LAYOUT_TEST.getPropName()); if (layoutString != null) { return readFile(layoutString, Charset.defaultCharset()); } // Try pulling directly from URL layoutString = properties.getProperty(CobolTableProperties.LAYOUT_URL.getPropName()); if (layoutString == null || layoutString.equals(LAYOUT_NONE)) throw new CobolSerdeException(EXCEPTION_MESSAGE); try { String s = getLayoutFromFS(layoutString, conf); if (s == null) { // in case layout is not a file system return CobolSerdeUtils.getLayoutFor(new URL(layoutString).openStream()); } return s; } catch (IOException ioe) { throw new CobolSerdeException("Unable to read layout from given path: " + layoutString, ioe); } catch (URISyntaxException urie) { throw new CobolSerdeException("Unable to read layout from given path: " + layoutString, urie); } }
From source file:gdt.data.entity.BaseHandler.java
/** * Execute an action//from w ww .j a v a 2 s . c om * @param entigrator instance of the Entigrator class * @param locator$ the arguments string. * @return response string. */ public static String execute(Entigrator entigrator, String locator$) { try { Properties locator = Locator.toProperties(locator$); String handlerClass$ = locator.getProperty(HANDLER_CLASS); String method$ = locator.getProperty(HANDLER_METHOD); Class<?> cls = Class.forName(handlerClass$); Object obj = cls.newInstance(); // System.out.println("ConsoleHandler:execute:context="+handlerClass$); Method method = cls.getDeclaredMethod(method$, Entigrator.class, String.class); return (String) method.invoke(obj, entigrator, locator$); } catch (Exception e) { Logger.getLogger(BaseHandler.class.getName()).severe(e.toString()); return Locator.append(locator$, FacetHandler.METHOD_STATUS, FacetHandler.METHOD_STATUS_FAILED); } }
From source file:com.bluexml.tools.miscellaneous.Translate.java
protected static TreeMap<String, String> loadProperties(File input) throws FileNotFoundException, IOException { TreeMap<String, String> map = new TreeMap<String, String>(); Properties props = new Properties(); FileInputStream fin = new FileInputStream(input); props.load(fin);// w ww .j a va 2s .com Enumeration<Object> keys = props.keys(); while (keys.hasMoreElements()) { String nextElement = (String) keys.nextElement(); String property = props.getProperty(nextElement); map.put(nextElement, property); } return map; }
From source file:com.griddynamics.jagger.JaggerLauncher.java
public static ApplicationContext loadContext(URL directory, String role, Properties environmentProperties) { String[] includePatterns = StringUtils.split(environmentProperties.getProperty(role + INCLUDE_SUFFIX), ", "); String[] excludePatterns = StringUtils.split(environmentProperties.getProperty(role + EXCLUDE_SUFFIX), ", "); List<String> descriptors = discoverResources(directory, includePatterns, excludePatterns); log.info("Discovered descriptors:"); for (String descriptor : descriptors) { log.info(" " + descriptor); }/* w w w . j a va 2 s . c o m*/ return new JaggerXmlApplicationContext(directory, environmentProperties, descriptors.toArray(new String[descriptors.size()])); }
From source file:com.alibaba.napoli.metamorphosis.utils.DiamondUtils.java
/** * ?zk??NPE/* ww w . ja v a 2s . co m*/ * * @param diamondManager * @param timeout * @return */ // public static ZKConfig getZkConfig(final DiamondManager diamondManager, // final long timeout) { // final Properties props = // diamondManager.getAvailablePropertiesConfigureInfomation(timeout); // if (props != null) { // log.info("diamondzk?" + props); // return getZkConfig(props); // } // return null; // } public static ZKConfig getZkConfig(final Properties props) { if (props != null) { boolean zkEnable = true; if (!com.alibaba.napoli.gecko.core.util.StringUtils.isBlank(props.getProperty("zk.zkEnable"))) { zkEnable = Boolean.valueOf(props.getProperty("zk.zkEnable")); } String zkRoot = "/meta"; if (!com.alibaba.napoli.gecko.core.util.StringUtils.isBlank(props.getProperty("zk.zkRoot"))) { zkRoot = props.getProperty("zk.zkRoot"); } final ZKConfig rt = new ZKConfig(zkRoot, props.getProperty("zk.zkConnect"), Integer.parseInt(props.getProperty("zk.zkSessionTimeoutMs")), Integer.parseInt(props.getProperty("zk.zkConnectionTimeoutMs")), Integer.parseInt(props.getProperty("zk.zkSyncTimeMs")), zkEnable); return rt; } else { throw new NullPointerException("Null zk config"); } }
From source file:controllers.ConfigurationController.java
public static DBConfig getConfig(HttpServletRequest request) { try {/*from w w w .j a v a 2 s .c om*/ String path = Utility.getPath("dbconfig", request); path += "config.properties"; Properties p = new Properties(); FileInputStream file = new FileInputStream(path); p.load(file); file.close(); DBConfig config = new DBConfig(); String db = p.getProperty("prop.db"); if (db.equals("SQLServer")) config.setDb_type(DB_TYPE.SQLServer); if (db.equals("MySQL")) config.setDb_type(DB_TYPE.MySQL); if (db.equals("FirebirdSQL")) config.setDb_type(DB_TYPE.FirebirdSQL); if (db.equals("PostgreSQL")) config.setDb_type(DB_TYPE.PostgreSQL); if (db.equals("ORACLE")) config.setDb_type(DB_TYPE.ORACLE); config.setHost(p.getProperty("prop.server")); config.setPort(Integer.parseInt(p.getProperty("prop.port"))); config.setUser(p.getProperty("prop.user")); config.setPassword(p.getProperty("prop.passwd")); config.setDatabase(p.getProperty("prop.database")); return config; } catch (Exception ex) { System.err.println(ex.getMessage()); } return new DBConfig(); }