Example usage for java.lang Byte Byte

List of usage examples for java.lang Byte Byte

Introduction

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

Prototype

@Deprecated(since = "9")
public Byte(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Byte object that represents the byte value indicated by the String parameter.

Usage

From source file:Main.java

public static ArrayList<Byte> toByteArray(byte[] data) {
    ArrayList<Byte> rval = new ArrayList<>(data.length);
    for (int i = 0; i < data.length; i++) {
        rval.add(i, new Byte(data[i]));
    }//  w  w  w  .  j av  a 2  s.c  o  m
    return rval;
}

From source file:Main.java

public static int[] byte2int(byte[] src, int height, int width) {
    int dstLength = src.length;
    int[] dst = new int[dstLength];

    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            Byte b = new Byte(src[height * (143 - j) + i]);
            dst[(width * i) + j] = b.intValue() & 0x000000ff;
            if (dst[(width * i) + j] < 0) {
                System.out.println(dst[(width * i) + j]);
            }//from ww w. java 2s.c om
        }
    }
    return dst;
}

From source file:Main.java

public static Byte toByteObject(String value, Byte defaultValue) {
    try {/*w ww  .  j  av  a  2  s .  co m*/
        return new Byte(value);
    } catch (Exception e) {
        return defaultValue;
    }
}

From source file:Main.java

/**
 * Returns the Md5 hash for the given text.
 * /*from w w w .java2  s . c  o  m*/
 * @param text
 *            String whose Md5 hash should be returned.
 * @return Returns the Md5 hash for the given text.
 */
public static String getMd5Hash(String text) {
    StringBuffer result = new StringBuffer(32);
    try {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(text.getBytes());
        Formatter f = new Formatter(result);

        byte[] digest = md5.digest();

        for (int i = 0; i < digest.length; i++) {
            f.format("%02x", new Object[] { new Byte(digest[i]) });
        }
    } catch (NoSuchAlgorithmException ex) {
        ex.printStackTrace();
    }

    return result.toString();
}

From source file:org.goko.core.common.GkUtils.java

public static List<Byte> toBytesList(String... strings) {
    List<Byte> lst = new ArrayList<Byte>();
    if (strings != null) {
        for (String str : strings) {
            for (byte b : str.getBytes()) {
                lst.add(new Byte(b));
            }/* ww w .j a  v a2 s.c o  m*/
        }
    }
    return lst;
}

From source file:de.odysseus.calyxo.base.util.ParseUtils.java

private static Object nullValue(Class type) {
        if (type.isPrimitive()) {
            if (type == boolean.class)
                return Boolean.FALSE;
            if (type == byte.class)
                return new Byte((byte) 0);
            if (type == char.class)
                return new Character((char) 0);
            if (type == short.class)
                return new Short((short) 0);
            if (type == int.class)
                return new Integer(0);
            if (type == long.class)
                return new Long(0);
            if (type == float.class)
                return new Float(0);
            if (type == double.class)
                return new Double(0);
        }//from   w ww . j  a  v  a 2s .c  o m
        return null;
    }

From source file:com.pfarrell.crypto.HmacUtil.java

/**
 * toHexes the given bytes array, and returns it.
 * @param buf input byte buffer/*  ww  w . j a  v a 2 s.  c o  m*/
 * @return  hexified result
 */
public static String hexify(byte[] buf) {
    Preconditions.checkNotNull(buf);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < buf.length; i++) {
        Byte b = new Byte(buf[i]);
        String s = Integer.toHexString(b.intValue());
        if (s.length() == 1)
            s = "0" + s;
        if (s.length() > 2)
            s = s.substring(s.length() - 2);
        sb.append(s);
    }
    return sb.toString();
}

From source file:org.goko.core.common.GkUtils.java

public static List<Byte> toBytesList(byte[] arr) {
    List<Byte> lst = new ArrayList<Byte>();
    if (arr != null) {
        for (int i = 0; i < arr.length; i++) {
            lst.add(new Byte(arr[i]));
        }/*from   ww w  .ja  v  a2  s  . c o  m*/
    }
    return lst;
}

From source file:com.jeeframework.util.validate.GenericTypeValidator.java

/**
 *  Checks if the value can safely be converted to a byte primitive.
 *
 *@param  value  The value validation is being performed on.
 *@return the converted Byte value.// ww w. j  a v a  2s.  c  om
 */
public static Byte formatByte(String value) {
    if (value == null) {
        return null;
    }

    try {
        return new Byte(value);
    } catch (NumberFormatException e) {
        return null;
    }

}

From source file:com.jaspersoft.studio.editor.preview.input.array.number.ByteElement.java

@Override
protected Object convertString(String str) {
    return new Byte(str);
}