Java Code Examples for java.util.UUID

The following are top voted examples for showing how to use java.util.UUID. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: vertx-cassandra-binarystore   File: DefaultBinaryStoreWriter.java View source code 8 votes vote down vote up
@Override
public Promise<FileInfo> write(final FileInfo fileInfo, final ReadStream<Buffer> rs) {

    // Copy file info to a writeable version and fill in missing fields
    FileInfo writeableFileInfo = new FileInfo()
            .setId((fileInfo.getId() == null ? UUID.randomUUID() : fileInfo.getId()))
            .setFileName(fileInfo.getFileName())
            .setChunkSize((fileInfo.getChunkSize() <= 0 ? DEFAULT_CHUNK_SIZE : fileInfo.getChunkSize()))
            .setContentType((fileInfo.getContentType() == null ? getContentType(fileInfo.getFileName()) : fileInfo.getContentType()))
            .setMetadata(fileInfo.getMetadata())
            .setUploadDate((fileInfo.getUploadDate() == 0 ? System.currentTimeMillis() : fileInfo.getUploadDate()));

    return innerWrite(writeableFileInfo, rs);

}
 
Example 2
Project: BLEConnect   File: DeviceControlActivity.java View source code 6 votes vote down vote up
private void displayGattServices(List<BluetoothGattService> gattServices) {
	if (gattServices == null)
		return;
	String uuid = null;
	String unknownServiceString = getResources().getString(
			R.string.unknown_service);
	String unknownCharaString = getResources().getString(
			R.string.unknown_characteristic);
	ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>();
	ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData = new ArrayList<ArrayList<HashMap<String, String>>>();
	mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>();

	// Loops through available GATT Services.
	for (BluetoothGattService gattService : gattServices) {
		HashMap<String, String> currentServiceData = new HashMap<String, String>();
		uuid = gattService.getUuid().toString();
		currentServiceData.put(LIST_NAME,
				SampleGattAttributes.lookup(uuid, unknownServiceString));
		currentServiceData.put(LIST_UUID, uuid);
		gattServiceData.add(currentServiceData);

		ArrayList<HashMap<String, String>> gattCharacteristicGroupData = new ArrayList<HashMap<String, String>>();
		List<BluetoothGattCharacteristic> gattCharacteristics = gattService
				.getCharacteristics();
		ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>();

		// Loops through available Characteristics.
		for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {

			if (UUID.fromString(SampleGattAttributes.HEART_RATE_MEASUREMENT)
					.equals(gattCharacteristic.getUuid())) {
				Log.d(TAG, "Found heart rate");
				mNotifyCharacteristic = gattCharacteristic;
			}

			charas.add(gattCharacteristic);
			HashMap<String, String> currentCharaData = new HashMap<String, String>();
			uuid = gattCharacteristic.getUuid().toString();
			currentCharaData.put(LIST_NAME,
					SampleGattAttributes.lookup(uuid, unknownCharaString));
			currentCharaData.put(LIST_UUID, uuid);
			gattCharacteristicGroupData.add(currentCharaData);
		}
		mGattCharacteristics.add(charas);
		gattCharacteristicData.add(gattCharacteristicGroupData);
	}

}
 
