Java Code Examples for java.util.UUID#nameUUIDFromBytes()

The following examples show how to use java.util.UUID#nameUUIDFromBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraPersistenceUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
/** @return UUID for composite key */
public static UUID keyID( Object... objects ) {
    if ( objects.length == 1 ) {
        Object obj = objects[0];
        if ( obj instanceof UUID ) {
            return ( UUID ) obj;
        }
    }
    String keyStr = key( objects ).toString();
    if ( keyStr.length() == 0 ) {
        return NULL_ID;
    }
    UUID uuid = UUID.nameUUIDFromBytes( keyStr.getBytes() ); //UUIDUtils.newTimeUUID(); //UUID.nameUUIDFromBytes( keyStr.getBytes() );

    if (logger.isTraceEnabled()) {
        logger.trace("Key {} equals UUID {}", keyStr, uuid);
    }

    return uuid;
}
 
Example 2
Source File: MD5UuidGenStrategy.java    From ambari-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] computeUuid(TimelineClusterMetric timelineClusterMetric, int maxLength) {

  String metricString = timelineClusterMetric.getMetricName() + timelineClusterMetric.getAppId();
  if (StringUtils.isNotEmpty(timelineClusterMetric.getInstanceId())) {
    metricString += timelineClusterMetric.getInstanceId();
  }
  byte[] metricBytes = metricString.getBytes();

  UUID uuid = UUID.nameUUIDFromBytes(metricBytes);
  ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[maxLength]);
  byteBuffer.putLong(uuid.getMostSignificantBits());
  byteBuffer.putLong(uuid.getLeastSignificantBits());

  return byteBuffer.array();
}
 
Example 3
Source File: JSTypeUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Used to generate a unique type name to hold module definitions.
 * 
 * @param string
 * @return
 */
public static String getUniqueTypeName(String string)
{
	if (string == null)
	{
		return "$module_" + UUID.randomUUID(); //$NON-NLS-1$
	}
	return "$module_" + UUID.nameUUIDFromBytes(string.getBytes()); //$NON-NLS-1$
}
 
Example 4
Source File: IncrementalRemoteKeyedStateHandleTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static IncrementalRemoteKeyedStateHandle create(Random rnd) {
	return new IncrementalRemoteKeyedStateHandle(
		UUID.nameUUIDFromBytes("test".getBytes()),
		KeyGroupRange.of(0, 0),
		1L,
		placeSpies(CheckpointTestUtils.createRandomStateHandleMap(rnd)),
		placeSpies(CheckpointTestUtils.createRandomStateHandleMap(rnd)),
		spy(CheckpointTestUtils.createDummyStreamStateHandle(rnd, null)));
}
 
Example 5
Source File: Utils.java    From BukkitPE with GNU General Public License v3.0 5 votes vote down vote up
public static UUID dataToUUID(byte[]... params) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    for (byte[] param : params) {
        try {
            stream.write(param);
        } catch (IOException e) {
            break;
        }
    }
    return UUID.nameUUIDFromBytes(stream.toByteArray());
}
 
Example 6
Source File: CommandUtil.java    From NickNamer with MIT License 5 votes vote down vote up
static UUID findOfflineTargetUUID(CommandSender sender, String targetName, boolean otherTarget) {
	UUID uuid = null;
	if (otherTarget) {
		Player target = Bukkit.getPlayer(targetName);
		if (target != null) {
			uuid = target.getUniqueId();
		} else {
			try {
				// Paper
				uuid = Bukkit.getPlayerUniqueId(targetName);
			} catch (Exception ignored) {
				// Spigot
				OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(targetName);
				UUID offlineUuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + targetName).getBytes(Charsets.UTF_8));
				if (!offlineUuid.equals(offlinePlayer.getUniqueId())) { // We want the real UUID, not the one generated from OfflinePlayer:name
					uuid = offlinePlayer.getUniqueId();
				}
			}
		}
	} else {
		if (sender instanceof Player) {
			uuid = ((Player) sender).getUniqueId();
		} else {
			throw new InvalidLengthException(2, 1);
		}
	}
	if (uuid == null) {
		sender.sendMessage(MESSAGE_LOADER.getMessage("error.target.notFound", "error.target.notFound"));
		return null;
	}
	return uuid;
}
 
