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:com.lyft.hive.serde.DynamoDbSerDe.java

@Override
public Object deserialize(Writable blob) throws SerDeException {
    ArrayList<Object> row = buildRow();
    Text rowText = (Text) blob;
    Map<String, String> values = decomposeRow(rowText.toString());

    for (int c = 0; c < numColumns; c++) {
        try {/*ww w  .  j  a v a 2s .  c o m*/
            String t = values.get(columnNames.get(c));
            TypeInfo typeInfo = columnTypes.get(c);

            // Convert the column to the correct type when needed and set in row obj
            PrimitiveTypeInfo pti = (PrimitiveTypeInfo) typeInfo;
            switch (pti.getPrimitiveCategory()) {
            case STRING:
                row.set(c, t);
                break;
            case BYTE:
                Byte b;
                b = Byte.valueOf(t);
                row.set(c, b);
                break;
            case SHORT:
                Short s;
                s = Short.valueOf(t);
                row.set(c, s);
                break;
            case INT:
                Integer i;
                i = Integer.valueOf(t);
                row.set(c, i);
                break;
            case LONG:
                Long l;
                l = Long.valueOf(t);
                row.set(c, l);
                break;
            case FLOAT:
                Float f;
                f = Float.valueOf(t);
                row.set(c, f);
                break;
            case DOUBLE:
                Double d;
                d = Double.valueOf(t);
                row.set(c, d);
                break;
            case BOOLEAN:
                Boolean bool;
                bool = Boolean.valueOf(t);
                row.set(c, bool);
                break;
            case TIMESTAMP:
                row.set(c, parseTimestamp(t));
                break;
            case DATE:
                Date date;
                date = Date.valueOf(t);
                row.set(c, date);
                break;
            case DECIMAL:
                HiveDecimal bd = HiveDecimal.create(t);
                row.set(c, bd);
                break;
            case CHAR:
                HiveChar hc = new HiveChar(t, ((CharTypeInfo) typeInfo).getLength());
                row.set(c, hc);
                break;
            case VARCHAR:
                HiveVarchar hv = new HiveVarchar(t, ((VarcharTypeInfo) typeInfo).getLength());
                row.set(c, hv);
                break;
            default:
                throw new SerDeException("Unsupported type " + typeInfo);
            }
        } catch (RuntimeException e) {
            row.set(c, null);
        }
    }
    return row;
}

From source file:com.neovisionaries.security.DigestTest.java

@Test
public void test10() {
    ByteBuffer byteBuffer = ByteBuffer.allocate(10);
    byteBuffer.put(new byte[] { 1, 2, 3, 4, 5 });
    byteBuffer.flip();/*from w  ww . j a  v  a 2 s  .  c om*/

    // Ensure there is no infinite loop.
    Digest.getInstanceSHA256().update("Hello, world.", new String[] { "Hello", "world" },

            Boolean.TRUE, new boolean[] { true, false }, new Boolean[] { Boolean.TRUE, Boolean.FALSE },

            Byte.valueOf((byte) 0), new byte[] { (byte) 0, (byte) 1 },
            new Byte[] { Byte.valueOf((byte) 0), Byte.valueOf((byte) 1) }, byteBuffer,

            Character.valueOf('b'), new char[] { 'a', 'b' },
            new Character[] { Character.valueOf('a'), Character.valueOf('b') },

            Double.valueOf(0.0), new double[] { 0.0, 1.0 },
            new Double[] { Double.valueOf(0.0), Double.valueOf(1.0) },

            Float.valueOf(0.0F), new float[] { 0.0F, 1.0F },
            new Float[] { Float.valueOf(0.0F), Float.valueOf(1.0F) },

            Integer.valueOf(1), new int[] { 1, 2 }, new Integer[] { Integer.valueOf(0), Integer.valueOf(1) },

            Long.valueOf(0L), new long[] { 0L, 1L }, new Long[] { Long.valueOf(0L), Long.valueOf(1L) },

            Short.valueOf((short) 0), new short[] { (short) 0, (short) 1 },
            new Short[] { Short.valueOf((short) 0), Short.valueOf((short) 1) },

            new Object[] { new boolean[] { true, false }, new byte[] { (byte) 0, (byte) 1 } },
            new Object[] { new Object[] { new char[] { 'a', 'b' }, new short[] { 10, 20 } },
                    new Object[] { new float[] { 1.0F, 2.0F }, new double[] { 3.0, 4.0 } } });

    assertTrue(true);
}

From source file:org.op4j.functions.FnObject.java

/**
 * <p>/*from ww w. java 2s  .c o  m*/
 * Determines whether the target object and the specified object are equal
 * by calling the <tt>equals</tt> method on the target object.
 * </p>
 * 
 * @param object the object to compare to the target
 * @return true if both objects are equal, false if not.
 */
