Example usage for java.nio ByteBuffer putInt

List of usage examples for java.nio ByteBuffer putInt

Introduction

In this page you can find the example usage for java.nio ByteBuffer putInt.

Prototype

public abstract ByteBuffer putInt(int value);

Source Link

Document

Writes the given int to the current position and increases the position by 4.

Usage

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

byte[] encodeUploadCommit(int token, int crc) {
    final short LENGTH_UPLOADCOMMIT = 9;
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_UPLOADCOMMIT);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort(LENGTH_UPLOADCOMMIT);//from ww w. j a  v a 2  s  .c  o  m
    buf.putShort(ENDPOINT_PUTBYTES);
    buf.put(PUTBYTES_COMMIT);
    buf.putInt(token);
    buf.putInt(crc);
    return buf.array();
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

byte[] encodeAppRefresh(int index) {
    final short LENGTH_REFRESHAPP = 5;
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_REFRESHAPP);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort(LENGTH_REFRESHAPP);/*from   w  ww. j a  v  a  2s . c  om*/
    buf.putShort(ENDPOINT_APPMANAGER);
    buf.put(APPMANAGER_REFRESHAPP);
    buf.putInt(index);

    return buf.array();
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

byte[] encodeUploadComplete(int token) {
    final short LENGTH_UPLOADCOMPLETE = 5;
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_UPLOADCOMPLETE);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort(LENGTH_UPLOADCOMPLETE);
    buf.putShort(ENDPOINT_PUTBYTES);//  w w w  . ja  va 2s  .  co  m
    buf.put(PUTBYTES_COMPLETE);
    buf.putInt(token);
    return buf.array();
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

private byte[] encodePhoneVersion2x(byte os) {
    final short LENGTH_PHONEVERSION = 17;
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_PHONEVERSION);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort(LENGTH_PHONEVERSION);/* ww  w.  j  av  a 2s.c om*/
    buf.putShort(ENDPOINT_PHONEVERSION);
    buf.put((byte) 0x01);
    buf.putInt(-1); //0xffffffff

    if (os == PHONEVERSION_REMOTE_OS_ANDROID) {
        buf.putInt(PHONEVERSION_SESSION_CAPS_GAMMARAY);
    } else {
        buf.putInt(0);
    }
    buf.putInt(PHONEVERSION_REMOTE_CAPS_SMS | PHONEVERSION_REMOTE_CAPS_TELEPHONY | os);

    buf.put(PHONEVERSION_APPVERSION_MAGIC);
    buf.put(PHONEVERSION_APPVERSION_MAJOR);
    buf.put(PHONEVERSION_APPVERSION_MINOR);
    buf.put(PHONEVERSION_APPVERSION_PATCH);

    return buf.array();
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

private byte[] encodePhoneVersion3x(byte os) {
    final short LENGTH_PHONEVERSION3X = 25;
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_PHONEVERSION3X);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort(LENGTH_PHONEVERSION3X);
    buf.putShort(ENDPOINT_PHONEVERSION);
    buf.put((byte) 0x01);
    buf.putInt(-1); //0xffffffff
    buf.putInt(0);/* w w  w . j  a  v a 2 s. c om*/

    buf.putInt(os);

    buf.put(PHONEVERSION_APPVERSION_MAGIC);
    buf.put((byte) 4); // major
    buf.put((byte) 1); // minor
    buf.put((byte) 1); // patch
    buf.order(ByteOrder.LITTLE_ENDIAN);
    buf.putLong(0x00000000000029af); //flags

    return buf.array();
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

byte[] encodeUploadChunk(int token, byte[] buffer, int size) {
    final short LENGTH_UPLOADCHUNK = 9;
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_UPLOADCHUNK + size);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort((short) (LENGTH_UPLOADCHUNK + size));
    buf.putShort(ENDPOINT_PUTBYTES);/*from   ww w. j  a  v  a  2s.  c o m*/
    buf.put(PUTBYTES_SEND);
    buf.putInt(token);
    buf.putInt(size);
    buf.put(buffer, 0, size);
    return buf.array();
}

From source file:org.apache.geode.internal.cache.DiskInitFile.java

