uuid 作为通用识别码,其java的实现版本如下 ,本文以 将url(https://blog.youkuaiyun.com/renyuanfang/article/details/86701148)转换成uuid为例,实现具体的代码实现
import java.util.UUID;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.io.IOException;
public class uuid_test {
public static void main (String[] args) throws IOException{
final Charset UTF8 = Charset.forName("UTF-8");
String url = "https://blog.youkuaiyun.com/renyuanfang/article/details/86701148";
UUID NAMESPACE = UUID.fromString("6ba7b811-9dad-11d1-80b4-00c04fd430c8");
byte[] input = url.getBytes(UTF8);
long least = NAMESPACE.getLeastSignificantBits();
long most = NAMESPACE.getMostSignificantBits();
byte[] out = new byte[16 + input.length];
ByteBuffer buffer = ByteBuffer.wrap(out).order(ByteOrder.BIG_ENDIAN);
buffer.putLong(most);
buffer.putLong(least);
buffer.put(input);
System.out.println(UUID.nameUUIDFromBytes(out).toString());
}
}
python 的生成版本如下:https://blog.youkuaiyun.com/renyuanfang/article/details/90213667