Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
public class GUID {
/**
*
* {talendTypes} byte | Byte
*
* {Category} User Defined
*
* {param} string("00000000-0000-0000-0000-000000000000") input: The guid as a string.
*
*/
public static byte[] stringToGuid(String guid) {
if (guid == null) {
return null; //$NON-NLS-1$
}
UUID uuid = UUID.fromString(guid);
long msb = uuid.getMostSignificantBits();
long lsb = uuid.getLeastSignificantBits();
byte[] output = new byte;
// Reverse the first 4 bytes
output = (byte) (msb >>> 8 * (7 - 3));
output = (byte) (msb >>> 8 * (7 - 2));
output = (byte) (msb >>> 8 * (7 - 1));
output = (byte) (msb >>> 8 * (7 - 0));
// Reverse 5th and 5th
output = (byte) (msb >>> 8 * (7 - 5));
output = (byte) (msb >>> 8 * (7 - 4));
// Reverse 7th and 8th
output = (byte) (msb >>> 8 * (7 - 7));
output = (byte) (msb >>> 8 * (7 - 6));
// Copy the rest
for (int i = 8; i < 16; i++) {
output = (byte) (lsb >>> 8 * (7 - i));
}
return output;
}
}