public static final Function<Object, Boolean> eq(final byte object) {
    return new Equals(Byte.valueOf(object));
}

From source file:br.com.fabiopereira.quebrazip.JavaZipSplitter.java

private static void invertArrayBytes(byte[] bytes) {
    Object[] objs = new Object[bytes.length];
    for (int i = 0; i < bytes.length; i++) {
        objs[i] = Byte.valueOf(bytes[i]);
    }/*w w  w  .  j  a  v a  2 s.c o  m*/
    CollectionUtils.reverseArray(objs);
    for (int i = 0; i < bytes.length; i++) {
        bytes[i] = (Byte) objs[i];
    }
}

From source file:org.apache.syncope.client.console.wicket.markup.html.form.AjaxSpinnerFieldPanel.java

@SuppressWarnings("rawtypes")
@Override/*from  w ww.  j  a va  2s .c om*/
public AjaxSpinnerFieldPanel<T> setNewModel(final ListItem item) {
    field.setModel(new Model<T>() {

        private static final long serialVersionUID = 6799404673615637845L;

        @Override
        public T getObject() {
            T number = null;

            final Object obj = item.getModelObject();

            if (obj != null && !obj.toString().isEmpty()) {
                if (obj instanceof String) {
                    number = reference.equals(Integer.class) ? reference.cast(Integer.valueOf((String) obj))
                            : reference.equals(Long.class) ? reference.cast(Long.valueOf((String) obj))
                                    : reference.equals(Short.class)
                                            ? reference.cast(Short.valueOf((String) obj))
                                            : reference.equals(Float.class)
                                                    ? reference.cast(Float.valueOf((String) obj))
                                                    : reference.equals(byte.class)
                                                            ? reference.cast(Byte.valueOf((String) obj))
                                                            : reference.cast(Double.valueOf((String) obj));
                } else if (obj instanceof Number) {
                    // Don't parse anything
                    number = reference.cast(obj);
                }
            }

            return number;
        }

        @Override
        @SuppressWarnings("unchecked")
        public void setObject(final T object) {
            item.setModelObject(object == null ? null : object.toString());
        }
    });

    return this;
}

From source file:StorageEngineClient.FormatStorageIRecordReader.java

@Override
public boolean next(LongWritable key, IRecord value) throws IOException {
    if (currentrec >= recnum)
        return false;
    key.set(currentrec);//from  w w  w  .  ja v  a 2 s. com
    if (!isGZ) {
        if (!ifdf.next(value)) {
            String err = "FSIR error read:\t" + this.file + ":\tcurrentrec\t" + currentrec + "\trecnum\t"
                    + recnum + "\tbeginline\t" + this.beginline + "\r\nvalue" + value.showstr();
            throw new IOException(err);
        }
    } else {
        try {
            int newSize = in.readLine(tValue);
            if (newSize == 0) {
                return false;
            }
        } catch (Exception e) {
            return false;
        }
        StringTokenizer stk = new StringTokenizer(tValue.toString(), new String(new char[] { '\01' }));
        int j = 0;
        while (stk.hasMoreTokens()) {
            IRecord.IFType type = this.fieldtypes.get(j);
            String str = stk.nextToken();
            if (!str.equals("\\N")) {
                if (type.type() == ConstVar.FieldType_Byte)
                    value.addFieldValue(new IRecord.IFValue(Byte.valueOf(str), j));
                else if (type.type() == ConstVar.FieldType_Short)
                    value.addFieldValue(new IRecord.IFValue(Short.valueOf(str), j));
                else if (type.type() == ConstVar.FieldType_Int)
                    value.addFieldValue(new IRecord.IFValue(Integer.valueOf(str), j));
                else if (type.type() == ConstVar.FieldType_Long)
                    value.addFieldValue(new IRecord.IFValue(Long.valueOf(str), j));
                else if (type.type() == ConstVar.FieldType_Float)
                    value.addFieldValue(new IRecord.IFValue(Float.valueOf(str), j));
                else if (type.type() == ConstVar.FieldType_Double)
                    value.addFieldValue(new IRecord.IFValue(Double.valueOf(str), j));
                else if (type.type() == ConstVar.FieldType_String) {
                    if (str.equals("\\NN")) {
                        value.addFieldValue(new IRecord.IFValue("", j));

                    } else {
                        value.addFieldValue(new IRecord.IFValue(str, j));
                    }
                }
            } else {
                value.setNull(j);
            }
            j++;
        }

    }
    currentrec++;
    return true;
}

From source file:cn.ctyun.amazonaws.util.XpathUtils.java

