Example usage for java.lang Byte intValue

List of usage examples for java.lang Byte intValue

Introduction

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

Prototype

public int intValue() 

Source Link

Document

Returns the value of this Byte as an int after a widening primitive conversion.

Usage

From source file:de.blizzy.backup.restore.RestoreDialog.java

private Entry toEntry(Record record, boolean fullPaths) {
    int id = record.getValue(Tables.ENTRIES.ID).intValue();
    Integer parentIdInt = record.getValue(Tables.ENTRIES.PARENT_ID);
    int parentId = (parentIdInt != null) ? parentIdInt.intValue() : -1;
    String name = record.getValue(Tables.ENTRIES.NAME);
    EntryType type = EntryType.fromValue(record.getValue(Tables.ENTRIES.TYPE).intValue());
    Timestamp createTime = record.getValue(Tables.ENTRIES.CREATION_TIME);
    Date creationTime = (createTime != null) ? new Date(createTime.getTime()) : null;
    Timestamp modTime = record.getValue(Tables.ENTRIES.MODIFICATION_TIME);
    Date modificationTime = (modTime != null) ? new Date(modTime.getTime()) : null;
    boolean hidden = record.getValue(Tables.ENTRIES.HIDDEN).booleanValue();
    Long lengthLong = record.getValue(Tables.FILES.LENGTH);
    long length = (lengthLong != null) ? lengthLong.longValue() : -1;
    String backupPath = record.getValue(Tables.FILES.BACKUP_PATH);
    Byte compressionByte = record.getValue(Tables.FILES.COMPRESSION);
    Compression compression = (compressionByte != null) ? Compression.fromValue(compressionByte.intValue())
            : null;//from   ww  w .j  a  v  a2 s. c  o m
    Entry entry = new Entry(id, parentId, name, type, creationTime, modificationTime, hidden, length,
            backupPath, compression);
    if (fullPaths) {
        entry.fullPath = getFolderPath(parentId);
    }
    return entry;
}

From source file:com.magnet.android.mms.controller.RequestPrimitiveTest.java

@SmallTest
public void testSingleListBytePostParam() throws JSONException {
    ControllerHandler handler = new ControllerHandler();
    String methodName = "postChars";

    JMethod method = new JMethod();
    JMeta metaInfo = new JMeta(methodName, API_METHOD_POST + methodName, POST);
    method.setMetaInfo(metaInfo);/*from   ww w. java2  s  .  co m*/

    method.addParam("param0", PLAIN, List.class, Byte.class, "", false);

    List<Byte> values = new ArrayList<Byte>();
    values.add((byte) 0x03);
    values.add((byte) 0x20);

    String uriString = handler.buildUri(method, new Object[] { values });
    String bodyString = handler.buildRequestBodyString(method, new Object[] { values });

    String expected = API_METHOD_POST + methodName;
    logger.log(Level.INFO, "uriString=" + uriString);
    logger.log(Level.INFO, "bodyString=" + bodyString);
    assertEquals(expected, uriString);

    JSONArray jarray = new JSONArray(bodyString);
    int idx = 0;
    for (Byte value : values) {
        assertEquals(jarray.getInt(idx), value.intValue());
        idx++;
    }
}

From source file:org.shampoo.goldenembed.parser.GoldenEmbedParserMain.java

private void ANTrxMsg(byte[] rxIN, int size, GoldenCheetah gc) {
    int i = 2;/*from ww  w .  j ava  2s.c o  m*/
    if (megaDebug)
        System.out.println("Converting 0x" + UnicodeFormatter.byteToHex(rxIN[i]));
    switch (rxIN[i]) {
    case MESG_RESPONSE_EVENT_ID:
        if (debug)
            System.out.println("ID: MESG_RESPONSE_EVENT_ID\n");
        ANTresponseHandler(rxIN, size, gc);
        break;
    case MESG_CAPABILITIES_ID:
        if (debug)
            System.out.println("ID: MESG_CAPABILITIES_ID\n");
        i = ANTCfgCapabilties(i, size); // rxBuf[3] .. skip sync, size, msg
        break;
    case MESG_BROADCAST_DATA_ID:
        if (debug)
            System.out.println("ID: MESG_BROADCAST_DATA_ID\n");
        Byte aByte = new Byte(rxIN[++i]);
        int chan = aByte.intValue();
        if (chan == 0)
            ANTparseHRM(rxIN, gc);
        else if (chan == 1)
            power.ANTParsePower(rxIN, size, gc, gcArray);
        break;

    case MESG_CHANNEL_ID_ID:
        if (debug)
            System.out.println("ID: MESG_CHANNEL_ID_ID\n");
        ANTChannelID(rxIN, gc);
        break;
    default:
        if (debug)
            System.out.println("ID: Unknown 0x" + UnicodeFormatter.byteToHex(rxIN[i]));
    }
    return;
}

From source file:org.shampoo.goldenembed.parser.GoldenEmbedParserMain.java

