Java Convert via ByteBuffer toUUID(byte[] uuid)

Here you can find the source of toUUID(byte[] uuid)

Description

Returns an instance of uuid.

License

Open Source License

Parameter

Parameter Description
uuid the uuid

Return

the java.util.uuid

Declaration

public static java.util.UUID toUUID(byte[] uuid) 

Method Source Code


//package com.java2s;
//License from project: MIT License 

import java.nio.ByteBuffer;
import java.util.UUID;

public class Main {
    /**//from w  ww  .  ja v  a2 s .  c om
    * Returns an instance of uuid. Useful for when you read out of cassandra
    * you are getting a byte[] that needs to be converted into a TimeUUID.
    *
    * @param uuid the uuid
    * @return the java.util.uuid
    */
    public static java.util.UUID toUUID(byte[] uuid) {
        return uuid(uuid, 0);
    }

    public static UUID uuid(byte[] uuid, int offset) {
        ByteBuffer bb = ByteBuffer.wrap(uuid, offset, 16);
        return new UUID(bb.getLong(), bb.getLong());
    }

    /**
    * Converts a ByteBuffer containing a UUID into a java.util.UUID
    * @param bb a ByteBuffer containing a UUID
    * @return a java.util.UUID
    */
    public static UUID uuid(ByteBuffer bb) {
        bb = bb.slice();
        return new UUID(bb.getLong(), bb.getLong());
    }
}

Related

  1. toThriftBinary(UUID uuid)
  2. toURI(String value)
  3. toUTF(byte[] bytes)
  4. toUTF8(String str)
  5. toUuid(byte[] bytes)
  6. toUUIDBinary(UUID uuid)