Example usage for java.util UUID getLeastSignificantBits

List of usage examples for java.util UUID getLeastSignificantBits

Introduction

In this page you can find the example usage for java.util UUID getLeastSignificantBits.

Prototype

public long getLeastSignificantBits() 

Source Link

Document

Returns the least significant 64 bits of this UUID's 128 bit value.

Usage

From source file:kx.c.java

void w(UUID uuid) {
    if (vt < 3)
        throw new RuntimeException("Guid not valid pre kdb+3.0");
    w(uuid.getMostSignificantBits());//from  w w  w. j  a va  2  s  . c  o  m
    w(uuid.getLeastSignificantBits());
}

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

@Override
public byte[] encodeAppReorder(UUID[] uuids) {
    int length = 2 + uuids.length * LENGTH_UUID;
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort((short) length);
    buf.putShort(ENDPOINT_APPREORDER);/*  www . jav a 2 s  .  com*/
    buf.put((byte) 0x01);
    buf.put((byte) uuids.length);
    for (UUID uuid : uuids) {
        buf.putLong(uuid.getMostSignificantBits());
        buf.putLong(uuid.getLeastSignificantBits());
    }

    return buf.array();
}

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

private byte[] encodeBlobdb(Object key, byte command, byte db, byte[] blob) {

    int length = 5;

    int key_length;
    if (key instanceof UUID) {
        key_length = LENGTH_UUID;
    } else if (key instanceof String) {
        key_length = ((String) key).getBytes().length;
    } else {//from   w  w w.  ja va 2s  . com
        LOG.warn("unknown key type");
        return null;
    }
    if (key_length > 255) {
        LOG.warn("key is too long");
        return null;
    }
    length += key_length;

    if (blob != null) {
        length += blob.length + 2;
    }

    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length);

    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort((short) length);
    buf.putShort(ENDPOINT_BLOBDB);

    buf.order(ByteOrder.LITTLE_ENDIAN);
    buf.put(command);
    buf.putShort((short) mRandom.nextInt()); // token
    buf.put(db);

    buf.put((byte) key_length);
    if (key instanceof UUID) {
        UUID uuid = (UUID) key;
        buf.order(ByteOrder.BIG_ENDIAN);
        buf.putLong(uuid.getMostSignificantBits());
        buf.putLong(uuid.getLeastSignificantBits());
        buf.order(ByteOrder.LITTLE_ENDIAN);
    } else {
        buf.put(((String) key).getBytes());
    }

    if (blob != null) {
        buf.putShort((short) blob.length);
        buf.put(blob);
    }

    return buf.array();
}

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

private GBDeviceEvent[] decodeAction(ByteBuffer buf) {
    buf.order(ByteOrder.LITTLE_ENDIAN);
    byte command = buf.get();
    if (command == NOTIFICATIONACTION_INVOKE) {
        int id;/*from w w  w  .  j a v a 2 s  .  com*/
        UUID uuid = new UUID(0, 0);
        if (mFwMajor >= 3) {
            uuid = getUUID(buf);
            id = (int) (uuid.getLeastSignificantBits() & 0xffffffffL);
        } else {
            id = buf.getInt();
        }
        byte action = buf.get();
        if (action >= 0x00 && action <= 0x05) {
            GBDeviceEventNotificationControl devEvtNotificationControl = new GBDeviceEventNotificationControl();
            devEvtNotificationControl.handle = id;
            String caption = "undefined";
            int icon_id = 1;
            boolean needsAck2x = true;
            switch (action) {
            case 0x01:
                devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.OPEN;
                caption = "Opened";
                icon_id = PebbleIconID.DURING_PHONE_CALL;
                break;
            case 0x02:
                devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.DISMISS;
                caption = "Dismissed";
                icon_id = PebbleIconID.RESULT_DISMISSED;
                needsAck2x = false;
                break;
            case 0x03:
                devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.DISMISS_ALL;
                caption = "All dismissed";
                icon_id = PebbleIconID.RESULT_DISMISSED;
                needsAck2x = false;
                break;
            case 0x04:
                devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.MUTE;
                caption = "Muted";
                icon_id = PebbleIconID.RESULT_MUTE;
                break;
            case 0x05:
            case 0x00:
                boolean failed = true;
                byte attribute_count = buf.get();
                if (attribute_count > 0) {
                    byte attribute = buf.get();
                    if (attribute == 0x01) { // reply string is in attribute 0x01
                        short length = buf.getShort();
                        if (length > 64)
                            length = 64;
                        byte[] reply = new byte[length];
                        buf.get(reply);
                        devEvtNotificationControl.phoneNumber = null;
                        if (buf.remaining() > 1 && buf.get() == 0x0c) {
                            short phoneNumberLength = buf.getShort();
                            byte[] phoneNumberBytes = new byte[phoneNumberLength];
                            buf.get(phoneNumberBytes);
                            devEvtNotificationControl.phoneNumber = new String(phoneNumberBytes);
                        }
                        devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY;
                        devEvtNotificationControl.reply = new String(reply);
                        caption = "SENT";
                        icon_id = PebbleIconID.RESULT_SENT;
                        failed = false;
                    }
                }
                if (failed) {
                    caption = "FAILED";
                    icon_id = PebbleIconID.RESULT_FAILED;
                    devEvtNotificationControl = null; // error
                }
                break;
            }
            GBDeviceEventSendBytes sendBytesAck = null;
            if (mFwMajor >= 3 || needsAck2x) {
                sendBytesAck = new GBDeviceEventSendBytes();
                if (mFwMajor >= 3) {
                    sendBytesAck.encodedBytes = encodeActionResponse(uuid, icon_id, caption);
                } else {
                    sendBytesAck.encodedBytes = encodeActionResponse2x(id, action, 6, caption);
                }
            }
            return new GBDeviceEvent[] { sendBytesAck, devEvtNotificationControl };
        }
        LOG.info("unexpected action: " + action);
    }

    return null;
}