/**
 * Evaluates the specified XPath expression and returns the result as a
 * Byte./*from  w ww .j av a  2  s  .  c o  m*/
 *
 * @param expression
 *            The XPath expression to evaluate.
 * @param node
 *            The node to run the expression on.
 *
 * @return The Byte result.
 *
 * @throws XPathExpressionException
 *             If there was a problem processing the specified XPath
 *             expression.
 */
public static Byte asByte(String expression, Node node) throws XPathExpressionException {
    String byteString = evaluateAsString(expression, node);
    return (isEmptyString(byteString)) ? null : Byte.valueOf(byteString);
}

From source file:org.crazydog.util.spring.NumberUtils.java

/**
 * Parse the given text into a number instance of the given target class,
 * using the corresponding {@code decode} / {@code valueOf} methods.
 * <p>Trims the input {@code String} before attempting to parse the number.
 * Supports numbers in hex format (with leading "0x", "0X" or "#") as well.
 *
 * @param text        the text to convert
 * @param targetClass the target class to parse into
 * @return the parsed number/*from  w w w .  ja  v  a  2s .  c o m*/
 * @throws IllegalArgumentException if the target class is not supported
 *                                  (i.e. not a standard Number subclass as included in the JDK)
 * @see Byte#decode
 * @see Short#decode
 * @see Integer#decode
 * @see Long#decode
 * @see #decodeBigInteger(String)
 * @see Float#valueOf
 * @see Double#valueOf
 * @see BigDecimal#BigDecimal(String)
 */
@SuppressWarnings("unchecked")
public static <T extends Number> T parseNumber(String text, Class<T> targetClass) {
    org.springframework.util.Assert.notNull(text, "Text must not be null");
    org.springframework.util.Assert.notNull(targetClass, "Target class must not be null");
    String trimmed = StringUtils.trimAllWhitespace(text);

    if (Byte.class == targetClass) {
        return (T) (isHexNumber(trimmed) ? Byte.decode(trimmed) : Byte.valueOf(trimmed));
    } else if (Short.class == targetClass) {
        return (T) (isHexNumber(trimmed) ? Short.decode(trimmed) : Short.valueOf(trimmed));
    } else if (Integer.class == targetClass) {
        return (T) (isHexNumber(trimmed) ? Integer.decode(trimmed) : Integer.valueOf(trimmed));
    } else if (Long.class == targetClass) {
        return (T) (isHexNumber(trimmed) ? Long.decode(trimmed) : Long.valueOf(trimmed));
    } else if (BigInteger.class == targetClass) {
        return (T) (isHexNumber(trimmed) ? decodeBigInteger(trimmed) : new BigInteger(trimmed));
    } else if (Float.class == targetClass) {
        return (T) Float.valueOf(trimmed);
    } else if (Double.class == targetClass) {
        return (T) Double.valueOf(trimmed);
    } else if (BigDecimal.class == targetClass || Number.class == targetClass) {
        return (T) new BigDecimal(trimmed);
    } else {
        throw new IllegalArgumentException(
                "Cannot convert String [" + text + "] to target class [" + targetClass.getName() + "]");
    }
}

From source file:org.apache.syncope.console.wicket.markup.html.form.SpinnerFieldPanel.java

@SuppressWarnings("rawtypes")
@Override// ww w . j  a va 2  s . c  o  m
public SpinnerFieldPanel<T> setNewModel(final ListItem item) {
    field.setModel(new Model<T>() {

        private static final long serialVersionUID = 6799404673615637845L;

        @Override
        public T getObject() {
            T number = null;

            final Object obj = item.getModelObject();

            if (obj != null && !obj.toString().isEmpty()) {
                if (obj instanceof String) {
                    number = reference.equals(Integer.class) ? reference.cast(Integer.valueOf((String) obj))
                            : reference.equals(Long.class) ? reference.cast(Short.valueOf((String) obj))
                                    : reference.equals(Short.class) ? reference.cast(Long.valueOf((String) obj))
                                            : reference.equals(Float.class)
                                                    ? reference.cast(Float.valueOf((String) obj))
                                                    : reference.equals(byte.class)
                                                            ? reference.cast(Byte.valueOf((String) obj))
                                                            : reference.cast(Double.valueOf((String) obj));
                } else if (obj instanceof Number) {
                    // Don't parse anything
                    number = reference.cast(obj);
                }
            }

            return number;
        }

        @Override
        @SuppressWarnings("unchecked")
        public void setObject(final T object) {
            item.setModelObject(object == null ? null : object.toString());
        }
    });

    return this;
}

From source file:it.unimi.dsi.util.Properties.java

public void addProperty(final Enum<?> key, final byte b) {
    super.addProperty(key.name().toLowerCase(), Byte.valueOf(b));
}