Example 3
Project: Urbanization   File: DataController.java View source code 6 votes vote down vote up
public File getInstanceFile(UUID instanceID){
	File f = new File(plugin.getDataFolder().getPath()+File.separator+"groups"+File.separator+instanceID.toString()+".yml");
	if (!f.exists()){
		try {
			f.createNewFile();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	return f;
}
 
Example 4
Project: Bagginses   File: InventoryBag.java View source code 6 votes vote down vote up
public ItemStack findParentItemStack(EntityPlayer entityPlayer) {
    if (NBTHelper.hasUUID(parentItemStack)) {
        UUID parentItemStackUUID = new UUID(parentItemStack.getTagCompound().getLong(Names.NBT.UUID_MOST_SIG), parentItemStack.getTagCompound().getLong(Names.NBT.UUID_LEAST_SIG));
        for (int i = 0; i < entityPlayer.inventory.getSizeInventory(); i++) {
            ItemStack itemStack = entityPlayer.inventory.getStackInSlot(i);

            if (NBTHelper.hasUUID(itemStack)) {
                if (itemStack.getTagCompound().getLong(Names.NBT.UUID_MOST_SIG) == parentItemStackUUID.getMostSignificantBits() && itemStack.getTagCompound().getLong(Names.NBT.UUID_LEAST_SIG) == parentItemStackUUID.getLeastSignificantBits()) {
                    return itemStack;
                }
            }
        }
    }

    return null;
}
 
Example 5
Project: funCKit   File: ComponentImporter.java View source code 6 votes vote down vote up
/**
 * Gets the uuid of the mapped inner accesspoint to the given uuid of the
 * outer accesspoint for the given component tag by searching trough the
 * mapping tags.
 * 
 * @param element
 *            the component tag with an accesspoint with the given uuid.
 * @param outerUUID
 *            the uuid of the outer accesspoint
 * @param converter
 *            [email protected] SEPFormatConverter} to use for importing.
 * @return the uuid of the mapped inner accesspoint.
 * @throws SEPFormatImportException
 */
private static UUID getInnerMapping(Element element, UUID outerUUID,
        SEPFormatConverter converter) throws SEPFormatImportException {
    NodeList componentList = element.getElementsByTagName("fck:mapping");
    for (int i = 0; i < componentList.getLength(); i++) {
        Element mappingElement = (Element) componentList.item(i);
        UUID foundOuterUUID =
                converter.ensureUUID(mappingElement, "fck:outerPoint");
        if (outerUUID.equals(foundOuterUUID)) {
            return converter.ensureUUID(mappingElement, "fck:innerPoint");
        }
    }

    throw new SEPFormatImportException(
            "SEPFormatImportException.unmappedAccessPoint", outerUUID);
}
 
Example 6
Project: GlowstonePlusPlus   File: LoginStartHandler.java View source code 6 votes vote down vote up
@Override
public void handle(GlowSession session, LoginStartMessage message) {
    final String name = message.getUsername();

    if (session.getServer().getOnlineMode()) {
        // Get necessary information to create our request message
        final String sessionId = session.getSessionId();
        final byte[] publicKey = SecurityUtils.generateX509Key(session.getServer().getKeyPair().getPublic()).getEncoded(); //Convert to X509 format
        final byte[] verifyToken = SecurityUtils.generateVerifyToken();

        // Set verify data on session for use in the response handler
        session.setVerifyToken(verifyToken);
        session.setVerifyUsername(name);

        // Send created request message and wait for the response
        session.send(new EncryptionKeyRequestMessage(sessionId, publicKey, verifyToken));
    } else {
        ProxyData proxy = session.getProxyData();
        if (proxy == null) {
            UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8));
            session.setPlayer(new PlayerProfile(name, uuid));
        } else {
            PlayerProfile profile = proxy.getProfile();
            session.setPlayer(profile == null ? proxy.getProfile(name) : profile);
        }
    }
}
 
Example 7
Project: cassandra-lucene-index   File: UUIDMapper.java View source code 6 votes vote down vote up
/**
 * Returns the [email protected] String} representation of the specified [email protected] UUID}. The returned value has the same
 * collation as [email protected] UUIDType}.
 *
 * @param uuid The [email protected] UUID} to be serialized.
 * @return The [email protected] String} representation of the specified [email protected] UUID}.
 */
public static String serialize(UUID uuid) {

    StringBuilder sb = new StringBuilder();

    // Get UUID type version
    ByteBuffer bb = UUIDType.instance.decompose(uuid);
    int version = (bb.get(bb.position() + 6) >> 4) & 0x0f;

    // Add version at the beginning
    sb.append(ByteBufferUtils.toHex((byte) version));

    // If it's a time based UUID, add the UNIX timestamp
    if (version == 1) {
        long timestamp = uuid.timestamp();
        String timestampHex = ByteBufferUtils.toHex(Longs.toByteArray(timestamp));
        sb.append(timestampHex);
    }

    // Add the UUID itself
    sb.append(ByteBufferUtils.toHex(bb));
    return sb.toString();
}
 
Example 8
Project: dimple   File: Ids.java View source code 6 votes vote down vote up
/**
 * Extracts environment id from Dimple UUID
 * <p>
 * Returns the [email protected] DimpleEnvironment#getEnvId() Dimple environment id} encoded in the
 * UUID or else -1 if UUID was not created by [email protected] #makeUUID(long, long)}.
 * @since 0.08
 */
public static long envIdFromUUID(UUID uid)
{
	if (uid.variant() != 2 || uid.version() != DIMPLE_UUID_VERSION)
	{
		return -1L;
	}
	final long msb = uid.getMostSignificantBits();
	return msb & UUID_NON_VERSION_MASK | (msb >>> UUID_VERSION_WIDTH) & ~UUID_NON_VERSION_MASK;
}
 
Example 9
Project: xDrip   File: DexShareCollectionService.java View source code 6 votes vote down vote up
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    UUID charUuid = characteristic.getUuid();
    Log.d(TAG, "Characteristic Update Received: " + charUuid);
    if (charUuid.compareTo(mReceiveDataCharacteristic.getUuid()) == 0) {
        Log.d(TAG, "mCharReceiveData Update");
        byte[] value = characteristic.getValue();
        if (value != null) {
            Observable.just(characteristic.getValue()).subscribe(mDataResponseListener);
        }
    }
}