Example usage for java.util UUID toString

List of usage examples for java.util UUID toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a String object representing this UUID .

Usage

From source file:cn.edu.sdnu.i.util.xauth.Xauth.java

public static String doMethod(String url) {
    // ?TreeMapparameters?????url?
    TreeMap<String, String> parameters = new TreeMap<String, String>();

    // 1.consumerkeyapp???keykey??app?key
    parameters.put(Constants.ConsumerKeyParameter, consumerKey);
    Log.d("test1", "1.consumerKey:" + consumerKey);

    // 2.UUID???????
    /*//from   w w  w .j  a  v  a 2 s .c  om
     * ?GUID
     * 
     * 
     * ??GUID???????10GUID?
     * ??? FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF
     */

    UUID uuid = UUID.randomUUID();

    // ????ws?
    String guid = uuid.toString();

    // nonce
    parameters.put(Constants.NonceParameter, guid);
    Log.d("test1", "2.guid:" + guid);

    // 3.?Hmacsha1
    parameters.put(Constants.SignatureMethodParameter, HMACSHA1SignatureType);
    Log.d("test1", "3.SignatureMethodParameter:" + HMACSHA1SignatureType);

    // 4.
    /*
     * 
     * 
     * 
     * Unix???UTC??197011000??? ?2014/1/29
     * 16:56:58UTC+8UTC2014/1/29
     * 8:56:58?Unix160998565813909858181390985818
     * ??60?
     */
    parameters.put(Constants.TimestampParameter, Long.toString(System.currentTimeMillis() / 1000));
    Log.d("test1", "4.TimestampParameter:" + Long.toString(System.currentTimeMillis() / 1000));

    // 5.TokenKey
    parameters.put(Constants.TokenParameter, token);
    Log.d("test", "5.TokenKey:" + token);

    // 6.XAuth??1.0?
    parameters.put(Constants.VersionParameter, OAuthVersion);
    Log.d("test1", "6.VersionParameter:" + OAuthVersion);

    // ????
    // ??StringBuffer?String??result
    StringBuffer resultBuffer = new StringBuffer("");

    // http?statusresult

    Boolean status = TryRequestRemote(url, tokenSecret, parameters, resultBuffer);
    Log.d("test1", "7.http?statusresult:" + resultBuffer.toString());
    return resultBuffer.toString();
}

From source file:com.enonic.cms.framework.util.UUIDGenerator.java

/**
 * Generate random uuid.//from w w w  . ja va2s .  co m
 */
public static String randomUUID() {
    UUID uuid = UUID.randomUUID();

    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DataOutputStream dataOut = new DataOutputStream(out);
        dataOut.writeLong(uuid.getMostSignificantBits());
        dataOut.writeLong(uuid.getLeastSignificantBits());
        dataOut.close();
        return new String(Hex.encodeHex(out.toByteArray()));
    } catch (Exception e) {
        return uuid.toString();
    }
}

From source file:edu.monash.merc.util.DMUtil.java

public static String genUUIDWithPrefix(String prefix) {
    UUID uuid = UUID.randomUUID();
    return prefix + uuid.toString();
}

From source file:gov.nih.nci.cagrid.identifiers.test.StressTestUtil.java

private static void addSomeRandomIdentifiers(List<String> list) {
    for (int i = 0; i < randomIdentifierSize; i++) {
        UUID temp = UUID.randomUUID();
        int tempSize = list.size() - 1;
        list.add(rand.nextInt(tempSize), temp.toString());
    }//from  w w w .ja v  a  2 s. c o  m
}

From source file:com.spleefleague.core.utils.DatabaseConnection.java

public static Rank getRank(UUID uuid) {
    Rank rank = rankCache.getRank(uuid);
    if (rank != null) {
        return rank;
    }/*  w  w  w  .  j a va 2s. c  o  m*/
    Document dbo = SpleefLeague.getInstance().getPluginDB().getCollection("Players")
            .find(new Document("uuid", uuid.toString())).first();
    if (dbo != null) {
        rank = Rank.valueOf((String) dbo.get("rank"));
        updateCache(uuid, rank);
        return rank;
    } else {
        return null;
    }
}

From source file:org.nebulaframework.deployment.classloading.node.exporter.GridNodeClassExporterSupport.java

/**
 * Creates an returns a proxy object which can be used to access the
 * {@code GridNodeClassExporter} service of a given {@code GridNode}.
 * <p>/*from   w  w w . j  a  v  a  2 s  .  co m*/
 * This method relies on Spring JMS Remoting API's proxy support to create
 * the proxy object.
 * 
 * @param nodeId
 *            Node Id of target {@code GridNode}
 * @param connectionFactory
 *            JMS {@code ConnectionFactory}
 * 
 * @return The {@code GridNodeClassExporter} Service Proxy
 */