Example 7
Source File: TacKbp2017KBWriter.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
@MoveToBUECommon
private static UUID uuidFromRandom(Random rng) {
  final byte[] lowBits = Longs.toByteArray(rng.nextLong());
  final byte[] highBits = Longs.toByteArray(rng.nextLong());
  final byte[] allBits = new byte[16];
  System.arraycopy(lowBits, 0, allBits, 0, 8);
  System.arraycopy(highBits, 0, allBits, 8, 8);
  return UUID.nameUUIDFromBytes(allBits);
}
 
Example 8
Source File: UUIDTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @see UUID#nameUUIDFromBytes(byte[])
 */
public void test_nameUUIDFromBytes() throws Exception {
    byte[] name = { (byte) 0x6b, (byte) 0xa7, (byte) 0xb8, (byte) 0x11,
            (byte) 0x9d, (byte) 0xad, (byte) 0x11, (byte) 0xd1,
            (byte) 0x80, (byte) 0xb4, (byte) 0x00, (byte) 0xc0,
            (byte) 0x4f, (byte) 0xd4, (byte) 0x30, (byte) 0xc8 };

    UUID uuid = UUID.nameUUIDFromBytes(name);

    assertEquals(2, uuid.variant());
    assertEquals(3, uuid.version());

    assertEquals(0xaff565bc2f771745L, uuid.getLeastSignificantBits());
    assertEquals(0x14cdb9b4de013faaL, uuid.getMostSignificantBits());

    uuid = UUID.nameUUIDFromBytes(new byte[0]);
    assertEquals(2, uuid.variant());
    assertEquals(3, uuid.version());

    assertEquals(0xa9800998ecf8427eL, uuid.getLeastSignificantBits());
    assertEquals(0xd41d8cd98f003204L, uuid.getMostSignificantBits());

    try {
        UUID.nameUUIDFromBytes(null);
        fail("No NPE");
    } catch (NullPointerException e) {}
}
 
Example 9
Source File: IncrementalRemoteKeyedStateHandleTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static IncrementalRemoteKeyedStateHandle create(Random rnd) {
	return new IncrementalRemoteKeyedStateHandle(
		UUID.nameUUIDFromBytes("test".getBytes()),
		KeyGroupRange.of(0, 0),
		1L,
		placeSpies(CheckpointTestUtils.createRandomStateHandleMap(rnd)),
		placeSpies(CheckpointTestUtils.createRandomStateHandleMap(rnd)),
		spy(CheckpointTestUtils.createDummyStreamStateHandle(rnd)));
}
 
Example 10
Source File: FaweForge.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public UUID getUUID(String name) {
    try {
        return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8));
    } catch (Throwable e) {
        return null;
    }
}
 
Example 11
Source File: PhoenixReader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Retrieves the parent task for a Phoenix activity.
 *
 * @param activity Phoenix activity
 * @return parent task
 */
private ChildTaskContainer getParentTask(Activity activity)
{
   //
   // Make a map of activity codes and their values for this activity
   //
   Map<UUID, UUID> map = getActivityCodes(activity);

   //
   // Work through the activity codes in sequence
   //
   ChildTaskContainer parent = m_projectFile;
   StringBuilder uniqueIdentifier = new StringBuilder();
   for (UUID activityCode : m_codeSequence)
   {
      UUID activityCodeValue = map.get(activityCode);
      String activityCodeText = m_activityCodeValues.get(activityCodeValue);
      if (activityCodeText != null)
      {
         if (uniqueIdentifier.length() != 0)
         {
            uniqueIdentifier.append('>');
         }
         uniqueIdentifier.append(activityCodeValue.toString());
         UUID uuid = UUID.nameUUIDFromBytes(uniqueIdentifier.toString().getBytes());
         Task newParent = findChildTaskByUUID(parent, uuid);
         if (newParent == null)
         {
            newParent = parent.addTask();
            newParent.setGUID(uuid);
            newParent.setName(activityCodeText);
         }
         parent = newParent;
      }
   }
   return parent;
}
 
Example 12
Source File: MockAuthenticationService.java    From JMCCC with MIT License 5 votes vote down vote up
public static GameProfile createGameProfile(String name) {
	try {
		return new GameProfile(UUID.nameUUIDFromBytes(name.getBytes("UTF-8")), name);
	} catch (UnsupportedEncodingException e) {
		throw new IllegalStateException(e);
	}
}
 
Example 13
Source File: TestOzoneManagerRatisServer.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyRaftGroupIdGenerationWithDefaultOmServiceId() throws
    Exception {
  UUID uuid = UUID.nameUUIDFromBytes(OzoneConsts.OM_SERVICE_ID_DEFAULT
      .getBytes());
  RaftGroupId raftGroupId = omRatisServer.getRaftGroup().getGroupId();
  Assert.assertEquals(uuid, raftGroupId.getUuid());
  Assert.assertEquals(raftGroupId.toByteString().size(), 16);
}
 
Example 14
Source File: Xenserver625StorageProcessor.java    From cosmic with Apache License 2.0 4 votes vote down vote up
protected SR createFileSr(final Connection conn, final String remotePath, final String dir) {
    final String localDir = "/var/cloud_mount/" + UUID.nameUUIDFromBytes(remotePath.getBytes());
    mountNfs(conn, remotePath, localDir);
    final SR sr = createFileSR(conn, localDir + "/" + dir);
    return sr;
}
 
Example 15
Source File: RepositorySearcher.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public RepositorySearchResult consumeRepositorySearches(RepositorySearch repositorySearch) throws Exception {
	
	System.out.println("Searching " + repositorySearch.getRepository());
	
	TechrankWorkflowContext context = new TechrankWorkflowContext(workflow);
	
	File clone = new File(context.getProperties().getProperty("clones") + "/" + UUID.nameUUIDFromBytes(repositorySearch.getRepository().getBytes()));
	
	if (!clone.exists()) {
			
		try {
			// Try the command-line option first as it supports --depth 1
			Process process = Runtime.getRuntime().exec("git clone --depth 1 " + "https://github.com/" + 
					repositorySearch.getRepository() + ".git " + clone.getAbsolutePath());
			process.waitFor();
		}
		catch (Exception ex) {
			System.out.println("Falling back to JGit because " + ex.getMessage());
			Git.cloneRepository()
				.setURI( "https://github.com/" + repositorySearch.getRepository() + ".git" )
				.setDirectory(clone)
				.call();
		}
	}
	
	for (Technology technology : repositorySearch.getTechnologies()) {
		
		/* TODO: See why grep has stopped working (it returns 0 results even when the terminal says otherwise
		try {
			String grep = "grep -r -l --include=\"*." + technology.getExtension() + "\" \"" + 
					technology.getKeyword() + "\" " + clone.getAbsolutePath();
			
			System.out.println("Grepping: " + grep);
			
			Process process = Runtime.getRuntime().exec(grep);
			
			
			BufferedReader processInputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
			BufferedReader processErrorStream = new BufferedReader(new InputStreamReader(process.getErrorStream()));
			
			
			int files = 0;
			String s;
			while ((s = processInputStream.readLine()) != null) { 
				System.out.println("Found: " + s);
				files++; 
			}
			
			String e;
			while ((e = processErrorStream.readLine()) != null) { 
				System.out.println("Error: " + e);
			}
			
			RepositorySearchResult result = new RepositorySearchResult(technology.getName(), files, repositorySearch);
			sendToRepositorySearchResults(result);
			
		}
		catch (Exception ex) {
			System.out.println("Falling back to file-by-file searching because " + ex.getMessage());*/
			return new RepositorySearchResult(technology.getName(), countFiles(clone, technology), repositorySearch);
		//}
	}
	return null;
}
 
Example 16
Source File: GlucoseReadingRx.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public UUID getUuid() {
    data.rewind();
    final byte[] barr = new byte[data.remaining()];
    data.get(barr);
    return UUID.nameUUIDFromBytes(barr);
}
 
Example 17
Source File: SerializationTest.java    From rapidoid with Apache License 2.0 4 votes vote down vote up
private UUID uuid(int num) {
	return UUID.nameUUIDFromBytes(("UUID" + num).getBytes());
}
 
Example 18
Source File: Skin.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void generateSkinId(String name) {
    byte[] data = Binary.appendBytes(getSkinData().data, getSkinResourcePatch().getBytes(StandardCharsets.UTF_8));
    this.skinId = UUID.nameUUIDFromBytes(data) + "." + name;
}
 
Example 19
Source File: ConsoleSender.java    From Cleanstone with MIT License 4 votes vote down vote up
@Override
public Identity getID() {
    return new ConsoleIdentity(UUID.nameUUIDFromBytes("Console:0".getBytes(Charsets.UTF_8)));
}
 
Example 20
Source File: UuidUtils.java    From Velocity with MIT License 2 votes vote down vote up
/**
 * Generates a UUID for use for offline mode.
 *
 * @param username the username to use
 * @return the offline mode UUID
 */
public static UUID generateOfflinePlayerUuid(String username) {
  return UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8));
}