From source file:org.apache.geode.internal.InternalDataSerializer.java

private static void writeUUID(java.util.UUID o, DataOutput out) throws IOException {
    InternalDataSerializer.checkOut(out);

    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
        logger.trace(LogMarker.SERIALIZER, "Writing UUID: {}", o);
    }//from   ww  w .ja  v  a  2  s  .  c om
    DataSerializer.writePrimitiveLong(o.getMostSignificantBits(), out);
    DataSerializer.writePrimitiveLong(o.getLeastSignificantBits(), out);
}

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

private byte[] encodeActionResponse(UUID uuid, int iconId, String caption) {
    short length = (short) (29 + caption.getBytes().length);
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort(length);//from  w  w w .j  av a  2 s .  c  o m
    buf.putShort(ENDPOINT_NOTIFICATIONACTION);
    buf.put(NOTIFICATIONACTION_RESPONSE);
    buf.putLong(uuid.getMostSignificantBits());
    buf.putLong(uuid.getLeastSignificantBits());
    buf.order(ByteOrder.LITTLE_ENDIAN);
    buf.put(NOTIFICATIONACTION_ACK);
    buf.put((byte) 2); //nr of attributes
    buf.put((byte) 6); // icon
    buf.putShort((short) 4); // length
    buf.putInt(0x80000000 | 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[] encodeWeatherPin(int timestamp, String title, String subtitle, String body, String location,
        int iconId) {
    final short NOTIFICATION_PIN_LENGTH = 46;
    final short ACTION_LENGTH_MIN = 10;

    String[] parts = { title, subtitle, body, location, "test", "test" };

    // Calculate length first
    byte actions_count = 1;
    short actions_length;
    String remove_string = "Remove";
    actions_length = (short) (ACTION_LENGTH_MIN * actions_count + remove_string.getBytes().length);

    byte attributes_count = 3;
    short attributes_length = (short) (21 + actions_length);
    if (parts != null) {
        for (String s : parts) {
            if (s == null || s.equals("")) {
                continue;
            }//from  w ww.ja  v  a  2  s .  co m
            attributes_count++;
            attributes_length += (3 + s.getBytes().length);
        }
    }

    UUID uuid = UUID.fromString("61b22bc8-1e29-460d-a236-3fe409a43901");

    short pin_length = (short) (NOTIFICATION_PIN_LENGTH + attributes_length);

    ByteBuffer buf = ByteBuffer.allocate(pin_length);

    // pin (46 bytes)
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putLong(uuid.getMostSignificantBits());
    buf.putLong(uuid.getLeastSignificantBits());
    buf.putLong(uuid.getMostSignificantBits());
    buf.putLong(uuid.getLeastSignificantBits() | 0xff);
    buf.order(ByteOrder.LITTLE_ENDIAN);
    buf.putInt(timestamp); // 32-bit timestamp
    buf.putShort((short) 0); // duration
    buf.put((byte) 0x02); // type (0x02 = pin)
    buf.putShort((short) 0x0001); // flags 0x0001 = ?
    buf.put((byte) 0x06); // layout (0x06 = weather)
    buf.putShort(attributes_length); // total length of all attributes and actions in bytes
    buf.put(attributes_count);
    buf.put(actions_count);

    byte attribute_id = 0;
    // Encode Pascal-Style Strings
    if (parts != null) {
        for (String s : parts) {
            attribute_id++;
            if (s == null || s.equals("")) {
                continue;
            }

            int partlength = s.getBytes().length;
            if (partlength > 512)
                partlength = 512;
            if (attribute_id == 4) {
                buf.put((byte) 11);
            } else if (attribute_id == 5) {
                buf.put((byte) 25);
            } else if (attribute_id == 6) {
                buf.put((byte) 26);
            } else {
                buf.put(attribute_id);
            }
            buf.putShort((short) partlength);
            buf.put(s.getBytes(), 0, partlength);
        }
    }

    buf.put((byte) 4); // icon
    buf.putShort((short) 4); // length of int
    buf.putInt(0x80000000 | iconId);

    buf.put((byte) 6); // icon
    buf.putShort((short) 4); // length of int
    buf.putInt(0x80000000 | iconId);

    buf.put((byte) 14); // last updated
    buf.putShort((short) 4); // length of int
    buf.putInt(timestamp);

    // remove action
    buf.put((byte) 123); // action id
    buf.put((byte) 0x09); // remove
    buf.put((byte) 0x01); // number attributes
    buf.put((byte) 0x01); // attribute id (title)
    buf.putShort((short) remove_string.getBytes().length);
    buf.put(remove_string.getBytes());

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

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

byte[] encodeApplicationMessageAck(UUID uuid, byte id) {
    if (uuid == null) {
        uuid = currentRunningApp;/* ww w.  j a  v a2s.c  o  m*/
    }
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + 18); // +ACK

    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort((short) 18);
    buf.putShort(ENDPOINT_APPLICATIONMESSAGE);
    buf.put(APPLICATIONMESSAGE_ACK);
    buf.put(id);
    buf.putLong(uuid.getMostSignificantBits());
    buf.putLong(uuid.getLeastSignificantBits());

    return buf.array();
}

From source file:org.ow2.authzforce.pap.dao.flatfile.FlatFileBasedDomainsDAO.java

@Override
public String addDomain(final WritableDomainProperties props) throws IOException, IllegalArgumentException {
    final UUID uuid = uuidGen.generate();
    /*/*  ww w.  j a va  2  s. co m*/
     * Encode UUID with Base64url to have shorter IDs in REST API URL paths
     * and to be compatible with filenames on any operating system, since
     * the resulting domain ID is used as name for the directory where all
     * the domain's data will be stored.
     */
    final ByteBuffer byteBuf = ByteBuffer.wrap(new byte[16]);
    byteBuf.putLong(uuid.getMostSignificantBits());
    byteBuf.putLong(uuid.getLeastSignificantBits());
    final String domainId = FlatFileDAOUtils.base64UrlEncode(byteBuf.array());
    synchronized (domainsRootDir) {
        // this should not happen if the UUID generator can be trusted, but
        // - hey - we never
        // know.
        if (this.domainMap.containsKey(domainId)) {
            throw new ConcurrentModificationException(
                    "Generated domain ID conflicts (is same as) ID of existing domain (flawed domain UUID generator or ID generated in different way?): ID="
                            + domainId);
        }

        final Path domainDir = this.domainsRootDir.resolve(domainId);
        if (Files.notExists(domainDir)) {
            /*
             * Create/initialize new domain directory from domain template
             * directory
             */
            FlatFileDAOUtils.copyDirectory(this.domainTmplDirPath, domainDir, 3);
        }

        addDomainToCacheAfterDirectoryCreated(domainId, domainDir, props);
    }

    return domainId;
}

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);//from   w  ww  . java2s . com
    buf.putInt(iconId);
    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());
}