List of usage examples for java.lang Byte valueOf
public static Byte valueOf(String s) throws NumberFormatException
From source file:oracle.kv.hadoop.hive.table.TableSerDeBase.java
/** * Convenience method that return the byte value of the given number * String; where if the given defaultVal is returned if the given number * String is not a number./* w w w.j a va 2 s . com*/ */ static byte getByte(String altValue, byte defaultVal) { if (altValue != null && altValue.length() > 0) { try { return Byte.valueOf(altValue).byteValue(); } catch (NumberFormatException e) { return (byte) altValue.charAt(0); } } return defaultVal; }
From source file:com.meetup.memcached.NativeHandler.java
protected static Byte decodeByte(byte[] b) { return Byte.valueOf(b[0]); }
From source file:org.red5.io.utils.ConversionUtils.java
/** * Convert number to primitive wrapper like Boolean or Float * /*from w ww . j a v a 2s. co m*/ * @param num * Number to conver * @param wrapper * Primitive wrapper type * @return Converted object */ public static Object convertNumberToWrapper(Number num, Class<?> wrapper) { //XXX Paul: Using valueOf will reduce object creation if (wrapper.equals(String.class)) { return num.toString(); } else if (wrapper.equals(Boolean.class)) { return Boolean.valueOf(num.intValue() == 1); } else if (wrapper.equals(Double.class)) { return Double.valueOf(num.doubleValue()); } else if (wrapper.equals(Long.class)) { return Long.valueOf(num.longValue()); } else if (wrapper.equals(Float.class)) { return Float.valueOf(num.floatValue()); } else if (wrapper.equals(Integer.class)) { return Integer.valueOf(num.intValue()); } else if (wrapper.equals(Short.class)) { return Short.valueOf(num.shortValue()); } else if (wrapper.equals(Byte.class)) { return Byte.valueOf(num.byteValue()); } throw new ConversionException(String.format("Unable to convert number to: %s", wrapper)); }
From source file:com.xpn.xwiki.objects.classes.PasswordClass.java
public static String randomSalt() { StringBuilder salt = new StringBuilder(); SecureRandom random = new SecureRandom(); byte bytes[] = new byte[32]; random.nextBytes(bytes);/*from www .j av a 2s . c o m*/ for (byte temp : bytes) { String s = Integer.toHexString(Byte.valueOf(temp)); while (s.length() < 2) { s = "0" + s; } s = s.substring(s.length() - 2); salt.append(s); } return salt.toString(); }
From source file:org.apache.hadoop.hive.ql.exec.vector.RandomRowObjectSource.java
public Object randomObject(int column) { PrimitiveCategory primitiveCategory = primitiveCategories[column]; PrimitiveTypeInfo primitiveTypeInfo = primitiveTypeInfos[column]; switch (primitiveCategory) { case BOOLEAN: return Boolean.valueOf(r.nextInt(1) == 1); case BYTE://from www . j a v a2 s . c om return Byte.valueOf((byte) r.nextInt()); case SHORT: return Short.valueOf((short) r.nextInt()); case INT: return Integer.valueOf(r.nextInt()); case LONG: return Long.valueOf(r.nextLong()); case DATE: return getRandDate(r); case FLOAT: return Float.valueOf(r.nextFloat() * 10 - 5); case DOUBLE: return Double.valueOf(r.nextDouble() * 10 - 5); case STRING: return getRandString(r); case CHAR: return getRandHiveChar(r, (CharTypeInfo) primitiveTypeInfo); case VARCHAR: return getRandHiveVarchar(r, (VarcharTypeInfo) primitiveTypeInfo); case BINARY: return getRandBinary(r, 1 + r.nextInt(100)); case TIMESTAMP: return getRandTimestamp(r); case INTERVAL_YEAR_MONTH: return getRandIntervalYearMonth(r); case INTERVAL_DAY_TIME: return getRandIntervalDayTime(r); case DECIMAL: return getRandHiveDecimal(r, (DecimalTypeInfo) primitiveTypeInfo); default: throw new Error("Unknown primitive category " + primitiveCategory); } }
From source file:com.wavemaker.commons.util.TypeConversionUtils.java
public static Object fromString(Class<?> type, String s, boolean isList) { if (isList || !isPrimitiveOrWrapper(type)) { if (s == null) { return null; }/*from ww w .j a v a 2 s . c om*/ ObjectLiteralParser p = new ObjectLiteralParser(s, type); Object o = p.parse(); return o; } if (s == null) { return null; } else if (type == AtomicInteger.class) { return null; } else if (type == AtomicLong.class) { return null; } else if (type == BigDecimal.class) { return new BigDecimal(s); } else if (type == BigInteger.class) { return new BigDecimal(s); } else if (type == Boolean.class || type == boolean.class) { return Boolean.valueOf(s); } else if (type == Byte.class || type == byte.class) { return Byte.valueOf(s); } else if (type == Date.class) { if (StringUtils.isNumber(s)) { return new Date(Long.parseLong(s)); } else { throw new IllegalArgumentException("Unable to convert " + s + " to " + Date.class.getName()); } } else if (type == java.sql.Date.class) { return WMDateDeSerializer.getDate(s); } else if (type == Time.class) { return WMDateDeSerializer.getDate(s); } else if (type == Timestamp.class) { if (StringUtils.isNumber(s)) { return new Timestamp(Long.valueOf(s)); } else { throw new IllegalArgumentException("Unable to convert " + s + " to " + Timestamp.class.getName()); } } else if (type == LocalDateTime.class) { return WMLocalDateTimeDeSerializer.getLocalDateTime(s); } else if (type == Double.class || type == double.class) { return Double.valueOf(s); } else if (type == Float.class || type == float.class) { return Float.valueOf(s); } else if (type == Integer.class || type == int.class) { return Integer.valueOf(s); } else if (type == Long.class || type == long.class) { return Long.valueOf(s); } else if (type == Short.class || type == short.class) { return Short.valueOf(s); } else if (type == String.class || type == StringBuffer.class) { return s; } else if (type == Character.class || type == char.class) { return Character.valueOf(s.charAt(0)); } else { throw new AssertionError("Unable to convert \"" + s + "\" to " + type + " - unknown type: " + type); } }
From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF3Deserializer.java
protected Object readAMF3Object() throws IOException { if (debug)// ww w . j a v a 2 s. c o m debug("readAMF3Object()..."); Object result = null; int type = readAMF3Integer(); if (debug) debug("readAMF3Object() - type=", Integer.valueOf(type)); if ((type & 0x01) == 0) // stored object. result = getFromStoredObjects(type >> 1); else { boolean inlineClassDef = (((type >> 1) & 0x01) != 0); if (debug) debug("readAMF3Object() - inlineClassDef=", String.valueOf(inlineClassDef)); // read class decriptor. ActionScriptClassDescriptor desc = null; if (inlineClassDef) { int propertiesCount = type >> 4; if (debug) debug("readAMF3Object() - propertiesCount=", String.valueOf(propertiesCount)); byte encoding = (byte) ((type >> 2) & 0x03); if (debug) debug("readAMF3Object() - encoding=", Byte.valueOf(encoding)); String className = readAMF3String(); if (debug) debug("readAMF3Object() - className=", StringUtil.toString(className)); desc = new DefaultActionScriptClassDescriptor(className, encoding); addToStoredClassDescriptors(desc); if (debug) debug("readAMF3Object() - defining ", String.valueOf(propertiesCount), " properties..."); for (int i = 0; i < propertiesCount; i++) { String name = readAMF3String(); System.out.println("readAMF3Object() - defining property name=" + name); if (debug) debug("readAMF3Object() - defining property name=", name); //bugging out here desc.defineProperty(name); } } else desc = getFromStoredClassDescriptors(type >> 2); if (debug) debug("readAMF3Object() - actionScriptClassDescriptor=", desc); int objectEncoding = desc.getEncoding(); // Find externalizer and create Java instance. Externalizer externalizer = desc.getExternalizer(); if (externalizer != null) { try { result = externalizer.newInstance(desc.getType(), this); } catch (Exception e) { throw new RuntimeException("Could not instantiate type: " + desc.getType(), e); } } else result = desc.newJavaInstance(); int index = addToStoredObjects(result); // read object content... if ((objectEncoding & 0x01) != 0) { // externalizer. if (externalizer != null) { if (debug) debug("readAMF3Object() - using externalizer=", externalizer); try { externalizer.readExternal(result, this); } catch (IOException e) { throw e; } catch (Exception e) { throw new RuntimeException("Could not read externalized object: " + result, e); } } // legacy externalizable. else { if (debug) debug("readAMF3Object() - legacy Externalizable=", result.getClass()); try { ((Externalizable) result).readExternal(this); } catch (IOException e) { throw e; } catch (Exception e) { throw new RuntimeException("Could not read externalizable object: " + result, e); } } } else { // defined values... if (desc.getPropertiesCount() > 0) { if (debug) debug("readAMF3Object() - reading defined properties..."); System.out.println("readAMF3Object() - reading defined properties..."); for (int i = 0; i < desc.getPropertiesCount(); i++) { byte vType = readByte(); Object value = readObject(vType); if (debug) debug("readAMF3Object() - setting defined property: ", desc.getPropertyName(i), "=", StringUtil.toString(value)); desc.setPropertyValue(i, result, value); } } // dynamic values... if (objectEncoding == 0x02) { if (debug) debug("readAMF3Object() - reading dynamic properties..."); while (true) { String name = readAMF3String(); if (name.length() == 0) break; byte vType = readByte(); Object value = readObject(vType); if (debug) debug("readAMF3Object() - setting dynamic property: ", name, "=", StringUtil.toString(value)); desc.setPropertyValue(name, result, value); } } } if (result instanceof AbstractInstanciator) { if (debug) debug("readAMF3Object() - resolving instanciator..."); try { result = ((AbstractInstanciator<?>) result).resolve(); } catch (Exception e) { throw new RuntimeException("Could not instantiate object: " + result, e); } setStoredObject(index, result); } } if (debug) debug("readAMF3Object() -> ", result); return result; }
From source file:org.apache.tuscany.sca.node.launcher.NodeLauncher.java
static Object invoke(Object proxy, String operationName, String... params) throws IllegalAccessException, InvocationTargetException { for (Method m : proxy.getClass().getMethods()) { if (m.getName().equals(operationName) && m.getParameterTypes().length == params.length) { Object parameters[] = new Object[params.length]; int i = 0; for (Class<?> type : m.getParameterTypes()) { if (type == byte.class || type == Byte.class) { parameters[i] = Byte.valueOf(params[i]); } else if (type == char.class || type == Character.class) { parameters[i] = params[i].charAt(0); } else if (type == boolean.class || type == Boolean.class) { parameters[i] = Boolean.valueOf(params[i]); } else if (type == short.class || type == Short.class) { parameters[i] = Short.valueOf(params[i]); } else if (type == int.class || type == Integer.class) { parameters[i] = Integer.valueOf(params[i]); } else if (type == long.class || type == Long.class) { parameters[i] = Long.valueOf(params[i]); } else if (type == float.class || type == Float.class) { parameters[i] = Float.valueOf(params[i]); } else if (type == double.class || type == Double.class) { parameters[i] = Double.valueOf(params[i]); } else if (type == String.class) { parameters[i] = params[i]; } else { throw new IllegalArgumentException("Parameter type is not supported: " + type); }//from ww w .ja va2s . co m i++; } Object result = m.invoke(proxy, parameters); return result; } } throw new IllegalArgumentException("Invalid service operation: " + operationName); }
From source file:org.eclipse.dataset.ByteDataset.java
@Override public Object getObject(final int i) { return Byte.valueOf(get(i)); // CLASS_TYPE }
From source file:org.eclipse.dataset.ByteDataset.java
@Override public Object getObject(final int i, final int j) { return Byte.valueOf(get(i, j)); // CLASS_TYPE }