public static GridNodeClassExporter createServiceProxy(UUID nodeId, ConnectionFactory cf)
        throws IllegalArgumentException {

    // Check for nulls
    String queueName = getExporterQueueName(nodeId);

    // Return Proxy Object
    GridNodeClassExporter proxy = JMSRemotingSupport.createProxy(cf, queueName, GridNodeClassExporter.class);

    // CleanUp Hook
    CleanUpSupport.removeQueueWhenNodeLeft(nodeId.toString(), queueName);

    return proxy;
}

From source file:com.ntsync.android.sync.shared.SyncUtils.java

/**
 * Stores a Payment to make sure that the Payment will be verified and
 * processed.//w  ww  . j  a v a 2 s .  c o m
 * 
 * @param account
 * @param accountManager
 * @param paymentConf
 *            null: clear any stored information.
 * @param priceId
 *            null: clear any stored information
 */
public static void savePayment(Account account, AccountManager accountManager, JSONObject paymentConf,
        UUID priceId) {
    String storeValue = priceId == null || paymentConf == null ? null
            : priceId.toString() + ";" + paymentConf.toString() + ";" + System.currentTimeMillis();
    accountManager.setUserData(account, LAST_PAYMENT, storeValue);
}

From source file:com.spleefleague.core.utils.DatabaseConnection.java

public static String getUsername(UUID uuid) {
    String username = uuidCache.getUsername(uuid);
    if (username != null) {
        return username;
    }// w w  w  .  j  a va  2s. c o m
    Document dbo = SpleefLeague.getInstance().getPluginDB().getCollection("Players")
            .find(new Document("uuid", uuid.toString())).first();
    if (dbo != null) {
        username = (String) dbo.get("username");
        updateCache(uuid, username);
        return username;
    } else {
        return null;
    }
}

From source file:com.microsoft.windowsazure.services.media.samples.contentprotection.playreadywidevine.Program.java

public static ContentKeyInfo createCommonTypeContentKey(AssetInfo asset) {
    try {/*from w w w. j a v  a 2 s  . c  o m*/
        // Get the protection key id for ContentKey
        String protectionKeyId = mediaService
                .action(ProtectionKey.getProtectionKeyId(ContentKeyType.CommonEncryption));

        // Download and create the X509 certificate
        String protectionKey = mediaService.action(ProtectionKey.getProtectionKey(protectionKeyId));
        X509Certificate certificate = (X509Certificate) CertificateFactory.getInstance("X.509")
                .generateCertificate(new ByteArrayInputStream(Base64.decode(protectionKey)));

        // Create a new ContentKey (secure random)
        byte[] contentKeyData = new byte[16];
        EncryptionUtils.eraseKey(contentKeyData);

        // Encrypt ContentKey
        byte[] encryptedContentKey = EncryptionUtils.encryptSymmetricKeyData(certificate, contentKeyData);
        String encryptedContentKeyString = Base64.encode(encryptedContentKey);

        // Create the ContentKey Id
        UUID contentKeyIdUuid = UUID.randomUUID();
        String contentKeyId = String.format("nb:kid:UUID:%s", contentKeyIdUuid.toString());

        // Calculate the checksum
        String checksum = EncryptionUtils.calculateChecksum(contentKeyData, contentKeyIdUuid);

        // Create the ContentKey entity
        ContentKeyInfo contentKey = mediaService.create(
                ContentKey.create(contentKeyId, ContentKeyType.CommonEncryption, encryptedContentKeyString)
                        .setChecksum(checksum).setProtectionKeyType(ProtectionKeyType.X509CertificateThumbprint)
                        .setName("Common Encryption Content Key")
                        .setProtectionKeyId(EncryptionUtils.getThumbPrint(certificate)));

        // Associate the ContentKey with the Asset
        mediaService.action(Asset.linkContentKey(asset.getId(), contentKeyId));

        return contentKey;

    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

    return null;
}

From source file:Main.java

/**
 * Checks if the given UUID starts with the given service UUID i.e. their beginnings match.
 *
 * @param uuidToCheck The UUID to check.
 * @param serviceUuid The expected service UUID to compare against.
 * @return True, if the beginnings match. False otherwise.
 *//*  w  ww .j  a va  2s.  c  o m*/
public static boolean uuidStartsWithExpectedServiceUuid(UUID uuidToCheck, UUID serviceUuid) {
    boolean startsWithExpectedServiceUuid = false;

    if (uuidToCheck != null && serviceUuid != null) {
        if (serviceUuid.compareTo(uuidToCheck) == 0) {
            // The UUID is a match
            // No need to do anything
            startsWithExpectedServiceUuid = true;
        } else {
            // Get the beginning of the parsed UUID, leave out the last seven bytes (11 chars)
            String beginningOfUuidToCheck = uuidToCheck.toString().substring(0, 22);
            startsWithExpectedServiceUuid = serviceUuid.toString().startsWith(beginningOfUuidToCheck);
        }
    }

    return startsWithExpectedServiceUuid;
}