Example usage for java.util UUID nameUUIDFromBytes

List of usage examples for java.util UUID nameUUIDFromBytes

Introduction

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

Prototype

public static UUID nameUUIDFromBytes(byte[] name) 

Source Link

Document

Static factory to retrieve a type 3 (name based) UUID based on the specified byte array.

Usage

From source file:Main.java

public static void main(String[] args) {
    byte[] nbyte = { 10, 20, 30 };

    // creating UUID from byte     
    UUID uid = UUID.nameUUIDFromBytes(nbyte);

    // checking UUID value
    System.out.println("UUID value from byte: " + uid);
}

From source file:com.my.quickstart.util.Digests.java

/**
 * ?UUIDsalt//from   w ww.ja  va 2 s  .c om
 * @return
 */
public static String generateUUIDSalt() {
    byte[] b = KeyGenerators.secureRandom(16).generateKey();
    String salt = UUID.nameUUIDFromBytes(b).toString();
    return salt;
}

From source file:org.apache.nifi.registry.security.authorization.file.IdentifierUtil.java

static String getIdentifier(final String seed) {
    if (StringUtils.isBlank(seed)) {
        return null;
    }/*from   www.ja v  a  2 s . c  o  m*/

    return UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8)).toString();
}

From source file:QRCode.java

public static String createQRCode(String arg) {
    int size = 125;
    String fileType = "png";
    File myFile = null;/*ww  w  .j a  v  a  2s  . c  om*/
    UUID uuid = UUID.nameUUIDFromBytes(arg.getBytes());

    try {
        myFile = File.createTempFile("temp-file-name", ".png");

        Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        BitMatrix byteMatrix = qrCodeWriter.encode(uuid.toString(), BarcodeFormat.QR_CODE, size, size, hintMap);
        int CrunchifyWidth = byteMatrix.getWidth();
        BufferedImage image = new BufferedImage(CrunchifyWidth, CrunchifyWidth, BufferedImage.TYPE_INT_RGB);
        image.createGraphics();

        Graphics2D graphics = (Graphics2D) image.getGraphics();
        graphics.setColor(Color.WHITE);
        graphics.fillRect(0, 0, CrunchifyWidth, CrunchifyWidth);
        graphics.setColor(Color.BLACK);

        for (int i = 0; i < CrunchifyWidth; i++) {
            for (int j = 0; j < CrunchifyWidth; j++) {
                if (byteMatrix.get(i, j)) {
                    graphics.fillRect(i, j, 1, 1);
                }
            }
        }
        ImageIO.write(image, fileType, myFile);
        //System.out.println("\n\nYou have successfully created QR Code " + myFile.getCanonicalPath());
        return myFile.getCanonicalPath();
    } catch (WriterException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:org.usergrid.utils.CodecUtils.java

public static UUID decodeBase64UUID(String base64String) {
    byte[] bytes = base64.decode(base64String);
    return UUID.nameUUIDFromBytes(bytes);
}

From source file:org.wso2.carbon.dataservices.core.odata.ODataUtils.java

/**
 * This method generates an unique ETag for each data row entry.
 *
 * @param tableName Name of the table//from  w  w w  . ja va2s  .c o  m
 * @param entry     Data row entry
 * @return E Tag
 */
public static String generateETag(String configID, String tableName, ODataEntry entry) {
    StringBuilder uniqueString = new StringBuilder();
    uniqueString.append(configID).append(tableName);
    for (String columnName : entry.getNames()) {
        uniqueString.append(columnName).append(entry.getValue(columnName));
    }
    return UUID.nameUUIDFromBytes((uniqueString.toString()).getBytes()).toString();
}

From source file:Main.java

private static UUID getUuid(Context c) {
    final SharedPreferences prefs = c.getSharedPreferences(ID_PREFS_FILE, Context.MODE_PRIVATE);
    final String id = prefs.getString(ID_PREFS_DEVICE_ID, null);
    final UUID uuid;
    if (id != null) {
        uuid = UUID.fromString(id);
    } else {//from ww  w. j  a  v a  2 s .  c  om
        final String androidId = Secure.getString(c.getContentResolver(), Secure.ANDROID_ID);
        try {
            if (!BAD_UUID.equals(androidId)) {
                uuid = UUID.nameUUIDFromBytes(androidId.getBytes("utf8"));
            } else {
                final String deviceId = ((TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE))
                        .getDeviceId();
                if (deviceId != null)
                    uuid = UUID.nameUUIDFromBytes(deviceId.getBytes("utf8"));
                else
                    uuid = UUID.randomUUID();
            }
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        prefs.edit().putString(ID_PREFS_DEVICE_ID, uuid.toString()).commit();
    }
    return uuid;
}

From source file:lydichris.smashbracket.persistence.EntrantPersistence.java

public Entrant createEntrant(Entrant entrant) {
    UUID uuid = UUID.nameUUIDFromBytes((entrant.getTag() + entrant.getTournamentUuid()).getBytes());
    String SQL = "insert into entrants (uuid, tournament_uuid, user_uuid, tag, seed) values (?, ?, ?, ?, ?)";
    entrant.setUuid(uuid.toString());//from ww w  .j  a  v  a  2  s  .c om
    jdbcTemplateObject.update(SQL, entrant.getUuid(), entrant.getTournamentUuid(), entrant.getUserUuid(),
            entrant.getTag(), entrant.getSeed());
    return entrant;
}

From source file:org.apache.somewhere.general.BlankNodeImpl.java

BlankNodeImpl(String identifier) {
    // Mange the identifier with an internal startng point to produce a type 3 UUID. 
    uuid = UUID.nameUUIDFromBytes((SALT.toString() + ":" + identifier).getBytes(StandardCharsets.US_ASCII));
}

From source file:com.chiorichan.util.WebFunc.java

public static String createGUID(String seed) {
    if (seed == null)
        seed = "";

    byte[] bytes;
    try {/*w ww .  j  a v  a 2s . com*/
        bytes = seed.getBytes("ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
        bytes = new byte[0];
    }

    byte[] bytesScrambled = new byte[0];

    for (byte b : bytes) {
        byte[] tbyte = new byte[2];
        new Random().nextBytes(bytes);

        tbyte[0] = (byte) (b + tbyte[0]);
        tbyte[1] = (byte) (b + tbyte[1]);

        bytesScrambled = ArrayUtils.addAll(bytesScrambled, tbyte);
    }

    return "{" + UUID.nameUUIDFromBytes(bytesScrambled).toString() + "}";
}