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:org.shampoo.goldenembed.parser.GoldenEmbedParserMain.java

private boolean ANTrxHandler(byte[] rxBuf, GoldenCheetah gc) {
    int msgN = 0;
    int i;/* w ww. jav a2 s  .  c  o m*/
    int size = 0;
    boolean inMsg = true;
    boolean errorFlag = true;

    for (i = 0; i < rxBuf.length; i++) {
        if (rxBuf[i] == MESG_TX_SYNC && inMsg) {
            inMsg = false;
            msgN = 0; // Always reset msg count if we get a sync
            msgN++;
            errorFlag = false;
            totalTrans++;
            if (megaDebug)
                System.out.println("RX: [sync]");
        } else if (msgN == 1) {
            Byte aByte = new Byte(rxBuf[i]);
            msgN++; // Size
            size = aByte.intValue();
        } else if (msgN == 2) {
            byte checksum = checkSum(rxBuf, size);
            if (checksum == rxBuf[size + 3]) // Check if chksum = msg
            // chksum
            {
                inMsg = true;
                // Handle Message
                ANTrxMsg(rxBuf, size, gc);
                msgN++;
                break;
            } else {
                if (megaDebug)
                    System.out.println("CheckSum Mismatch 0x" + UnicodeFormatter.byteToHex(rxBuf[size + 3])
                            + "!=: 0x" + UnicodeFormatter.byteToHex(checksum));
                msgN = 0;
                inMsg = true;
                totalChecksumError++;
                errorFlag = true;
                return errorFlag;
            }
        } else
            return errorFlag;
    }
    return errorFlag;
}

From source file:org.floggy.synchronization.jme.core.impl.JSONSerializationManager.java

protected static Object fromJSON(JSONObject jsonObject) throws Exception {
    String className = jsonObject.getString("className");

    if (className.equals("java.lang.String")) {
        return jsonObject.getString("value");
    } else if (className.equals("java.lang.Byte")) {
        return new Byte((byte) jsonObject.getInt("value"));
    } else {/*from   w w w . j  a  va2  s. c  om*/
        throw new SynchronizationException(className + " not supported!");
    }
}

From source file:net.sf.json.TestJSONObject.java

