public static void toByteArray(UUID uuid, byte[] buffer, int offset) { _checkUUIDByteArray(buffer, offset); long hi = uuid.getMostSignificantBits(); long lo = uuid.getLeastSignificantBits(); _appendInt((int) (hi >> 32), buffer, offset); _appendInt((int) hi, buffer, offset+4); _appendInt((int) (lo >> 32), buffer, offset+8); _appendInt((int) lo, buffer, offset+12); }
protected final static long gatherLong(byte[] buffer, int offset) { long hi = ((long) _gatherInt(buffer, offset)) << 32; //long lo = ((long) _gatherInt(buffer, offset+4)) & MASK_LOW_INT; long lo = (((long) _gatherInt(buffer, offset+4)) << 32) >>> 32; return hi | lo; }
@Override public UUID generate(byte[] nameBytes) { byte[] digest; synchronized (_digester) { _digester.reset(); if (_namespace != null) { _digester.update(UUIDUtil.asByteArray(_namespace)); } _digester.update(nameBytes); digest = _digester.digest(); } return UUIDUtil.constructUUID(_type, digest); } }
public static UUID uuid(byte[] bytes, int offset) { _checkUUIDByteArray(bytes, offset); return new UUID(gatherLong(bytes, offset), gatherLong(bytes, offset+8)); }
/** * @param addr Hardware address (802.1) to use for generating * spatially unique part of UUID. If system has more than one NIC, */ public TimeBasedGenerator(EthernetAddress ethAddr, UUIDTimer timer) { byte[] uuidBytes = new byte[16]; if (ethAddr == null) { ethAddr = EthernetAddress.constructMulticastAddress(); } // initialize baseline with MAC address info _ethernetAddress = ethAddr; _ethernetAddress.toByteArray(uuidBytes, 10); // and add clock sequence int clockSeq = timer.getClockSequence(); uuidBytes[UUIDUtil.BYTE_OFFSET_CLOCK_SEQUENCE] = (byte) clockSeq; uuidBytes[UUIDUtil.BYTE_OFFSET_CLOCK_SEQUENCE+1] = (byte) (clockSeq >> 8); long l2 = UUIDUtil.gatherLong(uuidBytes, 8); _uuidL2 = UUIDUtil.initUUIDSecondLong(l2); _timer = timer; }
public static byte[] asByteArray(UUID uuid) { long hi = uuid.getMostSignificantBits(); long lo = uuid.getLeastSignificantBits(); byte[] result = new byte[16]; _appendInt((int) (hi >> 32), result, 0); _appendInt((int) hi, result, 4); _appendInt((int) (lo >> 32), result, 8); _appendInt((int) lo, result, 12); return result; }
public static long initUUIDFirstLong(long l1, UUIDType type) { return initUUIDFirstLong(l1, type.raw()); }
public static void toByteArray(UUID uuid, byte[] buffer) { toByteArray(uuid, buffer, 0); }
/** * Helper method for constructing UUID instances with appropriate type */ public static UUID constructUUID(UUIDType type, byte[] uuidBytes) { // first, ensure type is ok int b = uuidBytes[BYTE_OFFSET_TYPE] & 0xF; // clear out high nibble b |= type.raw() << 4; uuidBytes[BYTE_OFFSET_TYPE] = (byte) b; // second, ensure variant is properly set too b = uuidBytes[UUIDUtil.BYTE_OFFSET_VARIATION] & 0x3F; // remove 2 MSB b |= 0x80; // set as '10' uuidBytes[BYTE_OFFSET_VARIATION] = (byte) b; return uuid(uuidBytes); }
@Override public UUID generate() { /* 14-Oct-2010, tatu: Surprisingly, variant for reading byte array is * tad faster for SecureRandom... so let's use that then */ long r1, r2; if (_secureRandom) { final byte[] buffer = new byte[16]; _random.nextBytes(buffer); r1 = _toLong(buffer, 0); r2 = _toLong(buffer, 1); } else { r1 = _random.nextLong(); r2 = _random.nextLong(); } return UUIDUtil.constructUUID(UUIDType.RANDOM_BASED, r1, r2); }
/** * Factory method for constructing {@link java.util.UUID} instance from given * 16 bytes. * NOTE: since absolutely no validation is done for contents, this method should * usually not be used, unless contents are known to be valid. */ public static UUID uuid(byte[] bytes) { _checkUUIDByteArray(bytes, 0); long l1 = gatherLong(bytes, 0); long l2 = gatherLong(bytes, 8); return new UUID(l1, l2); }
/** * @param ethAddr Hardware address (802.1) to use for generating * spatially unique part of UUID. If system has more than one NIC, */ public TimeBasedGenerator(EthernetAddress ethAddr, UUIDTimer timer) { byte[] uuidBytes = new byte[16]; if (ethAddr == null) { ethAddr = EthernetAddress.constructMulticastAddress(); } // initialize baseline with MAC address info _ethernetAddress = ethAddr; _ethernetAddress.toByteArray(uuidBytes, 10); // and add clock sequence int clockSeq = timer.getClockSequence(); uuidBytes[UUIDUtil.BYTE_OFFSET_CLOCK_SEQUENCE] = (byte) (clockSeq >> 8); uuidBytes[UUIDUtil.BYTE_OFFSET_CLOCK_SEQUENCE+1] = (byte) clockSeq; long l2 = UUIDUtil.gatherLong(uuidBytes, 8); _uuidL2 = UUIDUtil.initUUIDSecondLong(l2); _timer = timer; }
public static byte[] asByteArray(UUID uuid) { long hi = uuid.getMostSignificantBits(); long lo = uuid.getLeastSignificantBits(); byte[] result = new byte[16]; _appendInt((int) (hi >> 32), result, 0); _appendInt((int) hi, result, 4); _appendInt((int) (lo >> 32), result, 8); _appendInt((int) lo, result, 12); return result; }
public static long initUUIDFirstLong(long l1, UUIDType type) { return initUUIDFirstLong(l1, type.raw()); }
public static void toByteArray(UUID uuid, byte[] buffer) { toByteArray(uuid, buffer, 0); }
/** * Helper method for constructing UUID instances with appropriate type */ public static UUID constructUUID(UUIDType type, byte[] uuidBytes) { // first, ensure type is ok int b = uuidBytes[BYTE_OFFSET_TYPE] & 0xF; // clear out high nibble b |= type.raw() << 4; uuidBytes[BYTE_OFFSET_TYPE] = (byte) b; // second, ensure variant is properly set too b = uuidBytes[UUIDUtil.BYTE_OFFSET_VARIATION] & 0x3F; // remove 2 MSB b |= 0x80; // set as '10' uuidBytes[BYTE_OFFSET_VARIATION] = (byte) b; return uuid(uuidBytes); }
@Override public UUID generate() { /* 14-Oct-2010, tatu: Surprisingly, variant for reading byte array is * tad faster for SecureRandom... so let's use that then */ long r1, r2; if (_secureRandom) { final byte[] buffer = new byte[16]; _random.nextBytes(buffer); r1 = _toLong(buffer, 0); r2 = _toLong(buffer, 1); } else { r1 = _random.nextLong(); r2 = _random.nextLong(); } return UUIDUtil.constructUUID(UUIDType.RANDOM_BASED, r1, r2); }
/** * Factory method for constructing {@link java.util.UUID} instance from given * 16 bytes. * NOTE: since absolutely no validation is done for contents, this method should * only be used if contents are known to be valid. */ public static UUID uuid(byte[] bytes) { _checkUUIDByteArray(bytes, 0); long l1 = gatherLong(bytes, 0); long l2 = gatherLong(bytes, 8); return new UUID(l1, l2); }
public static void toByteArray(UUID uuid, byte[] buffer, int offset) { _checkUUIDByteArray(buffer, offset); long hi = uuid.getMostSignificantBits(); long lo = uuid.getLeastSignificantBits(); _appendInt((int) (hi >> 32), buffer, offset); _appendInt((int) hi, buffer, offset+4); _appendInt((int) (lo >> 32), buffer, offset+8); _appendInt((int) lo, buffer, offset+12); }
@Override public UUID generate(byte[] nameBytes) { byte[] digest; synchronized (_digester) { _digester.reset(); if (_namespace != null) { _digester.update(UUIDUtil.asByteArray(_namespace)); } _digester.update(nameBytes); digest = _digester.digest(); } return UUIDUtil.constructUUID(_type, digest); } }