All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.core.uuid.UuidBytes Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.core.uuid;

import java.nio.ByteBuffer;
import java.util.UUID;

/**
 * Conversion methods between UUID and bytes array.
 *
 * @author Oliver Richers
 */
public class UuidBytes {

	public static UUID asUuid(byte[] bytes) {

		ByteBuffer bb = ByteBuffer.wrap(bytes);
		long firstLong = bb.getLong();
		long secondLong = bb.getLong();
		return new UUID(firstLong, secondLong);
	}

	public static byte[] asBytes(UUID uuid) {

		ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
		bb.putLong(uuid.getMostSignificantBits());
		bb.putLong(uuid.getLeastSignificantBits());
		return bb.array();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy