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

The following examples show how to use java.util.UUID#toString() . 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: IntegrationTestReplication.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Run the {@link org.apache.hadoop.hbase.test.IntegrationTestBigLinkedList.Verify}
 * in the sink cluster. If replication is working properly the data written at the source
 * cluster should be available in the sink cluster after a reasonable gap
 *
 * @param expectedNumNodes the number of nodes we are expecting to see in the sink cluster
 * @throws Exception
 */
protected void runVerify(long expectedNumNodes) throws Exception {
  Path outputPath = new Path(outputDir);
  UUID uuid = util.getRandomUUID(); //create a random UUID.
  Path iterationOutput = new Path(outputPath, uuid.toString());

  Verify verify = new Verify();
  verify.setConf(sink.getConfiguration());

  int retCode = verify.run(iterationOutput, numReducers);
  if (retCode > 0) {
    throw new RuntimeException("Verify.run failed with return code: " + retCode);
  }

  if (!verify.verify(expectedNumNodes)) {
    throw new RuntimeException("Verify.verify failed");
  }

  LOG.info("Verify finished with success. Total nodes=" + expectedNumNodes);
}
 
Example 2
Source File: AccountManager.java    From The-5zig-Mod with GNU General Public License v3.0 6 votes vote down vote up
public AccountManager() {
    // The client generates a random UUID for authentication.
    UUID uuid = UUID.randomUUID();

    AuthenticationService service = new YggdrasilAuthenticationService(The5zigMod.getVars().getProxy(), uuid.toString());
    userAuth = service.createUserAuthentication(Agent.MINECRAFT);
    service.createMinecraftSessionService();

    isNewManager = !new File(The5zigMod.getModDirectory(), "accounts.enc").exists();
}
 
Example 3
Source File: JsBridge.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
private String getIdentity() {
    if (mPlatformLoginInterface != null && mPlatformLoginInterface.getLoginUser() != null) {
        String customUDID = mPlatformLoginInterface.getLoginUser().getCustomerDeviceId();
        return customUDID != null ? customUDID : "";
    } else {
        if (mPlatform != null && mPlatform.getPlatformInfo() != null && TextUtils.isEmpty(mPlatform.getPlatformInfo().getIdentity())) {
            return mPlatform.getPlatformInfo().getIdentity();
        }
        UUID uuid = VenvyDeviceUtil.getDeviceUuid(mContext);
        if (uuid != null) {
            return uuid.toString();
        }
    }
    return "";
}
 
Example 4
Source File: RabbitMQ.java    From AntiVPN with MIT License 5 votes vote down vote up
private Builder(UUID serverID, MessagingHandler handler) {
    if (serverID == null) {
        throw new IllegalArgumentException("serverID cannot be null.");
    }
    if (handler == null) {
        throw new IllegalArgumentException("handler cannot be null.");
    }

    result.uuidServerID = serverID;
    result.serverID = serverID.toString();
    result.handler = handler;
}
 
Example 5
Source File: AclEntityFactory.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static RootPersistentEntity createAclEntity(String entityType, String uuid) {
    // Validate the uuid first, exception will be thrown if the uuid string is not a valid uuid
    UUID uuidObj = UUID.fromString(uuid);
    uuid = uuidObj.toString();

    if (CUBE_INSTANCE.equals(entityType)) {
        CubeInstance cubeInstance = new CubeInstance();
        cubeInstance.setUuid(uuid);

        return cubeInstance;
    }

    if (DATA_MODEL_DESC.equals(entityType)) {
        DataModelDesc modelInstance = new DataModelDesc();
        modelInstance.setUuid(uuid);

        return modelInstance;
    }

    if (JOB_INSTANCE.equals(entityType)) {
        JobInstance jobInstance = new JobInstance();
        jobInstance.setUuid(uuid);

        return jobInstance;
    }

    if (PROJECT_INSTANCE.equals(entityType)) {
        ProjectInstance projectInstance = new ProjectInstance();
        projectInstance.setUuid(uuid);

        return projectInstance;
    }

    throw new RuntimeException("Unsupported entity type!");
}
 
Example 6
Source File: RandomUtils.java    From jfinal-api-scaffold with MIT License 5 votes vote down vote up
/**
 * 生成32位UUID字符,去除字符'-'
 * @return 32位随机UUID字符串
 */
public static String randomCustomUUID() {
    UUID uuid = UUID.randomUUID();
    String uuidStr = uuid.toString();

    return uuidStr.replaceAll("-","");
}
 
Example 7
Source File: MessageIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that receiving a message with a UUID typed message-id results in returning the
 * expected value for JMSMessageId where the JMS "ID:" prefix has been added to the UUID.tostring()
 *
 * @throws Exception if an error occurs during the test.
 */
@Test(timeout = 20000)
public void testReceivedMessageWithUUIDMessageIdReturnsExpectedJMSMessageID() throws Exception {
    UUID uuid = UUID.randomUUID();
    String expected = "ID:AMQP_UUID:" + uuid.toString();
    receivedMessageWithMessageIdTestImpl(uuid, expected);
}
 
Example 8
Source File: ExampleController.java    From building-microservices with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/")
public String hello(HttpSession session) {
	UUID uid = (UUID) session.getAttribute("uid");
	if (uid == null) {
		uid = UUID.randomUUID();
	}
	session.setAttribute("uid", uid);
	return uid.toString();
}
 
Example 9
Source File: KdbxHeader.java    From KeePassJava2 with Apache License 2.0 5 votes vote down vote up
public void setCipherUuid(byte[] uuid) {
    ByteBuffer b = ByteBuffer.wrap(uuid);
    UUID incoming = new UUID(b.getLong(), b.getLong(8));
    if (!incoming.equals(AES_CIPHER)) {
        throw new IllegalStateException("Unknown Cipher UUID " + incoming.toString());
    }
    this.cipherUuid = incoming;
}
 
Example 10
Source File: AmqpMessageIdHelperTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
 * indicating an AMQP encoded UUID when given a UUID object.
 */
@Test
public void testToMessageIdStringWithUUID() {
    UUID uuidMessageId = UUID.randomUUID();
    String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_UUID_PREFIX + uuidMessageId.toString();

    doToMessageIdTestImpl(uuidMessageId, expected);
}
 
Example 11
Source File: HeliumOnlineRegistry.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public HeliumOnlineRegistry(String name, String uri, File registryCacheDir) {
  super(name, uri);
  registryCacheDir.mkdirs();
  UUID registryCacheFileUuid = UUID.nameUUIDFromBytes(uri.getBytes());
  this.registryCacheFile = new File(registryCacheDir, registryCacheFileUuid.toString());

  gson = new Gson();
}
 
Example 12
Source File: DownloadSharedPreferenceEntry.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Check if a string is a valid GUID. GUID is RFC 4122 compliant, it should have format
 * xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
 * TODO(qinmin): move this to base/.
 * @return true if the string is a valid GUID, or false otherwise.
 */
static boolean isValidGUID(String guid) {
    if (guid == null) return false;
    try {
        // Java UUID class doesn't check the length of the string. Need to convert it back to
        // string so that we can validate the length of the original string.
        UUID uuid = UUID.fromString(guid);
        String uuidString = uuid.toString();
        return guid.equalsIgnoreCase(uuidString);
    } catch (IllegalArgumentException e) {
        return false;
    }
}
 
