List of usage examples for java.util Properties getProperty
public String getProperty(String key)
From source file:com.impetus.client.cassandra.pelops.PelopsUtils.java
/** * Gets the pool config policy.//from www . ja va 2 s . c o m * * @param persistenceUnitMetadata * the persistence unit metadata * @return the pool config policy */ public static Policy getPoolConfigPolicy(PersistenceUnitMetadata persistenceUnitMetadata) { Policy policy = new Policy(); Properties props = persistenceUnitMetadata.getProperties(); String maxActivePerNode = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_ACTIVE); String maxIdlePerNode = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_IDLE); String minIdlePerNode = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MIN_IDLE); String maxTotal = props.getProperty(PersistenceProperties.KUNDERA_POOL_SIZE_MAX_TOTAL); try { if (!StringUtils.isEmpty(maxActivePerNode)) { policy.setMaxActivePerNode(Integer.parseInt(maxActivePerNode)); } if (!StringUtils.isEmpty(maxIdlePerNode)) { policy.setMaxActivePerNode(Integer.parseInt(maxIdlePerNode)); } if (!StringUtils.isEmpty(minIdlePerNode)) { policy.setMaxActivePerNode(Integer.parseInt(minIdlePerNode)); } if (!StringUtils.isEmpty(maxTotal)) { policy.setMaxActivePerNode(Integer.parseInt(maxTotal)); } } catch (NumberFormatException e) { logger.warn( "Some Connection pool related property for " + persistenceUnitMetadata.getPersistenceUnitName() + " persistence unit couldn't be parsed. Default pool policy would be used"); policy = null; } return policy; }
From source file:Main.java
private static String getVerNameFromAssert(Context context) { String versionName = ""; try {/* w w w . j a v a 2 s . c om*/ Properties pro = new Properties(); InputStream is = context.getAssets().open("channel.properties"); pro.load(is); String tmpVersionName = pro.getProperty("versionName"); versionName = new String(tmpVersionName.getBytes("ISO-8859-1"), "UTF-8"); is.close(); is = null; } catch (Exception e) { versionName = ""; Log.e(TAG, "AppConfig.loadVersion have Exception e = " + e.getMessage()); } return versionName; }
From source file:com.eryansky.utils.SigarUtil.java
/** * ??/* w w w . ja v a2 s . co m*/ * @throws Exception */ public static ServerStatus getServerStatus() throws Exception { ServerStatus status = new ServerStatus(); status.setServerTime(DateFormatUtils.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss")); status.setServerName(System.getenv().get("COMPUTERNAME")); Runtime rt = Runtime.getRuntime(); //status.setIp(InetAddress.getLocalHost().getHostAddress()); status.setJvmTotalMem(rt.totalMemory() / (1024 * 1024)); status.setJvmFreeMem(rt.freeMemory() / (1024 * 1024)); status.setJvmMaxMem(rt.maxMemory() / (1024 * 1024)); Properties props = System.getProperties(); status.setServerOs(props.getProperty("os.name") + " " + props.getProperty("os.arch") + " " + props.getProperty("os.version")); status.setJavaHome(props.getProperty("java.home")); status.setJavaVersion(props.getProperty("java.version")); status.setJavaTmpPath(props.getProperty("java.io.tmpdir")); Sigar sigar = new Sigar(); getServerCpuInfo(sigar, status); getServerDiskInfo(sigar, status); getServerMemoryInfo(sigar, status); return status; }
From source file:com.sap.prd.mobile.ios.mios.SCMUtil.java
public static String getRevision(final Properties versionInfo) { final String type = versionInfo.getProperty("type"); final String key; if (type != null && type.equals("git")) { key = "commitId"; } else {//from ww w . jav a 2s .c o m key = "changelist"; } final String value = versionInfo.getProperty(key); if (StringUtils.isBlank(value)) { throw new IllegalStateException(String.format("%s has not been provided in sync.info file.", key)); } return value; }
From source file:ConnectionUtil.java
/** Get a Connection for the given config name from a provided Properties */ public static Connection getConnection(Properties p, String config) throws Exception { try {//www . java 2 s .co m String db_driver = p.getProperty(config + "." + "DBDriver"); String db_url = p.getProperty(config + "." + "DBURL"); String db_user = p.getProperty(config + "." + "DBUser"); String db_password = p.getProperty(config + "." + "DBPassword"); if (db_driver == null || db_url == null) { throw new IllegalStateException("Driver or URL null: " + config); } return createConnection(db_driver, db_url, db_user, db_password); } catch (ClassNotFoundException ex) { throw new Exception(ex.toString()); } catch (SQLException ex) { throw new Exception(ex.toString()); } }
From source file:at.ac.tuwien.dsg.comot.m.adapter.Main.java
private static String getServiceInstanceId() { String serviceId = null;//from ww w . ja v a 2s . co m try (InputStream input = new FileInputStream(PROPERTIES_FILE)) { Properties prop = new Properties(); prop.load(input); serviceId = prop.getProperty(SERVICE_INSTANCE_AS_PROPERTY); LOG.info("service={}", serviceId); } catch (IOException e) { LOG.error(" {}", e); } if (serviceId == null) { LOG.error("there is no property '{}'", SERVICE_INSTANCE_AS_PROPERTY); throw new IllegalArgumentException("there is no property " + SERVICE_INSTANCE_AS_PROPERTY); } return serviceId; }
From source file:Main.java
/** * Read and prepared exclude filters for robots that should not be downloaded or participate in battles. * * @param properties the properties to store. * @return a string array containing the excluded robots or null if no excludes are defined. *//* www . java2s . c o m*/ public static void setExcludes(Properties properties) { if (excludes != null) { return; } // Read and prepare exclude filters String exclude = properties.getProperty("EXCLUDE"); if (exclude != null) { // Convert into regular expression // Dots must be dots, not "any character" in the regular expression exclude = exclude.replaceAll("\\.", "\\\\."); // The wildcard character ? corresponds to the regular expression .? exclude = exclude.replaceAll("\\?", ".?"); // The wildcard character * corresponds to the regular expression .* exclude = exclude.replaceAll("\\*", ".*"); // Split the exclude line into independent exclude filters that are trimmed for white-spaces excludes = exclude.split("[,;]+"); // white spaces are allowed in the filter due to robot version numbers } }
From source file:org.openvpms.component.business.service.security.memory.UserMapEditor.java
public static UserMap addUsersFromProperties(UserMap userMap, Properties props) { for (Object o : props.keySet()) { String username = (String) o; String value = props.getProperty(username); // now retrieve the rest of the user details including the // details and the authorities String[] tokens = StringUtils.commaDelimitedListToStringArray(value); String password = tokens[0]; // the rest need to be granted authorities ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (int index = 1; index < tokens.length; index++) { authorities.add(new ArchetypeAwareGrantedAuthority(tokens[index])); }// w w w. j ava2 s. c o m userMap.addUser(new User(username, password, true)); } return userMap; }
From source file:com.baidu.qa.service.test.util.MysqlDatabaseManager.java
/** * ?mysql db??//from w w w.jav a 2 s. co m * @param dbname * @return * @throws SQLException */ static public Connection getCon(String dbname) throws SQLException { String host = ""; String user = ""; String database = ""; String password = ""; String driverClass = ""; String useUnicode = ""; try { // ???? InputStream in = new BufferedInputStream( new FileInputStream(ServiceInterfaceCaseTest.CASEPATH + Constant.FILENAME_DB)); Properties Info = new Properties(); Info.load(in); host = Info.getProperty(dbname + "_DB_Host"); user = Info.getProperty(dbname + "_DB_User"); database = Info.getProperty(dbname + "_DB_DataBase"); password = Info.getProperty(dbname + "_DB_Password"); driverClass = Info.getProperty(dbname + "_DB_DriverClass"); useUnicode = Info.getProperty(dbname + "_DB_UseUnicode"); } catch (Exception e) { log.error("[mysql configure file for" + dbname + "error]:", e); throw new AssertionError("[get mysql database config error from properties file]"); } if (host == null) { log.error("[load configure file for " + dbname + " error]:"); return null; } // String url = "jdbc:mysql://" + host.trim() + "/" + ((database != null) ? database.trim() : "") + "?useUnicode=" + ((useUnicode != null) ? useUnicode.trim() : "true&characterEncoding=gbk"); try { Class.forName(driverClass); } catch (ClassNotFoundException e) { log.error("[class not found]:", e); throw new AssertionError("[class not found]"); } Connection con = null; try { con = DriverManager.getConnection(url, user, password); } catch (SQLException a) { log.error("[mysql connection exception] ", a); throw new AssertionError("[mysql connection exception]"); } return con; }
From source file:com.threatconnect.sdk.config.Configuration.java
public static Configuration build(Properties props) { String tcApiUrl = props.getProperty("connection.tcApiUrl"); String tcApiAccessID = props.getProperty("connection.tcApiAccessID"); String tcApiUserSecretKey = props.getProperty("connection.tcApiUserSecretKey"); String tcDefaultOwner = props.getProperty("connection.tcDefaultOwner"); Integer tcResultLimit = Integer.valueOf(props.getProperty("connection.tcResultLimit")); Configuration conf = new Configuration(tcApiUrl, tcApiAccessID, tcApiUserSecretKey, tcDefaultOwner, tcResultLimit);/*from w w w. j a v a2 s. c o m*/ if (props.getProperty("connection.tcProxyHost") != null) { String tcProxyHost = props.getProperty("connection.tcProxyHost"); Integer tcProxyPort = Integer.valueOf(props.getProperty("connection.tcProxyPort")); conf.setProxy(tcProxyHost, tcProxyPort); } return conf; }