/** * @param uuid * @return */ public static UUID uuid( byte[] uuid ) { return uuid( uuid, 0 ); }
/** * @param obj * @return */ public static UUID uuid( Object obj ) { return uuid( obj, UUIDUtils.ZERO_UUID ); }
public static UUID getUUIDFromRowKey( ByteBuffer bytes ) { return ConversionUtils.uuid( bytes ); }
public static UUID uuid( Object obj, UUID defaultValue ) { if ( obj instanceof UUID ) { return ( UUID ) obj; } else if ( obj instanceof byte[] ) { return uuid( ( byte[] ) obj ); } else if ( obj instanceof ByteBuffer ) { return uuid( ( ByteBuffer ) obj ); } else if ( obj instanceof String ) { return uuid( ( String ) obj ); } return defaultValue; }
public static UUID fromBase64( String str ) { if ( str == null ) { return null; } byte[] bytes = decodeBase64( str ); if ( bytes.length != 16 ) { return null; } return uuid( bytes ); }
public UUID getStartResult() { if ( ( startResult == null ) && ( cursor != null ) ) { byte[] cursorBytes = decodeBase64( cursor ); if ( ( cursorBytes != null ) && ( cursorBytes.length == 16 ) ) { startResult = uuid( cursorBytes ); } } return startResult; }
public void setCursor( String cursor ) { if ( cursor != null ) { if ( cursor.length() == 22 ) { byte[] cursorBytes = decodeBase64( cursor ); if ( ( cursorBytes != null ) && ( cursorBytes.length == 16 ) ) { startResult = uuid( cursorBytes ); cursor = null; } } } this.cursor = cursor; }
public static UUID maxTimeUUID( long ts ) { byte[] uuidBytes = new byte[16]; uuidBytes[10] = ( byte ) 0xFF; uuidBytes[11] = ( byte ) 0xFF; uuidBytes[12] = ( byte ) 0xFF; uuidBytes[13] = ( byte ) 0xFF; uuidBytes[14] = ( byte ) 0xFF; uuidBytes[15] = ( byte ) 0xFF; setTimestamp( ts, uuidBytes, 0x3FFF, 0x1FFF ); return uuid( uuidBytes ); }
@Override public long getMaxTokenAge( String token ) { TokenCategory tokenCategory = TokenCategory.getFromBase64String( token ); byte[] bytes = decodeBase64( token.substring( TokenCategory.BASE64_PREFIX_LENGTH ) ); UUID uuid = uuid( bytes ); long timestamp = getTimestampInMillis( uuid ); int i = 16; if ( tokenCategory.getExpires() ) { long expires = ByteBuffer.wrap( bytes, i, 8 ).getLong(); return expires - timestamp; } return Long.MAX_VALUE; }
return uuid( bytes );
public UserInfo( UUID applicationId, Map<String, Object> properties ) { this.applicationId = applicationId; id = uuid( properties.remove( PROPERTY_UUID ) ); username = string( properties.remove( PROPERTY_USERNAME ) ); name = string( properties.remove( PROPERTY_NAME ) ); email = string( properties.remove( PROPERTY_EMAIL ) ); confirmed = getBoolean( properties.remove( PROPERTY_CONFIRMED ) ); activated = getBoolean( properties.remove( PROPERTY_ACTIVATED ) ); disabled = getBoolean( properties.remove( PROPERTY_DISABLED ) ); admin = getBoolean( properties.remove( PROPERTY_ADMIN) ); this.properties = properties; }
@JsonIgnore public synchronized UUID getUuid() { UUID uuid = uuid( properties.get( MESSAGE_ID ), null ); if ( uuid == null ) { if ( properties.containsKey( MESSAGE_TIMESTAMP ) ) { long ts = getLongValue( properties, MESSAGE_TIMESTAMP ); uuid = newTimeUUID( ts ); } else { uuid = newTimeUUID(); } properties.put( MESSAGE_ID, uuid ); properties.put( MESSAGE_TIMESTAMP, getTimestampInMillis( uuid ) ); } return uuid; }
private UUID getUUIDForToken(String token ) throws ExpiredTokenException, BadTokenException { TokenCategory tokenCategory = TokenCategory.getFromBase64String( token ); byte[] bytes = decodeBase64( token.substring( TokenCategory.BASE64_PREFIX_LENGTH ) ); UUID uuid = uuid( bytes ); int i = 16; long expires = Long.MAX_VALUE; if ( tokenCategory.getExpires() ) { expires = ByteBuffer.wrap( bytes, i, 8 ).getLong(); i = 24; } ByteBuffer expected = ByteBuffer.allocate( 20 ); expected.put( sha( tokenCategory.getPrefix() + uuid + tokenSecretSalt + expires ) ); expected.rewind(); ByteBuffer signature = ByteBuffer.wrap( bytes, i, 20 ); if ( !signature.equals( expected ) ) { throw new BadTokenException( "Invalid token signature" ); } long expirationDelta = System.currentTimeMillis() - expires; if ( expires != Long.MAX_VALUE && expirationDelta > 0 ) { throw new ExpiredTokenException( String.format( "Token expired %d milliseconds ago.", expirationDelta ) ); } return uuid; }
/** Returns a UUID that is -1 of the passed uuid, sorted by time uuid only */ public static UUID decrement( UUID uuid ) { if ( !isTimeBased( uuid ) ) { throw new IllegalArgumentException( "The uuid must be a time type" ); } //timestamp is in the 60 bit timestamp long timestamp = uuid.timestamp(); timestamp--; if ( timestamp < 0 ) { throw new IllegalArgumentException( "You must specify a time uuid with a timestamp > 0" ); } //get our bytes, then set the smaller timestamp into it byte[] uuidBytes = bytes( uuid ); setTime( uuidBytes, timestamp ); return uuid( uuidBytes ); }
return uuid( bytes );
/** @return object of correct type deserialize from column bytes */ public static Object deserializeEntityProperty( String entityType, String propertyName, ByteBuffer bytes ) { Object propertyValue = null; if ( PROPERTY_UUID.equals( propertyName ) ) { propertyValue = uuid( bytes ); } else if ( PROPERTY_TYPE.equals( propertyName ) ) { propertyValue = string( bytes ); } else { if ( Schema.getDefaultSchema().isPropertyEncrypted( entityType, propertyName ) ) { bytes = decrypt( bytes ); } propertyValue = Schema.deserializePropertyValueFromJsonBinary( bytes ); } return propertyValue; }
return uuid( obj );
public static ByteBuffer serializeEntityProperty( String entityType, String propertyName, Object propertyValue ) { ByteBuffer bytes = null; if ( PROPERTY_UUID.equals( propertyName ) ) { bytes = bytebuffer( uuid( propertyValue ) ); } else if ( PROPERTY_TYPE.equals( propertyName ) ) { bytes = bytebuffer( string( propertyValue ) ); } else { bytes = Schema.serializePropertyValueToJsonBinary( toJsonNode( propertyValue ) ); if ( Schema.getDefaultSchema().isPropertyEncrypted( entityType, propertyName ) ) { bytes.rewind(); bytes = encrypt( bytes ); } } return bytes; }
organizationId = uuid( properties.get( PROPERTY_UUID ) );
/** * Generate a timeuuid with the given timestamp in milliseconds and the time offset. Useful when you need to * generate sequential UUIDs for the same period in time. I.E * <p/> * newTimeUUID(1000, 0) <br/> newTimeUUID(1000, 1) <br /> newTimeUUID(1000, 2) <br /> * <p/> * etc. * <p/> * Only use this method if you are absolutely sure you need it. When it doubt use the method without the timestamp * offset * * @param ts The timestamp in milliseconds * @param timeoffset The offset, which should always be <= 10000. If you go beyond this range, the millisecond will * be incremented since this is beyond the possible values when coverrting from millis to 1/10 microseconds stored * in the time uuid. */ public static UUID newTimeUUID( long ts, int timeoffset ) { if ( ts == 0 ) { return newTimeUUID(); } byte[] uuidBytes = new byte[16]; // 47 bits of randomness EthernetAddress eth = EthernetAddress.constructMulticastAddress(); eth.toByteArray( uuidBytes, 10 ); setTimestamp( ts, uuidBytes, getRandomClockSequence(), timeoffset ); return uuid( uuidBytes ); }