List of usage examples for java.util UUID getLeastSignificantBits
public long getLeastSignificantBits()
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 w ww . j a v a 2s.com*/ 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 w ww . ja v a2s . c o m*/ * @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. j av a2s. 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)); }/*from ww w . ja v a 2s . c o m*/ 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)); }//from w ww .ja v a 2s .co m for (int i = 8; i < 16; i++) { buffer[i] = (byte) (lsb >>> 8 * (7 - i)); } return buffer; }
From source file:org.apache.jackrabbit.oak.plugins.segment.file.TarReader.java
/** * Regenerates a tar file from a list of entries. * /*from www. j a v a 2 s. co m*/ * @param entries * @param file * @throws IOException */ private static void generateTarFile(LinkedHashMap<UUID, byte[]> entries, File file) throws IOException { log.info("Regenerating tar file " + file); TarWriter writer = new TarWriter(file); for (Map.Entry<UUID, byte[]> entry : entries.entrySet()) { UUID uuid = entry.getKey(); byte[] data = entry.getValue(); writer.writeEntry(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits(), data, 0, data.length); } writer.close(); }
From source file:org.apache.jackrabbit.oak.segment.file.TarReader.java
private static Map<UUID, List<UUID>> parseGraph(ByteBuffer graphByteBuffer, boolean bulkOnly) { int count = graphByteBuffer.getInt(graphByteBuffer.limit() - 12); ByteBuffer buffer = graphByteBuffer.duplicate(); buffer.limit(graphByteBuffer.limit() - 16); List<UUID> uuids = newArrayListWithCapacity(count); for (int i = 0; i < count; i++) { uuids.add(new UUID(buffer.getLong(), buffer.getLong())); }/*from ww w. j a v a 2 s.com*/ Map<UUID, List<UUID>> graph = newHashMap(); while (buffer.hasRemaining()) { UUID uuid = uuids.get(buffer.getInt()); List<UUID> list = newArrayList(); int refid = buffer.getInt(); while (refid != -1) { UUID ref = uuids.get(refid); if (!bulkOnly || !isDataSegmentId(ref.getLeastSignificantBits())) { list.add(ref); } refid = buffer.getInt(); } graph.put(uuid, list); } return graph; }
From source file:org.primeframework.mvc.parameter.convert.converters.UUIDConverter.java
protected String objectToString(Object value, Type convertFrom, Map<String, String> attributes, String expression) throws ConversionException, ConverterStateException { UUID uuid = (UUID) value; if (uuid.getMostSignificantBits() == 0) { return Long.toString(uuid.getLeastSignificantBits()); }//w w w . ja v a 2 s .c om return value.toString(); }
From source file:org.apache.jackrabbit.oak.segment.file.TarReader.java
/** * Regenerates a tar file from a list of entries. * //w w w .j a v a2s . c o m * @param entries * @param file * @throws IOException */ private static void generateTarFile(LinkedHashMap<UUID, byte[]> entries, File file) throws IOException { log.info("Regenerating tar file {}", file); TarWriter writer = new TarWriter(file); for (Map.Entry<UUID, byte[]> entry : entries.entrySet()) { UUID uuid = entry.getKey(); byte[] data = entry.getValue(); int generation = getGcGeneration(wrap(data), uuid); writer.writeEntry(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits(), data, 0, data.length, generation); } writer.close(); }
From source file:org.dashbuilder.dataset.UUIDGeneratorImpl.java
public String uuidToBase64(String str) { UUID uuid = UUID.fromString(str); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return Base64.encodeBase64URLSafeString(bb.array()); }