I'm using this code to compact my UUIDs down to 22 chars strings :

        public static String asBase64String(UUID uuid) {
                return Base64.encodeBase64String(asByteArray(uuid));
        }

        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));
                }
                for (int i = 8; i < 16; i++) {
                        buffer[i] = (byte) (lsb >>> 8 * (7 - i));
                }

                return buffer;

        }

I'm using Apache Commons Codec for Base64 computations but other
librairies are available.

On 15 mai, 18:55, luka <[email protected]> wrote:
> Hey,
>
> I am currently using "Key as Encoded String"  on the child entities of
> my application model.
> When I create new child entity I set a special unique key to it using:
>
> java.util.UUID.randomUUID()
>
> This method ensure key uniqueness although it create a 144 character
> long string, which I fear will damage performance (due to his length),
> is my suspicious right ? should I employ other means to create unique
> key ?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/google-appengine?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to