Example usage for java.lang Byte valueOf

List of usage examples for java.lang Byte valueOf

Introduction

In this page you can find the example usage for java.lang Byte valueOf.

Prototype

public static Byte valueOf(String s) throws NumberFormatException 

Source Link

Document

Returns a Byte object holding the value given by the specified String .

Usage

From source file:Main.java

public static Object getObject(String type, String value) throws Exception {

    type = type.toLowerCase();//w  ww  .j a va 2  s .c  o m
    if ("boolean".equals(type))
        return Boolean.valueOf(value);
    if ("byte".equals(type))
        return Byte.valueOf(value);
    if ("short".equals(type))
        return Short.valueOf(value);
    if ("char".equals(type))
        if (value.length() != 1)
            throw new NumberFormatException("Argument is not a character!");
        else
            return Character.valueOf(value.toCharArray()[0]);
    if ("int".equals(type))
        return Integer.valueOf(value);
    if ("long".equals(type))
        return Long.valueOf(value);
    if ("float".equals(type))
        return Float.valueOf(value);
    if ("double".equals(type))
        return Double.valueOf(value);
    if ("string".equals(type))
        return value;
    else {
        Object objs[] = new String[] { value };
        return Class.forName(type).getConstructor(new Class[] { java.lang.String.class }).newInstance(objs);
    }
}

From source file:Main.java

/**
 * Converts to object array.//w w  w  .ja  v  a2s.  c  o  m
 */
public static Byte[] valuesOf(byte[] array) {
    Byte[] dest = new Byte[array.length];
    for (int i = 0; i < array.length; i++) {
        dest[i] = Byte.valueOf(array[i]);
    }
    return dest;
}

From source file:Main.java

public static UUID UUID(byte abyte0[]) {
    StringBuilder stringbuilder;/*from   ww w.j a  v a 2 s  .  c o  m*/
    switch (abyte0.length) {
    default:
        return null;

    case 2: // '\002'
        Object aobj4[] = new Object[2];
        aobj4[0] = Byte.valueOf(abyte0[0]);
        aobj4[1] = Byte.valueOf(abyte0[1]);
        return UUID16(String.format("%02x%02x", aobj4));

    case 16: // '\020'
        stringbuilder = new StringBuilder(128);
        break;
    }
    Object aobj[] = new Object[4];
    aobj[0] = Byte.valueOf(abyte0[0]);
    aobj[1] = Byte.valueOf(abyte0[1]);
    aobj[2] = Byte.valueOf(abyte0[2]);
    aobj[3] = Byte.valueOf(abyte0[3]);
    stringbuilder.append(String.format("%02x%02x%02x%02x", aobj));
    Object aobj1[] = new Object[4];
    aobj1[0] = Byte.valueOf(abyte0[4]);
    aobj1[1] = Byte.valueOf(abyte0[5]);
    aobj1[2] = Byte.valueOf(abyte0[6]);
    aobj1[3] = Byte.valueOf(abyte0[7]);
    stringbuilder.append(String.format("-%02x%02x-%02x%02x", aobj1));
    Object aobj2[] = new Object[4];
    aobj2[0] = Byte.valueOf(abyte0[8]);
    aobj2[1] = Byte.valueOf(abyte0[9]);
    aobj2[2] = Byte.valueOf(abyte0[10]);
    aobj2[3] = Byte.valueOf(abyte0[11]);
    stringbuilder.append(String.format("-%02x%02x-%02x%02x", aobj2));
    Object aobj3[] = new Object[4];
    aobj3[0] = Byte.valueOf(abyte0[12]);
    aobj3[1] = Byte.valueOf(abyte0[13]);
    aobj3[2] = Byte.valueOf(abyte0[14]);
    aobj3[3] = Byte.valueOf(abyte0[15]);
    stringbuilder.append(String.format("%02x%02x%02x%02x", aobj3));
    return UUID128(stringbuilder.toString());
}

From source file:Main.java

