List of usage examples for java.util UUID getMostSignificantBits
public long getMostSignificantBits()
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 w w w. jav a2 s . com*/ public static byte[] makeUUIDBytes() { final UUID uuid = UUID.randomUUID(); return append(toBytes(uuid.getMostSignificantBits()), toBytes(uuid.getLeastSignificantBits())); }
From source file:org.texai.util.ByteUtils.java
/** Returns the 16-byte array from the given UUID. * * @param uuid the given UUID//from w ww. j ava 2 s .c om * @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 . j a va2 s.c o m*/ 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 w w . j ava 2 s .c o m 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; }
From source file:net.servicestack.client.Utils.java
public static byte[] toGuidBytes(UUID theUuid) { ByteBuffer first8 = ByteBuffer.allocate(8); first8.putLong(theUuid.getMostSignificantBits()); first8.rewind();//from ww w . ja v a 2 s .c om byte[] first4 = new byte[4]; first8.get(first4); reverse(first4); byte[] second2 = new byte[2]; first8.get(second2); reverse(second2); byte[] third2 = new byte[2]; first8.get(third2); reverse(third2); ByteBuffer converted16 = ByteBuffer.allocate(16).put(first4).put(second2).put(third2); ByteBuffer last8 = ByteBuffer.allocate(8); last8.putLong(theUuid.getLeastSignificantBits()); last8.rewind(); converted16.put(last8); return converted16.array(); }
From source file:org.apache.jackrabbit.oak.run.SegmentUtils.java
private static void debugSegment(FileStore store, String[] args) { Pattern pattern = Pattern.compile("([0-9a-f-]+)|(([0-9a-f-]+:[0-9a-f]+)(-([0-9a-f-]+:[0-9a-f]+))?)?(/.*)?"); for (int i = 1; i < args.length; i++) { Matcher matcher = pattern.matcher(args[i]); if (!matcher.matches()) { System.err.println("Unknown argument: " + args[i]); } else if (matcher.group(1) != null) { UUID uuid = UUID.fromString(matcher.group(1)); SegmentId id = store.getTracker().getSegmentId(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()); System.out.println(id.getSegment()); } else {/*from www . j av a2 s . co m*/ RecordId id1 = store.getHead().getRecordId(); RecordId id2 = null; if (matcher.group(2) != null) { id1 = RecordId.fromString(store.getTracker(), matcher.group(3)); if (matcher.group(4) != null) { id2 = RecordId.fromString(store.getTracker(), matcher.group(5)); } } String path = "/"; if (matcher.group(6) != null) { path = matcher.group(6); } if (id2 == null) { NodeState node = new SegmentNodeState(id1); System.out.println("/ (" + id1 + ") -> " + node); for (String name : PathUtils.elements(path)) { node = node.getChildNode(name); RecordId nid = null; if (node instanceof SegmentNodeState) { nid = ((SegmentNodeState) node).getRecordId(); } System.out.println(" " + name + " (" + nid + ") -> " + node); } } else { NodeState node1 = new SegmentNodeState(id1); NodeState node2 = new SegmentNodeState(id2); for (String name : PathUtils.elements(path)) { node1 = node1.getChildNode(name); node2 = node2.getChildNode(name); } System.out.println(JsopBuilder.prettyPrint(JsopDiff.diffToJsop(node1, node2))); } } } }
From source file:com.easemob.dataexport.utils.ConversionUtils.java
/** * @param uuid//from www . j a va2 s . c om * @return */ public static byte[] bytes(UUID uuid) { if (uuid == null) { return null; } long msb = uuid.getMostSignificantBits(); long lsb = uuid.getLeastSignificantBits(); 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; }
From source file:org.apache.jackrabbit.oak.run.SegmentTarUtils.java
private static void debugSegment(FileStore store, String[] args) { SegmentReader reader = store.getReader(); Pattern pattern = Pattern.compile("([0-9a-f-]+)|(([0-9a-f-]+:[0-9a-f]+)(-([0-9a-f-]+:[0-9a-f]+))?)?(/.*)?"); for (int i = 1; i < args.length; i++) { Matcher matcher = pattern.matcher(args[i]); if (!matcher.matches()) { System.err.println("Unknown argument: " + args[i]); } else if (matcher.group(1) != null) { UUID uuid = UUID.fromString(matcher.group(1)); SegmentId id = store.newSegmentId(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()); System.out.println(id.getSegment()); } else {/*from w w w .jav a 2 s .c o m*/ RecordId id1 = store.getRevisions().getHead(); RecordId id2 = null; if (matcher.group(2) != null) { id1 = fromString(store, matcher.group(3)); if (matcher.group(4) != null) { id2 = fromString(store, matcher.group(5)); } } String path = "/"; if (matcher.group(6) != null) { path = matcher.group(6); } if (id2 == null) { NodeState node = reader.readNode(id1); System.out.println("/ (" + id1 + ") -> " + node); for (String name : PathUtils.elements(path)) { node = node.getChildNode(name); RecordId nid = null; if (node instanceof SegmentNodeState) { nid = ((SegmentNodeState) node).getRecordId(); } System.out.println(" " + name + " (" + nid + ") -> " + node); } } else { NodeState node1 = reader.readNode(id1); NodeState node2 = reader.readNode(id2); for (String name : PathUtils.elements(path)) { node1 = node1.getChildNode(name); node2 = node2.getChildNode(name); } System.out.println(JsopBuilder.prettyPrint(JsopDiff.diffToJsop(node1, node2))); } } } }
From source file:com.mber.client.MberClient.java
public static String generateTransactionId() { UUID uuid = UUID.randomUUID(); long msb = uuid.getMostSignificantBits(); long lsb = uuid.getLeastSignificantBits(); byte[] buffer = new byte[16]; for (int i = 0; i < 8; ++i) { buffer[i] = (byte) (msb >> 8 * (7 - i)); }// ww w . ja v a 2s . com for (int i = 8; i < 16; ++i) { buffer[i] = (byte) (lsb >> 8 * (7 - i)); } return new String(Base64.encodeBase64(buffer)); }
From source file:uk.nhs.cfh.dsp.srth.query.transform.sql.impl.MySQLReportingQueryExecutionEngineService.java
public static byte[] asByteArray(UUID uuid) { long msb = uuid.getMostSignificantBits(); long lsb = uuid.getLeastSignificantBits(); byte[] buffer = new byte[16]; for (int i = 0; i < 8; i++) { buffer[i] = (byte) (msb >>> 8 * (7 - i)); }/* w w w.j a va 2 s .c o m*/ for (int i = 8; i < 16; i++) { buffer[i] = (byte) (lsb >>> 8 * (7 - i)); } return buffer; }