public void testFromBean_use_wrappers() {
    JSONObject json = JSONObject.fromObject(Boolean.TRUE);
    assertTrue(json.isEmpty());/*www. ja  v  a 2 s .  co m*/
    json = JSONObject.fromObject(new Byte(Byte.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Short(Short.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Integer(Integer.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Long(Long.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Float(Float.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Double(Double.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Character('A'));
    assertTrue(json.isEmpty());
}

From source file:com.jaspersoft.jasperserver.war.action.ReportJobEditAction.java

public Event setTriggerReferenceData(RequestContext context) throws Exception {
    context.getRequestScope().put(getIntervalUnitsAttrName(), recurrenceIntervalUnits);

    ReportJob reportJob = getReportJob(context);
    byte triggerRecurrenceType = getTriggerRecurrenceType(reportJob.getTrigger());
    context.getRequestScope().put(ATTR_NAME_TRIGGER_RECURRENCE_TYPE, new Byte(triggerRecurrenceType));

    if (triggerRecurrenceType == RECURRENCE_TYPE_CALENDAR) {
        context.getRequestScope().put(ATTR_NAME_TRIGGER_ALL_WEEK_DAYS, weekDays);
        context.getRequestScope().put(ATTR_NAME_TRIGGER_ALL_MONTHS, months);
    }/* w w w  .ja va  2 s.  co m*/

    setTimeZoneData(context);
    return success();
}

From source file:com.twinsoft.convertigo.eclipse.learnproxy.http.HttpProxyWorker.java

private List<Byte> getAllChunks(BufferedInputStream inStream, BufferedOutputStream proxyClientStream)
        throws IOException {
    ArrayList<Byte> retList = new ArrayList<Byte>(10000);
    List<Byte> chunk;
    while (!isInterrupted && (chunk = getChunk(inStream, proxyClientStream)).size() != 0) {
        retList.addAll(chunk);/*w w w  .ja  v  a  2  s.  c  o  m*/
    }
    // dirty hack:
    byte[] appendBytes = "0\r\n".getBytes("ISO-8859-1");
    for (int i = 0; i < appendBytes.length; i++) {
        retList.add(new Byte(appendBytes[i]));
        proxyClientStream.write((int) appendBytes[i]);
    }
    return retList;
}

From source file:org.xenei.jdbc4sparql.iface.TypeConverter.java

private static <T> T fromString(final Object columnObject, final Class<T> resultingClass) throws SQLException {
    final String val = String.class.cast(columnObject);
    // to numeric casts
    try {//from  w w w.  ja  va 2 s. c om
        if (resultingClass == BigDecimal.class) {
            return resultingClass.cast(new BigDecimal(val));
        }
        if (resultingClass == BigInteger.class) {
            return resultingClass.cast(new BigInteger(val));
        }
        if (resultingClass == Byte.class) {
            return resultingClass.cast(new Byte(val));
        }
        if (resultingClass == Double.class) {
            return resultingClass.cast(new Double(val));
        }
        if (resultingClass == Float.class) {
            return resultingClass.cast(new Float(val));
        }
        if (resultingClass == Integer.class) {
            return resultingClass.cast(new Integer(val));
        }
        if (resultingClass == Long.class) {
            return resultingClass.cast(new Long(val));
        }
        if (resultingClass == Short.class) {
            return resultingClass.cast(new Short(val));
        }
    } catch (final NumberFormatException e) {
        return null;
    }

    if (resultingClass == Boolean.class) {
        if ("0".equals(val)) {
            return resultingClass.cast(Boolean.FALSE);
        }
        if ("1".equals(val)) {
            return resultingClass.cast(Boolean.TRUE);
        }
    }
    if (resultingClass == byte[].class) {
        return resultingClass.cast(val.getBytes());
    }
    if (resultingClass == Blob.class) {
        return resultingClass.cast(new SerialBlob(val.getBytes()));
    }
    if (resultingClass == Clob.class) {
        return resultingClass.cast(new SerialClob(val.toCharArray()));
    }
    return null;
}

From source file:org.latticesoft.util.container.PropertyMap.java

/**
 * Sets an byte value/*from w w w . j ava  2s  . c  o m*/
 * @param key the key of the attribute
 * @param the value of the attribute
 */
public void setByte(Object key, byte value) {
    if (key == null)
        return;
    Byte object = new Byte(value);
    this.put(key, object);
}

From source file:org.goko.controller.tinyg.controller.TinyGCommunicator.java

/**
 * Add the end line character at the end of the given list
 * @param list the list//from  w w w . ja  v a 2 s  . com
 */
private void addEndLineCharacter(List<Byte> list) {
    list.add(new Byte((byte) endLineCharDelimiter));
}

From source file:org.floggy.synchronization.jme.core.impl.JSONSerializationManagerTest.java

/**
* DOCUMENT ME!//from ww  w  .j a va2 s .  c o  m
*
* @throws Exception DOCUMENT ME!
*/
public void testSendHashtableNotNull() throws Exception {
    JSONStringer stringer = new JSONStringer();
    String name = "firstName";
    Hashtable value = new Hashtable();

    Calendar c1 = Calendar.getInstance();
    c1.setTimeZone(TimeZone.getTimeZone("America/Sao_Paulo"));
    c1.setTime(new Date(1234567890));

    Calendar c2 = Calendar.getInstance();
    c2.setTimeZone(TimeZone.getTimeZone("America/Sao_Paulo"));
    c2.setTime(new Date(1234567890));

    value.put(Boolean.TRUE, Boolean.TRUE);
    value.put(new Byte((byte) 90), new Byte((byte) 90));
    value.put(new Character('2'), new Character('2'));
    value.put(new Double(23d), new Double(23d));
    value.put(new Float(45f), new Float(45f));
    value.put(new Integer(87), new Integer(87));
    value.put(new Long(89), new Long(89));
    value.put(new Short((short) 78), new Short((short) 78));
    value.put("key", "value");
    value.put(new Date(1234567890), new Date(9876543221L));
    value.put(c1, c2);
    value.put(TimeZone.getTimeZone("America/Sao_Paulo"), TimeZone.getTimeZone("America/Sao_Paulo"));

    stringer.object();
    JSONSerializationManager.sendHashtable(name, value, stringer);
    stringer.endObject();

    String expected = "{\"firstName\":[{\"key\":{\"className\":\"java.lang.Byte\",\"value\":90},\"value\":{\"className\":\"java.lang.Byte\",\"value\":90}},{\"key\":{\"className\":\"java.lang.Long\",\"value\":89},\"value\":{\"className\":\"java.lang.Long\",\"value\":89}},{\"key\":{\"className\":\"java.lang.Float\",\"value\":45},\"value\":{\"className\":\"java.lang.Float\",\"value\":45}},{\"key\":{\"className\":\"java.util.Date\",\"value\":{\"time\":1234567890}},\"value\":{\"className\":\"java.util.Date\",\"value\":{\"time\":9876543221}}},{\"key\":{\"className\":\"java.lang.Integer\",\"value\":87},\"value\":{\"className\":\"java.lang.Integer\",\"value\":87}},{\"key\":{\"className\":\"java.lang.Double\",\"value\":23},\"value\":{\"className\":\"java.lang.Double\",\"value\":23}},{\"key\":{\"className\":\"java.lang.Boolean\",\"value\":true},\"value\":{\"className\":\"java.lang.Boolean\",\"value\":true}},{\"key\":{\"className\":\"java.util.TimeZone\",\"value\":{\"ID\":\"America/Sao_Paulo\"}},\"value\":{\"className\":\"java.util.TimeZone\",\"value\":{\"ID\":\"America/Sao_Paulo\"}}},{\"key\":{\"className\":\"java.lang.Short\",\"value\":78},\"value\":{\"className\":\"java.lang.Short\",\"value\":78}},{\"key\":{\"className\":\"java.util.Calendar\",\"value\":{\"timeZone\":{\"ID\":\"America/Sao_Paulo\"},\"time\":1234567890}},\"value\":{\"className\":\"java.util.Calendar\",\"value\":{\"timeZone\":{\"ID\":\"America/Sao_Paulo\"},\"time\":1234567890}}},{\"key\":{\"className\":\"java.lang.Character\",\"value\":\"2\"},\"value\":{\"className\":\"java.lang.Character\",\"value\":\"2\"}},{\"key\":{\"className\":\"java.lang.String\",\"value\":\"key\"},\"value\":{\"className\":\"java.lang.String\",\"value\":\"value\"}}]}";

    assertEquals(expected, stringer.toString());
}

From source file:com.ebay.nest.io.sede.lazy.LazySimpleSerDe.java

/**
 * Serialize the row into the StringBuilder.
 *
 * @param out/* w ww . ja v  a 2  s . c  o  m*/
 *          The StringBuilder to store the serialized data.
 * @param obj
 *          The object for the current field.
 * @param objInspector
 *          The ObjectInspector for the current Object.
 * @param separators
 *          The separators array.
 * @param level
 *          The current level of separator.
 * @param nullSequence
 *          The byte sequence representing the NULL value.
 * @param escaped
 *          Whether we need to escape the data when writing out
 * @param escapeChar
 *          Which char to use as the escape char, e.g. '\\'
 * @param needsEscape
 *          Which chars needs to be escaped. This array should have size of
 *          128. Negative byte values (or byte values >= 128) are never
 *          escaped.
 * @throws IOException
 * @throws SerDeException
 */
public static void serialize(ByteStream.Output out, Object obj, ObjectInspector objInspector, byte[] separators,
        int level, Text nullSequence, boolean escaped, byte escapeChar, boolean[] needsEscape)
        throws IOException, SerDeException {

    if (obj == null) {
        out.write(nullSequence.getBytes(), 0, nullSequence.getLength());
        return;
    }

    char separator;
    List<?> list;
    switch (objInspector.getCategory()) {
    case PRIMITIVE:
        LazyUtils.writePrimitiveUTF8(out, obj, (PrimitiveObjectInspector) objInspector, escaped, escapeChar,
                needsEscape);
        return;
    case LIST:
        separator = (char) LazyUtils.getSeparator(separators, level);
        ListObjectInspector loi = (ListObjectInspector) objInspector;
        list = loi.getList(obj);
        ObjectInspector eoi = loi.getListElementObjectInspector();
        if (list == null) {
            out.write(nullSequence.getBytes(), 0, nullSequence.getLength());
        } else {
            for (int i = 0; i < list.size(); i++) {
                if (i > 0) {
                    out.write(separator);
                }
                serialize(out, list.get(i), eoi, separators, level + 1, nullSequence, escaped, escapeChar,
                        needsEscape);
            }
        }
        return;
    case MAP:
        separator = (char) LazyUtils.getSeparator(separators, level);
        char keyValueSeparator = (char) LazyUtils.getSeparator(separators, level + 1);

        MapObjectInspector moi = (MapObjectInspector) objInspector;
        ObjectInspector koi = moi.getMapKeyObjectInspector();
        ObjectInspector voi = moi.getMapValueObjectInspector();
        Map<?, ?> map = moi.getMap(obj);
        if (map == null) {
            out.write(nullSequence.getBytes(), 0, nullSequence.getLength());
        } else {
            boolean first = true;
            for (Map.Entry<?, ?> entry : map.entrySet()) {
                if (first) {
                    first = false;
                } else {
                    out.write(separator);
                }
                serialize(out, entry.getKey(), koi, separators, level + 2, nullSequence, escaped, escapeChar,
                        needsEscape);
                out.write(keyValueSeparator);
                serialize(out, entry.getValue(), voi, separators, level + 2, nullSequence, escaped, escapeChar,
                        needsEscape);
            }
        }
        return;
    case STRUCT:
        separator = (char) LazyUtils.getSeparator(separators, level);
        StructObjectInspector soi = (StructObjectInspector) objInspector;
        List<? extends StructField> fields = soi.getAllStructFieldRefs();
        list = soi.getStructFieldsDataAsList(obj);
        if (list == null) {
            out.write(nullSequence.getBytes(), 0, nullSequence.getLength());
        } else {
            for (int i = 0; i < list.size(); i++) {
                if (i > 0) {
                    out.write(separator);
                }
                serialize(out, list.get(i), fields.get(i).getFieldObjectInspector(), separators, level + 1,
                        nullSequence, escaped, escapeChar, needsEscape);
            }
        }
        return;
    case UNION:
        separator = (char) LazyUtils.getSeparator(separators, level);
        UnionObjectInspector uoi = (UnionObjectInspector) objInspector;
        List<? extends ObjectInspector> ois = uoi.getObjectInspectors();
        if (ois == null) {
            out.write(nullSequence.getBytes(), 0, nullSequence.getLength());
        } else {
            LazyUtils.writePrimitiveUTF8(out, new Byte(uoi.getTag(obj)),
                    PrimitiveObjectInspectorFactory.javaByteObjectInspector, escaped, escapeChar, needsEscape);
            out.write(separator);
            serialize(out, uoi.getField(obj), ois.get(uoi.getTag(obj)), separators, level + 1, nullSequence,
                    escaped, escapeChar, needsEscape);
        }
        return;
    default:
        break;
    }

    throw new RuntimeException("Unknown category type: " + objInspector.getCategory());
}