/**
 * box the byte to Byte
 */
public static Byte boxed(byte v) {
    return Byte.valueOf(v);
}

From source file:Main.java

public static String byteArrayToHexString(byte[] paramArrayOfByte) {
    StringBuilder localStringBuilder = new StringBuilder(2 * paramArrayOfByte.length);
    Formatter localFormatter = new Formatter(localStringBuilder);
    int i = paramArrayOfByte.length;
    for (int j = 0; j < i; j++) {
        byte b = paramArrayOfByte[j];
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = Byte.valueOf(b);
        localFormatter.format("%02x", arrayOfObject);
    }/* w ww.j a va 2 s  . c o  m*/
    localFormatter.close();
    return localStringBuilder.toString();
}

From source file:Main.java

public static String toHexCode(byte[] data) {
    StringBuilder stringBuilder = new StringBuilder(data.length * SECOND_BITMASK);
    int length = data.length;
    for (int i = EventIDNotificationAdded; i < length; i += FIRST_BITMASK) {
        Object[] objArr = new Object[FIRST_BITMASK];
        objArr[EventIDNotificationAdded] = Byte.valueOf(data[i]);
        stringBuilder.append(String.format("%02X", objArr));
    }/*w  w  w .jav  a 2 s .co m*/
    return stringBuilder.toString();
}

From source file:Main.java

/**
 * Helper method used to get default value for wrappers used for primitive types
 * (0 for Integer etc)//from w w w .j  a v  a 2 s .com
 */
public static Object defaultValue(Class<?> cls) {
    if (cls == Integer.TYPE) {
        return Integer.valueOf(0);
    }
    if (cls == Long.TYPE) {
        return Long.valueOf(0L);
    }
    if (cls == Boolean.TYPE) {
        return Boolean.FALSE;
    }
    if (cls == Double.TYPE) {
        return Double.valueOf(0.0);
    }
    if (cls == Float.TYPE) {
        return Float.valueOf(0.0f);
    }
    if (cls == Byte.TYPE) {
        return Byte.valueOf((byte) 0);
    }
    if (cls == Short.TYPE) {
        return Short.valueOf((short) 0);
    }
    if (cls == Character.TYPE) {
        return '\0';
    }
    throw new IllegalArgumentException("Class " + cls.getName() + " is not a primitive type");
}

From source file:Main.java

public static String MD5(String paramString) {
    if (paramString == null)
        return null;
    try {// w w w  .  j a v  a 2 s. c om
        byte[] arrayOfByte1 = paramString.getBytes();
        MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
        localMessageDigest.reset();
        localMessageDigest.update(arrayOfByte1);
        byte[] arrayOfByte2 = localMessageDigest.digest();
        StringBuffer localStringBuffer = new StringBuffer();
        for (int i = 0; i < arrayOfByte2.length; i++) {
            Object[] arrayOfObject = new Object[1];
            arrayOfObject[0] = Byte.valueOf(arrayOfByte2[i]);
            localStringBuffer.append(String.format("%02X", arrayOfObject));
        }
        String str = localStringBuffer.toString();
        return str;
    } catch (Exception localException) {
    }
    return paramString.replaceAll("[^[a-z][A-Z][0-9][.][_]]", "");
}

From source file:org.yestech.lib.net.InternetAddress.java

public static InetAddress createIp4Address(String address) {
    String[] tempOctects = StringUtils.split(address, ".");
    if (tempOctects.length == 4) {
        byte[] octets = new byte[4];
        for (int i = 0; i < tempOctects.length; i++) {
            String tempOctect = tempOctects[i];
            octets[i] = Byte.valueOf(tempOctect);
        }//  w  w  w.  j a  v a 2s  .  co  m
        try {
            return InetAddress.getByAddress(octets);
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new IllegalArgumentException("not a valid ip4 address");
    }
}

From source file:Main.java

static byte byteElement(Element row, String name) {
    return Byte.valueOf(stringElement(row, name)).byteValue();
}