Java UUID to Byte Array uuidToBytes(UUID uuid)

Here you can find the source of uuidToBytes(UUID uuid)

Description

Converts a UUID object to a byte array for storing in MySQL.

License

Open Source License

Parameter

Parameter Description
uuid The UUID to convert.

Return

A byte array.

Declaration

public static byte[] uuidToBytes(UUID uuid) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

import java.util.UUID;

public class Main {
    /**//from  w  w w  . ja va 2  s.  co  m
     * Converts a UUID object to a byte array for storing in MySQL.
     * 
     * @param uuid The UUID to convert.
     * @return A byte array.
     * @since 2.0
     */
    public static byte[] uuidToBytes(UUID uuid) {
        ByteBuffer bb = ByteBuffer.wrap(new byte[16]);

        bb.putLong(uuid.getMostSignificantBits());
        bb.putLong(uuid.getLeastSignificantBits());

        return bb.array();
    }
}

Related

  1. uuidToBase58(UUID uuid)
  2. uuidToByteArray(UUID uuid)
  3. uuidToBytes(UUID id)
  4. uuidToBytes(UUID uuid)
  5. uuidToBytes(UUID uuid)
  6. uuidToBytesNullOk(UUID uuid)