List of usage examples for java.util UUID getLeastSignificantBits
public long getLeastSignificantBits()
From source file:com.codelanx.codelanxlib.util.auth.UUIDFetcher.java
/** * Converts a {@link UUID} into bytes//from w w w . ja v a 2 s .co m * * @since 0.0.1 * @version 0.0.1 * * @param uuid The {@link UUID} to convert * @return The new byte array */ public static byte[] toBytes(UUID uuid) { ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); byteBuffer.putLong(uuid.getMostSignificantBits()); byteBuffer.putLong(uuid.getLeastSignificantBits()); return byteBuffer.array(); }
From source file:com.linuxbox.enkive.docstore.mongo.FileDocStoreServiceTest.java
private static byte[] generateFakeRandomHash() { final byte[] result = new byte[20]; final UUID u = UUID.randomUUID(); // transfer bits into array long bits = u.getMostSignificantBits(); for (int i = 0; i < 8; i++) { result[i] = (byte) (bits & 0xff); }//from w w w.j ava 2 s .co m bits = u.getLeastSignificantBits(); for (int i = 8; i < 16; i++) { result[i] = (byte) (bits & 0xff); } // remaining bytes should be 0s return result; }
From source file:Main.java
public static byte[] randomUUID() { long n;// w w w . ja va2s . c o m byte[] result; UUID uuid; result = new byte[16]; uuid = UUID.randomUUID(); n = uuid.getMostSignificantBits(); result[0] = (byte) (n >> 56 & 0xff); result[1] = (byte) (n >> 48 & 0xff); result[2] = (byte) (n >> 40 & 0xff); result[3] = (byte) (n >> 32 & 0xff); result[4] = (byte) (n >> 24 & 0xff); result[5] = (byte) (n >> 16 & 0xff); result[6] = (byte) (n >> 8 & 0xff); result[7] = (byte) (n & 0xff); n = uuid.getLeastSignificantBits(); result[8] = (byte) (n >> 56 & 0xff); result[9] = (byte) (n >> 48 & 0xff); result[10] = (byte) (n >> 40 & 0xff); result[11] = (byte) (n >> 32 & 0xff); result[12] = (byte) (n >> 24 & 0xff); result[13] = (byte) (n >> 16 & 0xff); result[14] = (byte) (n >> 8 & 0xff); result[15] = (byte) (n & 0xff); return result; }
From source file:Main.java
private static byte[] encodeUrnUuid(String urn, int position, ByteBuffer bb) { String uuidString = urn.substring(position, urn.length()); UUID uuid; try {//from w w w. j av a 2 s . com uuid = UUID.fromString(uuidString); } catch (IllegalArgumentException e) { //Log.w(TAG, "encodeUrnUuid invalid urn:uuid format - " + urn); return null; } // UUIDs are ordered as byte array, which means most significant first bb.order(ByteOrder.BIG_ENDIAN); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return byteBufferToArray(bb); }
From source file:com.palantir.atlasdb.ptobject.EncodingUtils.java
public static byte[] encodeUUID(UUID uuid) { return ByteBuffer.allocate(2 * Longs.BYTES).order(ByteOrder.BIG_ENDIAN) .putLong(uuid.getMostSignificantBits()).putLong(uuid.getLeastSignificantBits()).array(); }
From source file:org.texai.util.ByteUtils.java
/** Returns the array of bytes resulting from a new UUID. * * @return the array of bytes resulting from a new UUID *///from www . j ava2 s.co m public static byte[] makeUUIDBytes() { final UUID uuid = UUID.randomUUID(); return append(toBytes(uuid.getMostSignificantBits()), toBytes(uuid.getLeastSignificantBits())); }
From source file:org.apache.jackrabbit.oak.segment.Segment.java
/** * Determine the gc generation a segment from its data. Note that bulk segments don't have * generations (i.e. stay at 0)./*from ww w.jav a2 s . c o m*/ * * @param data the date of the segment * @param segmentId the id of the segment * @return the gc generation of this segment or 0 if this is bulk segment. */ public static int getGcGeneration(ByteBuffer data, UUID segmentId) { return isDataSegmentId(segmentId.getLeastSignificantBits()) ? data.getInt(GC_GENERATION_OFFSET) : 0; }
From source file:org.texai.util.ByteUtils.java
/** Returns the 16-byte array from the given UUID. * * @param uuid the given UUID//from w w w.j a v a 2s . co m * @return the 16-byte array from the given UUID */ public static byte[] toBytes(final UUID uuid) { //Preconditions assert uuid != null : "uuid must not be null"; return append(toBytes(uuid.getMostSignificantBits()), toBytes(uuid.getLeastSignificantBits())); }
From source file:org.openecomp.core.utilities.CommonMethods.java
/** * Gets an universally unique identifier (UUID). * * @return String representation of generated UUID. *///from w w w. ja v a 2 s.c om public static String nextUuId() { UUID uuid = UUID.randomUUID(); StringBuilder buff = new StringBuilder(32); long2string(uuid.getMostSignificantBits(), buff); long2string(uuid.getLeastSignificantBits(), buff); return buff.toString(); }
From source file:com.github.nlloyd.hornofmongo.util.BSONizer.java
@SuppressWarnings("deprecation") public static Object convertBSONtoJS(MongoScope mongoScope, Object bsonObject) { Object jsObject = null;/* w ww. j a v a 2s . c om*/ if (bsonObject instanceof List<?>) { List<?> bsonList = (List<?>) bsonObject; Scriptable jsArray = (Scriptable) MongoRuntime.call(new NewInstanceAction(mongoScope, bsonList.size())); int index = 0; for (Object bsonEntry : bsonList) { ScriptableObject.putProperty(jsArray, index, convertBSONtoJS(mongoScope, bsonEntry)); index++; } jsObject = jsArray; } else if (bsonObject instanceof BSONObject) { Scriptable jsObj = (Scriptable) MongoRuntime.call(new NewInstanceAction(mongoScope)); BSONObject bsonObj = (BSONObject) bsonObject; for (String key : bsonObj.keySet()) { Object value = convertBSONtoJS(mongoScope, bsonObj.get(key)); MongoRuntime.call(new JSPopulatePropertyAction(jsObj, key, value)); } jsObject = jsObj; } else if (bsonObject instanceof Symbol) { jsObject = ((Symbol) bsonObject).getSymbol(); } else if (bsonObject instanceof Date) { jsObject = MongoRuntime.call( new NewInstanceAction(mongoScope, "Date", new Object[] { ((Date) bsonObject).getTime() })); } else if (bsonObject instanceof Pattern) { Pattern regex = (Pattern) bsonObject; String source = regex.pattern(); String options = Bytes.regexFlags(regex.flags()); jsObject = MongoRuntime .call(new NewInstanceAction(mongoScope, "RegExp", new Object[] { source, options })); } else if (bsonObject instanceof org.bson.types.ObjectId) { jsObject = MongoRuntime.call(new NewInstanceAction(mongoScope, "ObjectId")); ((ObjectId) jsObject).setRealObjectId((org.bson.types.ObjectId) bsonObject); } else if (bsonObject instanceof org.bson.types.MinKey) { jsObject = MongoRuntime.call(new NewInstanceAction(mongoScope, "MinKey")); } else if (bsonObject instanceof org.bson.types.MaxKey) { jsObject = MongoRuntime.call(new NewInstanceAction(mongoScope, "MaxKey")); } else if (bsonObject instanceof com.mongodb.DBRef) { com.mongodb.DBRef dbRef = (com.mongodb.DBRef) bsonObject; Object id = convertBSONtoJS(mongoScope, dbRef.getId()); jsObject = MongoRuntime.call( new NewInstanceAction(mongoScope, "DBRef", new Object[] { dbRef.getCollectionName(), id })); } else if (bsonObject instanceof BSONTimestamp) { BSONTimestamp bsonTstamp = (BSONTimestamp) bsonObject; jsObject = MongoRuntime.call(new NewInstanceAction(mongoScope, "Timestamp", new Object[] { bsonTstamp.getTime(), bsonTstamp.getInc() })); } else if (bsonObject instanceof Long) { jsObject = MongoRuntime.call(new NewInstanceAction(mongoScope, "NumberLong")); ((NumberLong) jsObject).setRealLong((Long) bsonObject); } else if (bsonObject instanceof Integer) { jsObject = Double.valueOf((Integer) bsonObject); } else if (bsonObject instanceof Code) { jsObject = ((Code) bsonObject).getCode(); } else if (bsonObject instanceof byte[]) { jsObject = MongoRuntime.call(new NewInstanceAction(mongoScope, "BinData")); ((BinData) jsObject).setValues(0, (byte[]) bsonObject); } else if (bsonObject instanceof Binary) { jsObject = MongoRuntime.call(new NewInstanceAction(mongoScope, "BinData")); ((BinData) jsObject).setValues(((Binary) bsonObject).getType(), ((Binary) bsonObject).getData()); } else if (bsonObject instanceof UUID) { jsObject = MongoRuntime.call(new NewInstanceAction(mongoScope, "BinData")); UUID uuid = (UUID) bsonObject; ByteBuffer dataBuffer = ByteBuffer.allocate(16); // mongodb wire protocol is little endian dataBuffer.order(ByteOrder.LITTLE_ENDIAN); dataBuffer.putLong(uuid.getMostSignificantBits()); dataBuffer.putLong(uuid.getLeastSignificantBits()); ((BinData) jsObject).setValues(BSON.B_UUID, dataBuffer.array()); } else { jsObject = bsonObject; } return jsObject; }