private boolean ANTrxHandler(byte[] rxBuf, GoldenCheetah gc) {
    int msgN = 0;
    int i;/*ww  w.jav a2s.  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.shampoo.goldenembed.parser.GoldenEmbedParserMain.java

private int readBuffer(byte[] readBytes, String filePath) {
    int bufPos = 0;
    GPS gps = new GPS();
    byte[] bufToSend;
    byte[] timeStamp;
    long secs = 0;

    if ((pos + bufPos + 64) >= readBytes.length - 1) {
        System.out.println("\n\nTotal Failed Checksums: " + totalChecksumError + " Out of Total ANT Messages: "
                + totalTrans);/*from w  w  w. j  ava  2s  . com*/
        System.out.println("% ANT Failure: " + (totalChecksumError / totalTrans) * 100.0);
        System.out.println("Total Failed GPS: " + totalGPSError + " Out of Total ANT Messages: " + totalTrans);
        System.out.println("% GPS Failure: " + (totalGPSError / totalTrans) * 100.0);
        System.out.println("Total Failed Messages: " + (totalChecksumError + totalGPSError)
                + " Out of Total ANT Messages: " + totalTrans);
        System.out.println("% Failure: " + ((totalChecksumError + totalGPSError) / totalTrans) * 100.0);

        System.out.println("Total CAD or Watt Spikes: " + totalSpikes);
        writeOutGCRecords();
        System.exit(0);
    }

    Byte aByte = new Byte(readBytes[pos + bufPos + 1]);
    int size = aByte.intValue();
    if (size < 0) {
        pos++;
        // We failed a checksum skip..
        while (readBytes[pos] != MESG_TX_SYNC) {
            pos++;
        }
        totalChecksumError++;
        return pos;

    }
    bufToSend = new byte[size + 4];

    for (; bufPos < bufToSend.length; bufPos++)
        bufToSend[bufPos] = readBytes[bufPos + pos];
    if (ANTrxHandler(bufToSend, gc) == true) {
        pos++;
        // We failed a checksum skip..
        while (readBytes[pos] != MESG_TX_SYNC)
            pos++;
        return pos;
    }

    pos = (pos + size + 4);

    try {

        if (isGPS) {

            // Now Parse GPS
            gps = new GPS().GPSHandler(readBytes, pos);

            pos += 22; // All GPS data

            // Get the intial elevation from Google use Lat and Lon

            if (altiPressure == null && serializedElevationPath == null) {
                altiPressure = new AltitudePressure(GoogleElevation
                        .getElevation(Float.valueOf(gps.getLatitude()), Float.valueOf(gps.getLongitude())));
            }
            int pressureCounter = 0;
            byte[] pressureByte = new byte[16];

            while (readBytes[pos] != 0x07) {
                if (pressureCounter == 15)
                    throw new NumberFormatException();
                pressureByte[pressureCounter++] = readBytes[pos++];
            }
            pos++; // skip the delimeter
            String strPressure = convertBytesToString(pressureByte);
            float pressure = Float.parseFloat(strPressure);

            strPressure = convertBytesToString(pressureByte);
            pressure = Float.parseFloat(strPressure);

            if (serializedElevationPath == null)
                gc.setElevation(altiPressure.altiCalc(pressure / 100.0f));

            timeStamp = new byte[6];

            for (int i = 0; i < 6; i++)
                timeStamp[i] = readBytes[pos++];
            secs = parseTimeStamp(timeStamp, gc);
        } else {
            timeStamp = new byte[3];
            for (int i = 0; i < 3; i++)
                timeStamp[i] = readBytes[pos++];
            secs = parseTimeStamp(timeStamp, gc);
        }

        if (rideDate == null && isGPS == true)
            createRideDate(gps, timeStamp);
        else if (rideDate == null)
            createRideDate();

        gc.setLatitude(gps.getLatitude());
        gc.setLongitude(gps.getLongitude());
        gc.setSpeed(gps.getSpeed() * KNOTS_TO_KILOMETERS);

        gc.setDistance(gc.getDistance() + (gc.getSpeed() * (gc.getSecs() - gc.getPrevSpeedSecs()) / 3600.0));

        gc.setPrevSpeedSecs(gc.getSecs());
        if (secs > 86400) // Only fools ride for more then 24hrs a time..
            throw new NumberFormatException();
        gc.setSecs(secs);
        gc.setDate(gps.getDate());

        // If we haven't created the file, create it
        if (outFile == null && outGCFilePath != null) {
            if (isGPS)
                initOutFile(gps, outGCFilePath, timeStamp);
            else
                createGCOutFile();
        }
        if (gc.getPrevsecs() != gc.getSecs()) {
            gc.setWatts((int) Round(power.getWatts() / power.getTotalWattCounter(), 0));
            gc.setCad((int) Round(power.getRpm() / power.getTotalCadCounter(), 0));
            GoldenCheetah _gc = gc.clone(gc);
            gcArray.add(_gc);
            gc.setPrevsecs(gc.getSecs());
            gc.newWatts = false;
        }

    } catch (NumberFormatException e) {
        while (readBytes[pos] != MESG_TX_SYNC)
            pos++;
        totalGPSError++;
        return pos;
    } catch (StringIndexOutOfBoundsException ex) {
        while (readBytes[pos] != MESG_TX_SYNC)
            pos++;
        totalGPSError++;
    }
    return pos;

}