Example usage for java.util UUID randomUUID

List of usage examples for java.util UUID randomUUID

Introduction

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

Prototype

public static UUID randomUUID() 

Source Link

Document

Static factory to retrieve a type 4 (pseudo randomly generated) UUID.

Usage

From source file:Main.java

public static UUID randomUUID() {
    UUID ret;/*from   w  w  w . ja va 2 s .com*/
    do {
        ret = UUID.randomUUID();
    } while (usedUUIDs.contains(ret));
    usedUUIDs.add(ret);
    return ret;
}

From source file:Main.java

public static String generateDocumentId() {
    return UUID.randomUUID().toString();
}

From source file:Main.java

/**
 * Generates a Base64 version of UUID/*www  .  ja v a 2 s.c om*/
 * @return a string in Base64 URL-safe format without padding at the end and no wrapping
 */
public static String randomUuidBase64() {
    UUID uuid = UUID.randomUUID();
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    return encodeUrlSafe64(bb.array());
}

From source file:Main.java

public static String createVoiceFile() {
    return createFile(VOICE_PATH, UUID.randomUUID() + ".amr");
}

From source file:Main.java

public static String getDeviceId(TelephonyManager tm) {
    String id = tm.getSubscriberId();
    if (TextUtils.isEmpty(id)) {
        id = tm.getDeviceId();//  w ww.ja va2s  .co m
    }
    if (TextUtils.isEmpty(id)) {
        id = UUID.randomUUID().toString();
    }
    return id;
}

From source file:Main.java

private static String saveCroppedImage(Bitmap bmp) {
    File file = new File("/sdcard/myFolder");
    UUID uuid = UUID.randomUUID();
    String uid = uuid.toString();
    if (!file.exists())
        file.mkdir();// w  w  w  .  j a v a  2s  . com
    String name = "/sdcard/" + uid + ".jpg";
    file = new File(name.trim());
    String fileName = file.getName();
    String mName = fileName.substring(0, fileName.lastIndexOf("."));
    String sName = fileName.substring(fileName.lastIndexOf("."));

    // /sdcard/myFolder/temp_cropped.jpg
    String newFilePath = "/sdcard/myFolder" + "/" + mName + "_cropped" + sName;
    file = new File(newFilePath);
    try {
        file.createNewFile();
        FileOutputStream fos = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.JPEG, 50, fos);
        fos.flush();
        fos.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return newFilePath;
}

From source file:Main.java

public static String UUID() {
    return UUID.randomUUID().toString();
}

From source file:Main.java

/**
 * Generates UUID string./*from w  w  w . j a  va2s  .  c  o m*/
 *
 * @param prefix string attached to uuid ('prefix', '-', 'uuid')
 * @return generated id as string
 */
public static String uuidString(final String prefix) {
    return prefix + "-" + UUID.randomUUID().toString();
}

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

/**
 * Generate random uuid.//from   w w w  .  j a  v a  2  s.  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:Main.java

/**
 * This method generates the unique GUID string of the length specified in passed
 * parameter./*  w w  w. j a  v  a 2s .c  om*/
 *
 * @param notAllowedChars Regular expression to replace any invalid characters
 * @param length Length to restrict the output to
 * @return the unique string
 */
public static String generateGUID(String notAllowedChars, int length) {
    String guid = UUID.randomUUID().toString();
    // Remove all the hypen's (-) from the page token
    guid = guid.replaceAll(notAllowedChars, "");
    // make it a 32-bit token
    guid = guid.substring(0, length);
    return guid;
}