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:org.red5.io.mock.Output.java

/** {@inheritDoc} */ // DONE
public void writeNull() {
    list.add(Byte.valueOf(DataTypes.CORE_NULL));
}

From source file:org.lingcloud.molva.ocl.util.GenericTypeValidator.java

/**
 * Checks if the value can safely be converted to a byte primitive.
 * //from ww  w  .j  ava  2 s  . co m
 * @param value
 *            The value validation is being performed on.
 * @param locale
 *            The locale to use to parse the number (system default if null)
 * @return the converted Byte value.
 */
public static Byte formatByte(String value, Locale locale) {
    Byte result = null;

    if (value != null) {
        NumberFormat formatter = null;
        if (locale != null) {
            formatter = NumberFormat.getNumberInstance(locale);
        } else {
            formatter = NumberFormat.getNumberInstance(Locale.getDefault());
        }
        formatter.setParseIntegerOnly(true);
        ParsePosition pos = new ParsePosition(0);
        Number num = formatter.parse(value, pos);

        // If there was no error and we used the whole string
        if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
            if (num.doubleValue() >= Byte.MIN_VALUE && num.doubleValue() <= Byte.MAX_VALUE) {
                result = Byte.valueOf(num.byteValue());
            }
        }
    }

    return result;
}

From source file:com.alibaba.dubboadmin.web.mvc.RouterController.java

private Object convertPrimitive(Class<?> cls, String value) {
    if (cls == boolean.class || cls == Boolean.class) {
        return value == null || value.length() == 0 ? false : Boolean.valueOf(value);
    } else if (cls == byte.class || cls == Byte.class) {
        return value == null || value.length() == 0 ? 0 : Byte.valueOf(value);
    } else if (cls == char.class || cls == Character.class) {
        return value == null || value.length() == 0 ? '\0' : value.charAt(0);
    } else if (cls == short.class || cls == Short.class) {
        return value == null || value.length() == 0 ? 0 : Short.valueOf(value);
    } else if (cls == int.class || cls == Integer.class) {
        return value == null || value.length() == 0 ? 0 : Integer.valueOf(value);
    } else if (cls == long.class || cls == Long.class) {
        return value == null || value.length() == 0 ? 0 : Long.valueOf(value);
    } else if (cls == float.class || cls == Float.class) {
        return value == null || value.length() == 0 ? 0 : Float.valueOf(value);
    } else if (cls == double.class || cls == Double.class) {
        return value == null || value.length() == 0 ? 0 : Double.valueOf(value);
    }/*from   www . j  av a 2 s .c om*/
    return value;
}

From source file:de.weltraumschaf.registermachine.asm.Assembler.java

/**
 * Creates the byte code header.//from  w w w .j  av a 2s .c om
 *
 * @param sourceFileName
 * @return liste of bytes
 * @throws UnsupportedEncodingException
 */
private List<Byte> createByteCodeWithHeader(final String sourceFileName) throws UnsupportedEncodingException {
    final List<Byte> bytecode = Lists.newArrayList();
    bytecode.add(Byte.valueOf(ByteCodeStream.BC_FST_HEADER_BYTE));
    bytecode.add(Byte.valueOf(ByteCodeStream.BC_SND_HEADER_BYTE));
    final byte[] version = ByteInteger.bytesFromShort(ByteCodeStream.BC_CURRENT_VERSION);
    bytecode.addAll(Bytes.asList(version));
    final byte[] filename = ByteString.bytesFromString(sourceFileName);
    final byte[] filenameLength = ByteInteger.bytesFromInt(filename.length);
    bytecode.addAll(Bytes.asList(filenameLength));
    bytecode.addAll(Bytes.asList(filename));
    return bytecode;
}

From source file:controller.PackageManagerController.java

@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
public String editPackage(@PathVariable(value = "id") String id, ModelMap mm) {
    Packages packages = packageModel.getByID(Integer.parseInt(id));
    if (packages == null) {
        packages = new Packages();
        packages.setStatus(Byte.valueOf("1"));
    }//from  www.  ja v a  2  s . co  m
    mm.addAttribute("packages", packages);
    List<Chanel> listChanel = chanelModel.getAll();

    mm.put("listChanel", listChanel);
    return "editPackage";
}

From source file:org.apache.tinkerpop.gremlin.process.computer.util.VertexProgramHelper.java

public static <T> T deserialize(final Configuration configuration, final String key) {
    try {//from  w  ww  .  j  av a  2 s . co  m
        final String[] stringBytes = configuration.getString(key).split(",");
        byte[] bytes = new byte[stringBytes.length];
        for (int i = 0; i < stringBytes.length; i++) {
            bytes[i] = Byte.valueOf(stringBytes[i].trim());
        }
        return (T) Serializer.deserializeObject(bytes);
    } catch (final IOException | ClassNotFoundException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}

From source file:controller.FeedbackControllerManager.java

@RequestMapping(value = "/process", method = RequestMethod.POST)
public String processFeedback(HttpServletRequest req, ModelMap mm, @ModelAttribute Feedback feed) {
    try {/*from ww w  .j a v  a 2  s  .c  om*/
        String contextPath = req.getContextPath();
        feed.setStatus(Byte.valueOf("1"));
        mm.put("check", feedModel.addOrUpdate(feed));
        mm.put("alert", "Feedback Updated");
        mm.put("link", contextPath + "/admin/feedbackManager.html");

    } catch (Exception ex) {
        ex.printStackTrace();
        mm.put("err", ex.getMessage());
    }
    return "processFeedback";
}

From source file:org.red5.io.mock.Output.java

/** {@inheritDoc} */ // DONE
public void writeNumber(Number num) {
    list.add(Byte.valueOf(DataTypes.CORE_NUMBER));
    list.add(num);
}

From source file:controller.DistributorManagerController.java

@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
public String editDistributor(@PathVariable(value = "id") int id, ModelMap mm) {
    Distributor dis = disModel.getByID(id);
    if (dis == null) {
        dis = new Distributor();
        dis.setStatus(Byte.valueOf("1"));
    }/*from  ww  w .  jav a  2s. c om*/
    mm.addAttribute("distributor", dis);
    return "editDistributor";
}

From source file:org.mule.util.NumberUtils.java

@SuppressWarnings("unchecked")
public static <T extends Number> T parseNumber(String text, Class<T> targetClass) {
    text = text.trim();//from  ww  w .  j a v  a 2 s  .c o  m

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