My favorites
▼
|
Sign in
pelops
A Java client library for the Cassandra database
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
src
/
org
/
wyki
/
cassandra
/
pelops
/
UuidHelper.java
r7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package org.wyki.cassandra.pelops;
public class UuidHelper {
/**
* Generate a new time UUID object
* @return A new time UUID object
*/
public static java.util.UUID newTimeUuid()
{
return java.util.UUID.fromString(new com.eaio.uuid.UUID().toString());
}
/**
* Generate a new time UUID in serialized form
* @return The serialized bytes of a new time UUID object
*/
public static byte[] newTimeUuidBytes()
{
return timeUuidToBytes(newTimeUuid());
}
/**
* Deserializes a TimeUUID from a byte array
* @param uuid The bytes of the time UUID
* @return The deserialized time UUID object
*/
public static java.util.UUID timeUuidFromBytes( byte[] uuid )
{
long msb = 0;
long lsb = 0;
assert uuid.length == 16;
for (int i=0; i<8; i++)
msb = (msb << 8) | (uuid[i] & 0xff);
for (int i=8; i<16; i++)
lsb = (lsb << 8) | (uuid[i] & 0xff);
com.eaio.uuid.UUID u = new com.eaio.uuid.UUID(msb,lsb);
return java.util.UUID.fromString(u.toString());
}
/**
* Serialize a time UUID into a byte array.
* @param uuid The time UUID to serialize
* @return The serialized bytes of the time UUID
*/
public static byte[] timeUuidToBytes(java.util.UUID uuid)
{
long msb = uuid.getMostSignificantBits();
long lsb = uuid.getLeastSignificantBits();
return uuidToBytes(msb, lsb);
}
public static byte[] uuidToBytes(long msb, long lsb) {
byte[] buffer = new byte[16];
for (int i = 0; i < 8; i++) {
buffer[i] = (byte) (msb >>> 8 * (7 - i));
}
for (int i = 8; i < 16; i++) {
buffer[i] = (byte) (lsb >>> 8 * (7 - i));
}
return buffer;
}
/**
* Convert a string representation of a time UUID into bytes
* @param uuidStr The string representation of the time UUID
* @return The serialized bytes of the represented time UUID object
*/
public static byte[] timeUuidStringToBytes(String uuidStr) {
return timeUuidToBytes(java.util.UUID.fromString(uuidStr));
}
}
Show details
Hide details
Change log
r2
by thedwilliams on Jun 8, 2010
Diff
[No log message]
Go to:
/trunk/build
/trunk/build/pelops.jar
/trunk/lib
...k/lib/apache-cassandra-0.6.0.jar
/trunk/lib/libthrift-r917130.jar
/trunk/lib/slf4j-api-1.5.10.jar
/trunk/lib/uuid-3.2-sources.jar
/trunk/lib/uuid-3.2.jar
/trunk/src
/trunk/src/org
/trunk/src/org/wyki
/trunk/src/org/wyki/cassandra
...nk/src/org/wyki/cassandra/pelops
...cassandra/pelops/IOperation.java
...cassandra/pelops/KeyDeletor.java
...ndra/pelops/KeyspaceOperand.java
...ki/cassandra/pelops/Metrics.java
...ki/cassandra/pelops/Mutator.java
...ssandra/pelops/NumberHelper.java
...ki/cassandra/pelops/Operand.java
...yki/cassandra/pelops/Pelops.java
...yki/cassandra/pelops/Policy.java
...i/cassandra/pelops/Selector.java
...ssandra/pelops/StringHelper.java
...cassandra/pelops/ThriftPool.java
...cassandra/pelops/UuidHelper.java
/trunk/src/org/wyki/concurrency
.../concurrency/AutoResetEvent.java
...yki/concurrency/IResetEvent.java
...oncurrency/ManualResetEvent.java
/trunk/src/org/wyki/networking
.../src/org/wyki/networking/utility
...g/utility/NetworkAlgorithms.java
/trunk/src/org/wyki/portability
.../portability/ILoggerFactory.java
...yki/portability/SystemProxy.java
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1991 bytes, 77 lines
View raw file
Powered by
Google Project Hosting