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:com.nestedbird.util.UUIDConverter.java

/**
 * Converts a Base64 encoded string to a string represented UUID
 *
 * @param base64String Base64 Representation of the UUID
 * @return String represented UUID/*from  w  w w .jav  a 2s.  c  om*/
 * @throws NullPointerException     String must not be null
 * @throws IllegalArgumentException String should be 22 characters long
 */
public static String fromBase64(final String base64String) {
    if (base64String == null)
        throw new NullPointerException("String cannot be null");
    if (base64String.length() != 22)
        throw new IllegalArgumentException("String should be 22 characters long");

    final byte[] bytes = Base64.decodeBase64(base64String);
    final ByteBuffer bb = ByteBuffer.wrap(bytes);
    final UUID uuid = new UUID(bb.getLong(), bb.getLong());
    return uuid.toString();
}

From source file:Main.java

/**
 * this generate the device Id/*  w  w  w .j  ava  2 s .  c  om*/
 *
 * @param baseContext
 * @param contentResolver
 * @return
 */
//http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id
public static String generateDeviceId(Context baseContext, ContentResolver contentResolver) {

    final TelephonyManager tm = (TelephonyManager) baseContext.getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, androidId;
    tmDevice = String.valueOf(tm.getDeviceId());
    tmSerial = String.valueOf(tm.getSimSerialNumber());
    androidId = String.valueOf(android.provider.Settings.Secure.getString(contentResolver,
            android.provider.Settings.Secure.ANDROID_ID));

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    return deviceUuid.toString();

}

From source file:Main.java

private static String generateDeviceUniqueIdentifier(Context context) {
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    final String tmDevice = "" + tm.getDeviceId();
    final String tmSerial = "" + tm.getSimSerialNumber();
    final String androidId = ""
            + Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    final String packageBasedAndroidId = context.getPackageName() + androidId;

    UUID deviceUuid = new UUID(packageBasedAndroidId.hashCode(),
            ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    return deviceUuid.toString();
}

From source file:org.trustedanalytics.uploader.security.PermissionVerifierTest.java

private static CcOrgPermission allOrgRoles(UUID guid) {
    return new CcOrgPermission(new CcOrg(guid, guid.toString()), true, true, true);
}

From source file:org.trustedanalytics.uploader.security.PermissionVerifierTest.java

private static CcOrgPermission noOrgRoles(UUID guid) {
    return new CcOrgPermission(new CcOrg(guid, guid.toString()), false, false, false);
}

From source file:Main.java

public static String getDeviceUUID(Context context) {

    @SuppressWarnings("static-access")
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, tmPhone, androidId;

    tmDevice = "" + tm.getDeviceId();

    tmSerial = "" + tm.getSimSerialNumber();

    androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(),
            android.provider.Settings.Secure.ANDROID_ID);

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());

    String uniqueId = deviceUuid.toString();

    Log.d("debug", "uuid=" + uniqueId);

    return uniqueId;
}

From source file:com.feedzai.fos.api.util.ManagerUtils.java

/**
 * Creates a file in {@code <location>/<id>.model} and serializes the given byte array to it.
 *
 * @param location The target location where the binary will be written to.
 * @param id       The UUID of the model.
 * @param model    The serialized classifier.
 * @return The File where the model was written to.
 * @throws java.io.IOException if saving to disk was not possible.
 *//*from  ww w  . j ava  2  s . c  o m*/
private static File createModelBinaryFile(File location, UUID id, byte[] model) throws IOException {
    File file = File.createTempFile(id.toString(), ".model", location);
    FileUtils.writeByteArrayToFile(file, model);
    return file;
}

From source file:com.feedzai.fos.api.util.ManagerUtils.java

/**
 * Creates a file in {@code <location>/<id>.xml} and serializes the given String to it.
 *
 * @param location The target location where the binary will be written to.
 * @param id       The UUID of the model.
 * @param pmml     The String containing the PMML representation.
 * @return The File where the model was written to.
 * @throws java.io.IOException if saving to disk was not possible.
 *///from   www  . j a  v a 2s  .co  m
private static File createModelPMMLFile(File location, UUID id, String pmml) throws IOException {
    File file = File.createTempFile(id.toString(), ".xml", location);

    try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
        writer.write(pmml);
    }

    return file;
}

From source file:Main.java

public static String getDeviceId(Context context) {

    if (deviceId == null) {

        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

        String tmDevice, tmSerial, tmPhone, androidId;
        tmDevice = "" + tm.getDeviceId();
        tmSerial = "" + tm.getSimSerialNumber();
        androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(),
                android.provider.Settings.Secure.ANDROID_ID);

        UUID deviceUuid = new UUID(androidId.hashCode(),
                ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
        deviceId = deviceUuid.toString();

        System.err.println(deviceId);
    }// ww w  . j  a v  a2  s .c o  m
    return deviceId;
}

From source file:eu.dasish.annotation.backend.Helpers.java

public static UUID generateUUID() {
    UUID result = UUID.randomUUID();
    char[] chars = result.toString().toCharArray();
    if (chars[0] >= 'a' && chars[0] <= 'z') {
        return result;
    } else {//ww w  . j  ava2  s.com
        Random r = new Random();
        chars[0] = hexa.charAt(r.nextInt(hexan));
        result = UUID.fromString(new String(chars));
        return result;
    }
}