/**
 * Write the specified DataSerializer to the file.
 *//*from   w  w w . ja va2  s  . c  om*/
private void saveDataSerializer(DataSerializer ds) {
    lock(true);
    try {
        if (!this.compactInProgress && this.dsIds.contains(ds.getId())) {
            // dataSerializer already written to disk so just return
            return;
        }
        final byte[] classNameBytes = classToBytes(ds.getClass());
        ByteBuffer bb = getIFWriteBuffer(1 + 4 + classNameBytes.length + 1);
        bb.put(IFREC_DATA_SERIALIZER_ID);
        bb.putInt(classNameBytes.length);
        bb.put(classNameBytes);
        bb.put(END_OF_RECORD_ID);
        writeIFRecord(bb);
    } catch (IOException ex) {
        throw new DiskAccessException(
                LocalizedStrings.DiskInitFile_FAILED_SAVING_DATA_SERIALIZER_TO_DISK_BECAUSE_0
                        .toLocalizedString(ex),
                this.parent);
    } finally {
        unlock(true);
    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

byte[] encodeInstallMetadata(UUID uuid, String appName, short appVersion, short sdkVersion, int flags,
        int iconId) {
    final short METADATA_LENGTH = 126;

    byte[] name_buf = new byte[96];
    System.arraycopy(appName.getBytes(), 0, name_buf, 0, appName.getBytes().length);
    ByteBuffer buf = ByteBuffer.allocate(METADATA_LENGTH);

    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putLong(uuid.getMostSignificantBits()); // watchapp uuid
    buf.putLong(uuid.getLeastSignificantBits());
    buf.order(ByteOrder.LITTLE_ENDIAN);
    buf.putInt(flags);
    buf.putInt(iconId);//from   w w  w  .j  av a 2 s  . c  o  m
    buf.putShort(appVersion);
    buf.putShort(sdkVersion);
    buf.put((byte) 0); // app_face_bgcolor
    buf.put((byte) 0); // app_face_template_id
    buf.put(name_buf); // 96 bytes

    return encodeBlobdb(uuid, BLOBDB_INSERT, BLOBDB_APP, buf.array());
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

private byte[] encodeActionResponse2x(int id, byte actionId, int iconId, String caption) {
    short length = (short) (18 + caption.getBytes().length);
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort(length);//ww  w.  j  a  va  2s. c  om
    buf.putShort(ENDPOINT_EXTENSIBLENOTIFS);
    buf.order(ByteOrder.LITTLE_ENDIAN);
    buf.put(NOTIFICATIONACTION_RESPONSE);
    buf.putInt(id);
    buf.put(actionId);
    buf.put(NOTIFICATIONACTION_ACK);
    buf.put((byte) 2); //nr of attributes
    buf.put((byte) 6); // icon
    buf.putShort((short) 4); // length
    buf.putInt(iconId);
    buf.put((byte) 2); // title
    buf.putShort((short) caption.getBytes().length);
    buf.put(caption.getBytes());
    return buf.array();
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

private byte[] encodeMessage(short endpoint, byte type, int cookie, String[] parts) {
    // Calculate length first
    int length = LENGTH_PREFIX + 1;
    if (parts != null) {
        for (String s : parts) {
            if (s == null || s.equals("")) {
                length++; // encode null or empty strings as 0x00 later
                continue;
            }//from  ww  w . ja  va  2 s  . co m
            length += (1 + s.getBytes().length);
        }
    }
    if (endpoint == ENDPOINT_PHONECONTROL) {
        length += 4; //for cookie;
    }

    // Encode Prefix
    ByteBuffer buf = ByteBuffer.allocate(length);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort((short) (length - LENGTH_PREFIX));
    buf.putShort(endpoint);
    buf.put(type);

    if (endpoint == ENDPOINT_PHONECONTROL) {
        buf.putInt(cookie);
    }
    // Encode Pascal-Style Strings
    if (parts != null) {
        for (String s : parts) {
            if (s == null || s.equals("")) {
                buf.put((byte) 0x00);
                continue;
            }

            int partlength = s.getBytes().length;
            if (partlength > 255)
                partlength = 255;
            buf.put((byte) partlength);
            buf.put(s.getBytes(), 0, partlength);
        }
    }
    return buf.array();
}