Example 13
Source File: AMQPMessageIdHelperTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Test that {@link AMQPMessageIdHelper#toIdObject(String)} returns a UUID
 * when given a string indicating an encoded AMQP uuid id.
 *
 * @throws Exception
 *         if an error occurs during the test.
 */
@Test
public void testToIdObjectWithEncodedUuid() throws Exception {
   UUID uuid = UUID.randomUUID();
   String provided = AMQPMessageIdHelper.JMS_ID_PREFIX + AMQPMessageIdHelper.AMQP_UUID_PREFIX + uuid.toString();

   doToIdObjectTestImpl(provided, uuid);
}
 
Example 14
Source File: AmqpMessageIdHelperTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
 * indicating an AMQP encoded UUID when given a UUID object.
 */
@Test
public void testToCorrelationIdStringWithUUID() {
    UUID uuidCorrelationId = UUID.randomUUID();
    String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_UUID_PREFIX + uuidCorrelationId.toString();

    doToCorrelationIDTestImpl(uuidCorrelationId, expected);
}
 
Example 15
Source File: UuidStrategy.java    From mongo-kafka with Apache License 2.0 5 votes vote down vote up
@Override
public BsonValue generateId(final SinkDocument doc, final SinkRecord orig) {
  UUID uuid = UUID.randomUUID();
  if (outputFormat.equals(UuidBsonFormat.STRING)) {
    return new BsonString(uuid.toString());
  }

  return new BsonBinary(uuid, UuidRepresentation.STANDARD);
}
 
Example 16
Source File: IDGenerator.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
public static String createId() {
	UUID uuid = UUID.randomUUID();
	return uuid.toString();
}
 
Example 17
Source File: Relic.java    From Shadbot with GNU General Public License v3.0 4 votes vote down vote up
public Relic(UUID id, RelicType type, Duration duration) {
    super(new RelicBean(id.toString(), type.toString(), duration.toMillis(), null, null, null));
}
 
Example 18
Source File: KafkaBoardClient.java    From event-store-demo with GNU General Public License v3.0 3 votes vote down vote up
@Override
    public Board find( final UUID boardUuid ) {
        log.debug( "find : enter" );

//        while( true ) {

            try {

                ReadOnlyKeyValueStore<String, Board> store = queryableStoreRegistry.getQueryableStoreType( BOARD_EVENTS_SNAPSHOTS, QueryableStoreTypes.<String, Board>keyValueStore() );

                Board board = store.get( boardUuid.toString() );
                if( null != board ) {

                    board.flushChanges();
                    log.debug( "find : board=" + board.toString() );

                    log.debug( "find : exit" );
                    return board;

                } else {

                    throw new IllegalArgumentException( "board[" + boardUuid.toString() + "] not found!" );
                }

            } catch( InvalidStateStoreException e ) {
                log.error( "find : error", e );

//                try {
//                    Thread.sleep( 100 );
//                } catch( InterruptedException e1 ) {
//                    log.error( "find : thread interrupted", e1 );
//                }

            }

//        }

        throw new IllegalArgumentException( "board[" + boardUuid.toString() + "] not found!" );
    }
 
Example 19
Source File: NoSuchStoreException.java    From database with GNU General Public License v2.0 2 votes vote down vote up
public NoSuchStoreException(UUID uuid) {
    
    this(uuid.toString());
    
}
 
Example 20
Source File: StoreManager.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the file on which a new {@link IndexSegment} should be written.
 * The file will exist but will have zero length. The file is created using
 * the {@link File#createTempFile(String, String, File)} mechanism within
 * the configured {@link #dataDir} in the subdirectory for the specified
 * scale-out index.
 * <p>
 * Note: The index name appears in the file path above the {@link UUID} of
 * the scale-out index. Therefore it is not possible to have collisions
 * arise in the file system when given indices whose scale-out names differ
 * only in characters that are munged onto the same character since the
 * files will always be stored in a directory specific to the scale-out
 * index.
 * 
 * @param scaleOutIndexName
 *            The name of the scale-out index.
 * @param indexUUID
 *            The UUID of the scale-out index.
 * @param partitionId
 *            The index partition identifier -or- <code>-1</code> if the
 *            index is not partitioned (handles the MDS which does not use
 *            partitioned indices at this time).
 * 
 * @return The {@link File} on which a {@link IndexSegmentStore} for that
 *         index partition may be written. The file will be unique and
 *         empty.
 * 
 * @throws IllegalArgumentException
 *             if any argument is <code>null</code>
 * @throws IllegalArgumentException
 *             if the partitionId is negative and not <code>-1</code>
 * 
 * @todo should the filename be relative or absolute?
 */
public File getIndexSegmentFile(final String scaleOutIndexName,
        final UUID indexUUID, final int partitionId) {

    assertOpen();

    if (scaleOutIndexName == null)
        throw new IllegalArgumentException();

    if (indexUUID == null)
        throw new IllegalArgumentException();

    if (partitionId < -1)
        throw new IllegalArgumentException();
    
    // munge index name to fit the file system.
    final String mungedName = munge(scaleOutIndexName);

    // subdirectory into which the individual index segs will be placed.
    final File indexDir = new File(segmentsDir, mungedName + File.separator
            + indexUUID.toString());

    // make sure that directory exists.
    indexDir.mkdirs();

    final String partitionStr = (partitionId == -1 ? "" : "_shardId"
            + leadingZeros.format(partitionId));

    final String prefix = mungedName + "" + partitionStr + "_";

    final File file;
    try {

        file = File.createTempFile(prefix, Options.SEG, indexDir);

    } catch (IOException e) {

        throw new RuntimeException(e);

    }

    if (log.isInfoEnabled())
        log.info("Created file: " + file);

    return file;

}