【在 b**********5 的大作中提到】 : twitter streaming api, status json里的ID 是 : 64 bit long。 我现在要换成cassandra里的 uuid, 怎么convert?
C*i
4 楼
谣言说二月 Iphone5 可能在五月
b*5
5 楼
yes, i know. but i still want to convert that twitter ID to a uuid. actually, there are various version of uuid, time based, name based, random. twitter gives u the time based unique ID, the first 53 bits or so defines the time lapsed. But let's say we have a cassandra schema table whose primary key is uuid (or timeuuid). how can I convert the twitter ID to that cassandra uuid?
convert long to byte array, then construct UUID from the byte array? From Java Source code: /** * Static factory to retrieve a type 3 (name based) [email protected]/* */ UUID} based on * the specified byte array. * * @param name * A byte array to be used to construct a [email protected]/* */ UUID} * * @return A [email protected]/* */ UUID} generated from the specified array */ public static UUID nameUUIDFromBytes(byte[] name) { MessageDigest md; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException nsae) { throw new InternalError("MD5 not supported", nsae); } byte[] md5Bytes = md.digest(name); md5Bytes[6] &= 0x0f; /* clear version */ md5Bytes[6] |= 0x30; /* set to version 3 */ md5Bytes[8] &= 0x3f; /* clear variant */ md5Bytes[8] |= 0x80; /* set to IETF variant */ return new UUID(md5Bytes); }
random. defines that
【在 b**********5 的大作中提到】 : yes, i know. but i still want to convert that twitter ID to a uuid. : actually, there are various version of uuid, time based, name based, random. : twitter gives u the time based unique ID, the first 53 bits or so defines : the time lapsed. But let's say we have a cassandra schema table whose : primary key is uuid (or timeuuid). how can I convert the twitter ID to that : cassandra uuid?