List of usage examples for java.lang Byte parseByte
public static byte parseByte(String s) throws NumberFormatException
From source file:com.example.forum.TypeUtils.java
/** * byte^?B/*from w ww .jav a2 s. c om*/ * @param byteString ??B * @param defaultValue ftHgl?B * @return byte^l?B */ public static byte toByte(String byteString, byte defaultValue) { if (byteString == null || byteString.length() == 0) { return defaultValue; } byte byteValue = defaultValue; try { byteValue = Byte.parseByte(byteString); } catch (Exception e) { log.error(e.getMessage(), e); } return byteValue; }
From source file:com.sun.honeycomb.admin.mgmt.server.HCCellAdapterBase.java
public void loadHCCellBase() throws InstantiationException { config = ClusterProperties.getInstance(); mgmtServer = MgmtServer.getInstance(); numNodes = ClusterProperties.getInstance().getPropertyAsInt(ConfigPropertyNames.PROP_NUM_NODES); localCellid = Byte.parseByte(config.getProperty(ConfigPropertyNames.PROP_CELLID)); }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.connections.PooledDatasourceHelper.java
public static PoolingDataSource setupPooledDataSource(final IDatabaseConnection databaseConnection) throws DatasourceServiceException { try {//from ww w.j ava2 s .co m final DataSourceCacheManager cacheManager = ClassicEngineBoot.getInstance().getObjectFactory() .get(DataSourceCacheManager.class); final IDatabaseDialectService databaseDialectService = ClassicEngineBoot.getInstance() .getObjectFactory().get(IDatabaseDialectService.class); final IDatabaseDialect dialect = databaseDialectService.getDialect(databaseConnection); final String driverClass; if (GENERIC.equals(databaseConnection.getDatabaseType().getShortName())) { //$NON-NLS-1$ driverClass = databaseConnection.getAttributes() .get(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS); } else { driverClass = dialect.getNativeDriver(); } String url; try { url = dialect.getURLWithExtraOptions(databaseConnection); } catch (DatabaseDialectException e) { url = null; } // Read default connection pooling parameter final String maxdleConn = getSystemSetting("dbcp-defaults.max-idle-conn"); //$NON-NLS-1$ final String minIdleConn = getSystemSetting("dbcp-defaults.min-idle-conn"); //$NON-NLS-1$ final String maxActConn = getSystemSetting("dbcp-defaults.max-act-conn"); //$NON-NLS-1$ String validQuery = null; final String whenExhaustedAction = getSystemSetting("dbcp-defaults.when-exhausted-action"); //$NON-NLS-1$ final String wait = getSystemSetting("dbcp-defaults.wait"); //$NON-NLS-1$ final String testWhileIdleValue = getSystemSetting("dbcp-defaults.test-while-idle"); //$NON-NLS-1$ final String testOnBorrowValue = getSystemSetting("dbcp-defaults.test-on-borrow"); //$NON-NLS-1$ final String testOnReturnValue = getSystemSetting("dbcp-defaults.test-on-return"); //$NON-NLS-1$ final boolean testWhileIdle = !StringUtils.isEmpty(testWhileIdleValue) && Boolean.parseBoolean(testWhileIdleValue); final boolean testOnBorrow = !StringUtils.isEmpty(testOnBorrowValue) && Boolean.parseBoolean(testOnBorrowValue); final boolean testOnReturn = !StringUtils.isEmpty(testOnReturnValue) && Boolean.parseBoolean(testOnReturnValue); int maxActiveConnection = -1; long waitTime = -1; byte whenExhaustedActionType = -1; final int minIdleConnection = !StringUtils.isEmpty(minIdleConn) ? Integer.parseInt(minIdleConn) : -1; final int maxIdleConnection = !StringUtils.isEmpty(maxdleConn) ? Integer.parseInt(maxdleConn) : -1; final Map<String, String> attributes = databaseConnection.getAttributes(); if (attributes.containsKey(DataBaseConnectionAttributes.MAX_ACTIVE_KEY)) { maxActiveConnection = Integer.parseInt(attributes.get(DataBaseConnectionAttributes.MAX_ACTIVE_KEY)); } else { if (!StringUtils.isEmpty(maxActConn)) { maxActiveConnection = Integer.parseInt(maxActConn); } } if (attributes.containsKey(DataBaseConnectionAttributes.MAX_WAIT_KEY)) { waitTime = Integer.parseInt(attributes.get(DataBaseConnectionAttributes.MAX_WAIT_KEY)); } else { if (!StringUtils.isEmpty(wait)) { waitTime = Long.parseLong(wait); } } if (attributes.containsKey(DataBaseConnectionAttributes.QUERY_KEY)) { validQuery = attributes.get(DataBaseConnectionAttributes.QUERY_KEY); } if (!StringUtils.isEmpty(whenExhaustedAction)) { whenExhaustedActionType = Byte.parseByte(whenExhaustedAction); } else { whenExhaustedActionType = GenericObjectPool.WHEN_EXHAUSTED_BLOCK; } final PoolingDataSource poolingDataSource = new PoolingDataSource(); // As the name says, this is a generic pool; it returns basic Object-class objects. final GenericObjectPool pool = new GenericObjectPool(null); pool.setWhenExhaustedAction(whenExhaustedActionType); // Tuning the connection pool pool.setMaxActive(maxActiveConnection); pool.setMaxIdle(maxIdleConnection); pool.setMaxWait(waitTime); pool.setMinIdle(minIdleConnection); pool.setTestWhileIdle(testWhileIdle); pool.setTestOnReturn(testOnReturn); pool.setTestOnBorrow(testOnBorrow); pool.setTestWhileIdle(testWhileIdle); /* * ConnectionFactory creates connections on behalf of the pool. Here, we use the DriverManagerConnectionFactory * because that essentially uses DriverManager as the source of connections. */ final Properties properties = new Properties(); properties.setProperty("user", databaseConnection.getUsername()); properties.setProperty("password", databaseConnection.getPassword()); final ConnectionFactory factory = new DriverConnectionFactory(getDriver(dialect, driverClass, url), url, properties); /* * Puts pool-specific wrappers on factory connections. For clarification: "[PoolableConnection]Factory," not * "Poolable[ConnectionFactory]." */ // This declaration is used implicitly. // noinspection UnusedDeclaration final PoolableConnectionFactory pcf = new PoolableConnectionFactory(factory, // ConnectionFactory pool, // ObjectPool null, // KeyedObjectPoolFactory validQuery, // String (validation query) false, // boolean (default to read-only?) true // boolean (default to auto-commit statements?) ); /* * initialize the pool to X connections */ logger.debug("Pool defaults to " + maxActiveConnection + " max active/" + maxIdleConnection + "max idle" + "with " + waitTime + "wait time"//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + " idle connections."); //$NON-NLS-1$ for (int i = 0; i < maxIdleConnection; ++i) { pool.addObject(); } logger.debug( "Pool now has " + pool.getNumActive() + " active/" + pool.getNumIdle() + " idle connections."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ /* * All of this is wrapped in a DataSource, which client code should already know how to handle (since it's the * same class of object they'd fetch via the container's JNDI tree */ poolingDataSource.setPool(pool); // store the pool, so we can get to it later cacheManager.getDataSourceCache().put(databaseConnection.getName(), poolingDataSource); return (poolingDataSource); } catch (Exception e) { throw new DatasourceServiceException(e); } }
From source file:com.ebay.erl.mobius.core.mapred.AbstractMobiusMapper.java
/** * Setup Mapper.//from w w w .jav a 2 s . c o m * <p> * * Override this method if there is extra initial * settings need to be done. * <p> * * Make sure to call <code>super.configure(JobConf)</code> * when overriding. * */ @SuppressWarnings("unchecked") @Override public void configure(JobConf conf) { super.configure(conf); this.conf = conf; this._IS_MAP_ONLY_JOB = this.conf.getInt("mapred.reduce.tasks", 1) == 0; // catch the current dataset ID, the {@link Configuration#get(String)} // is costly as it compose Pattern every time. this.currentDatasetID = Byte.valueOf(this.conf.get(ConfigureConstants.CURRENT_DATASET_ID)); String[] datasetIDstoNames = this.conf.getStrings(ConfigureConstants.DATASET_ID_TO_NAME_MAPPING); Map<Byte, String> mapping = new HashMap<Byte, String>(); for (String aMapping : datasetIDstoNames) { int cut = aMapping.indexOf(";"); Byte datasetID = Byte.parseByte(aMapping.substring(0, cut)); String datasetDisplayName = aMapping.substring(cut + 1); mapping.put(datasetID, datasetDisplayName); } if (mapping.size() == 0) throw new IllegalArgumentException(ConfigureConstants.DATASET_ID_TO_NAME_MAPPING + " is not set."); this.dataset_display_id = mapping.get(this.currentDatasetID); if (this.dataset_display_id == null) { throw new IllegalArgumentException("Cannot find display name for datasetID:" + this.currentDatasetID + " from " + ConfigureConstants.DATASET_ID_TO_NAME_MAPPING + ":" + this.conf.get(ConfigureConstants.DATASET_ID_TO_NAME_MAPPING)); } // initialize counters this._COUNTER_INPUT_RECORD = 0L; this._COUNTER_OUTPUT_RECORD = 0L; this._COUNTER_FILTERED_RECORD = 0L; this._COUNTER_INVALIDATE_FORMAT_RECORD = 0L; try { this.key_columns = (String[]) this.conf.getStrings(this.getDatasetID() + ".key.columns", Util.ZERO_SIZE_STRING_ARRAY); this.value_columns = (String[]) this.conf.getStrings(this.getDatasetID() + ".value.columns", Util.ZERO_SIZE_STRING_ARRAY); this.tuple_criteria = (TupleCriterion) this.get("tuple.criteria"); this.computedColumns = (List<ComputedColumns>) this.get("computed.columns"); if (this._IS_MAP_ONLY_JOB) { this.projection_order = (String[]) this.conf.getStrings( this.getDatasetID() + ".columns.in.original.order", Util.ZERO_SIZE_STRING_ARRAY); } } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } }
From source file:com.evolveum.midpoint.prism.util.JavaTypeConverter.java
public static <T> T convert(Class<T> expectedType, Object rawValue) { if (rawValue == null || expectedType.isInstance(rawValue)) { return (T) rawValue; }/*from w w w .j av a2s .com*/ if (rawValue instanceof PrismPropertyValue<?>) { rawValue = ((PrismPropertyValue<?>) rawValue).getValue(); } // This really needs to be checked twice if (rawValue == null || expectedType.isInstance(rawValue)) { return (T) rawValue; } // Primitive types // boolean if (expectedType == boolean.class && rawValue instanceof Boolean) { return (T) ((Boolean) rawValue); } if (expectedType == Boolean.class && rawValue instanceof String) { return (T) (Boolean) Boolean.parseBoolean(((String) rawValue)); } if (expectedType == Boolean.class && rawValue instanceof PolyString) { return (T) (Boolean) Boolean.parseBoolean(((PolyString) rawValue).toString()); } if (expectedType == boolean.class && rawValue instanceof String) { return (T) (Boolean) Boolean.parseBoolean(((String) rawValue)); } if (expectedType == boolean.class && rawValue instanceof PolyString) { return (T) (Boolean) Boolean.parseBoolean(((PolyString) rawValue).toString()); } if (expectedType == String.class && rawValue instanceof Boolean) { return (T) rawValue.toString(); } // int if (expectedType == int.class && rawValue instanceof Integer) { return (T) ((Integer) rawValue); } if (expectedType == Integer.class && rawValue instanceof String) { return (T) (Integer) Integer.parseInt(((String) rawValue)); } if (expectedType == int.class && rawValue instanceof String) { return (T) (Integer) Integer.parseInt(((String) rawValue)); } if (expectedType == String.class && rawValue instanceof Integer) { return (T) rawValue.toString(); } if (expectedType == int.class && rawValue instanceof Long) { return (T) (Integer) ((Long) rawValue).intValue(); } if (expectedType == long.class && rawValue instanceof Long) { return (T) ((Long) rawValue); } if (expectedType == Long.class && rawValue instanceof String) { return (T) (Long) Long.parseLong(((String) rawValue)); } if (expectedType == long.class && rawValue instanceof String) { return (T) (Long) Long.parseLong(((String) rawValue)); } if (expectedType == String.class && rawValue instanceof Long) { return (T) rawValue.toString(); } if (expectedType == float.class && rawValue instanceof Float) { return (T) ((Float) rawValue); } if (expectedType == Float.class && rawValue instanceof String) { return (T) (Float) Float.parseFloat(((String) rawValue)); } if (expectedType == float.class && rawValue instanceof String) { return (T) (Float) Float.parseFloat(((String) rawValue)); } if (expectedType == String.class && rawValue instanceof Float) { return (T) rawValue.toString(); } if (expectedType == double.class && rawValue instanceof Double) { return (T) ((Double) rawValue); } if (expectedType == Double.class && rawValue instanceof String) { return (T) (Double) Double.parseDouble(((String) rawValue)); } if (expectedType == double.class && rawValue instanceof String) { return (T) (Double) Double.parseDouble(((String) rawValue)); } if (expectedType == String.class && rawValue instanceof Float) { return (T) rawValue.toString(); } if (expectedType == byte.class && rawValue instanceof Byte) { return (T) ((Byte) rawValue); } if (expectedType == Byte.class && rawValue instanceof String) { return (T) (Byte) Byte.parseByte(((String) rawValue)); } if (expectedType == byte.class && rawValue instanceof String) { return (T) (Byte) Byte.parseByte(((String) rawValue)); } if (expectedType == String.class && rawValue instanceof Byte) { return (T) rawValue.toString(); } if (expectedType == BigInteger.class && rawValue instanceof String) { return (T) new BigInteger(((String) rawValue)); } if (expectedType == String.class && rawValue instanceof BigInteger) { return (T) ((BigInteger) rawValue).toString(); } if (expectedType == BigDecimal.class && rawValue instanceof String) { return (T) new BigDecimal(((String) rawValue)); } if (expectedType == String.class && rawValue instanceof BigDecimal) { return (T) ((BigDecimal) rawValue).toString(); } if (expectedType == PolyString.class && rawValue instanceof String) { return (T) new PolyString((String) rawValue); } if (expectedType == PolyStringType.class && rawValue instanceof String) { PolyStringType polyStringType = new PolyStringType(); polyStringType.setOrig((String) rawValue); return (T) polyStringType; } if (expectedType == String.class && rawValue instanceof PolyString) { return (T) ((PolyString) rawValue).getOrig(); } if (expectedType == String.class && rawValue instanceof PolyStringType) { return (T) ((PolyStringType) rawValue).getOrig(); } if (expectedType == PolyString.class && rawValue instanceof PolyStringType) { return (T) ((PolyStringType) rawValue).toPolyString(); } if (expectedType == PolyString.class && rawValue instanceof Integer) { return (T) new PolyString(((Integer) rawValue).toString()); } if (expectedType == PolyStringType.class && rawValue instanceof PolyString) { PolyStringType polyStringType = new PolyStringType((PolyString) rawValue); return (T) polyStringType; } if (expectedType == PolyStringType.class && rawValue instanceof Integer) { PolyStringType polyStringType = new PolyStringType(((Integer) rawValue).toString()); return (T) polyStringType; } // Date and time if (expectedType == XMLGregorianCalendar.class && rawValue instanceof Long) { XMLGregorianCalendar xmlCalType = XmlTypeConverter.createXMLGregorianCalendar((Long) rawValue); return (T) xmlCalType; } if (expectedType == XMLGregorianCalendar.class && rawValue instanceof String) { XMLGregorianCalendar xmlCalType = magicDateTimeParse((String) rawValue); return (T) xmlCalType; } if (expectedType == String.class && rawValue instanceof XMLGregorianCalendar) { return (T) ((XMLGregorianCalendar) rawValue).toXMLFormat(); } if (expectedType == Long.class && rawValue instanceof XMLGregorianCalendar) { return (T) (Long) XmlTypeConverter.toMillis((XMLGregorianCalendar) rawValue); } // XML Enums (JAXB) if (expectedType.isEnum() && expectedType.getAnnotation(XmlEnum.class) != null && rawValue instanceof String) { return XmlTypeConverter.toXmlEnum(expectedType, (String) rawValue); } if (expectedType == String.class && rawValue.getClass().isEnum() && rawValue.getClass().getAnnotation(XmlEnum.class) != null) { return (T) XmlTypeConverter.fromXmlEnum(rawValue); } // Java Enums if (expectedType.isEnum() && rawValue instanceof String) { return (T) Enum.valueOf((Class<Enum>) expectedType, (String) rawValue); } if (expectedType == String.class && rawValue.getClass().isEnum()) { return (T) rawValue.toString(); } //QName if (expectedType == QName.class && rawValue instanceof QName) { return (T) rawValue; } if (expectedType == QName.class && rawValue instanceof String) { return (T) QNameUtil.uriToQName((String) rawValue); } throw new IllegalArgumentException("Expected " + expectedType + " type, but got " + rawValue.getClass()); }
From source file:edu.cornell.med.icb.goby.util.dynoptions.DynamicOptionClient.java
/** * Obtain the Byte value corresponding to the key. * * @param key option key.// w w w . j a va 2s. com * @return Value/default value for option, or null if the value and the default were missing. */ public Byte getByte(final String key) { final String val = getString(key); if (val != null) { return Byte.parseByte(val); } return null; }
From source file:fr.cedrik.util.ExtendedProperties.java
public byte getByte(String key) { return Byte.parseByte(getProperty(key)); }
From source file:com.mpush.test.connection.body.BodyTest.java
@Before public void init() { try {/* w ww.java 2 s .c om*/ dailyPrivateKey = (RSAPrivateKey) RSAUtils.decodePrivateKey(daily_privateKey); prePrivateKey = (RSAPrivateKey) RSAUtils.decodePrivateKey(pre_privateKey); onlinePrivateKey = (RSAPrivateKey) RSAUtils.decodePrivateKey(online_privateKey); String[] temp = rawData.split(","); data = new byte[temp.length]; for (int i = 0; i < temp.length; i++) { data[i] = Byte.parseByte(temp[i].trim()); } } catch (Exception e) { e.printStackTrace(); } }
From source file:net.agkn.field_stripe.stripe.XMLFieldStripeReader.java
/** * Parses the specified non-<code>null</code> string value into the appropriate * type based on the {@link IField field's} {@link IField#getType() type}. */// w w w. j ava2 s . com private Object parseValue(final String stringValue) { switch (fieldType) { case BYTE: return Byte.parseByte(stringValue); case SHORT: return Short.parseShort(stringValue); case INT: return Integer.parseInt(stringValue); case LONG: return Long.parseLong(stringValue); case FLOAT: return Float.parseFloat(stringValue); case DOUBLE: return Double.parseDouble(stringValue); case BOOLEAN: return Boolean.parseBoolean(stringValue); case STRING: return StringEscapeUtils.unescapeXml(stringValue); default: throw new DeveloperException("Unknown field type in field \"" + field.getName() + "."); } }
From source file:fr.cedrik.util.ExtendedProperties.java
public byte getByte(String key, byte defaultValue) { String val = getProperty(key); return (val == null) ? defaultValue : Byte.parseByte(val); }