List of usage examples for java.util UUID getMostSignificantBits
public long getMostSignificantBits()
From source file:com.pinterest.deployservice.common.CommonUtils.java
/** * TODO figure out how to use guava to achive this * * @return base64 encoded shorten UUID, e.g. 11YozyYYTvKmuUXpRDvoJA *//*from ww w .ja v a 2 s. co m*/ public static String getBase64UUID() { UUID uuid = UUID.randomUUID(); ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); buffer.putLong(uuid.getMostSignificantBits()); buffer.putLong(uuid.getLeastSignificantBits()); String base64 = BaseEncoding.base64Url().omitPadding().encode(buffer.array()); if (base64.charAt(0) == '_') { return 'x' + base64.substring(1); } if (base64.charAt(0) == '-') { return 'X' + base64.substring(1); } return base64; }
From source file:Main.java
/** * Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid. * * @param parcelUuid//from w w w .j a va2 s. c o m * @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise. */ public static boolean is16BitUuid(ParcelUuid parcelUuid) { UUID uuid = parcelUuid.getUuid(); if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) { return false; } return ((uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L); }
From source file:com.nestedbird.util.UUIDConverter.java
/** * Turns a UUID in string format to a Base64 encoded version * * @param uuidString String representation of the uuid * @return base64 encoded version of the uuid * @throws IllegalArgumentException String must be a valid uuid * @throws NullPointerException String cannot be null *///ww w .ja v a 2 s . c om public static String toBase64(final String uuidString) { if (uuidString == null) throw new NullPointerException("String cannot be null"); if (!isUUID(uuidString)) throw new IllegalArgumentException("string must be a valid uuid"); final UUID uuid = UUID.fromString(uuidString); final ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return Base64.encodeBase64URLSafeString(bb.array()); }
From source file:com.cnaude.mutemanager.UUIDFetcher.java
public static byte[] toBytes(UUID uuid) { ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); byteBuffer.putLong(uuid.getMostSignificantBits()); byteBuffer.putLong(uuid.getLeastSignificantBits()); return byteBuffer.array(); }
From source file:com.networknt.light.util.HashUtil.java
public static String generateUUID() { UUID id = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(id.getMostSignificantBits()); bb.putLong(id.getLeastSignificantBits()); Base64 base64 = new Base64(); return base64.encodeBase64URLSafeString(bb.array()); }
From source file:com.github.seqware.queryengine.system.Utility.java
/** * Parse a timestamp-less SGID from a String representation * * @param stringSGID a {@link java.lang.String} object. * @return a {@link com.github.seqware.queryengine.util.SGID} object. *///from ww w . ja va2s . c o m public static SGID parseSGID(String stringSGID) { SGID sgid; try { UUID uuid = UUID.fromString(stringSGID); sgid = new SGID(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits(), 0, null); } catch (IllegalArgumentException e) { String fRowKey = stringSGID; sgid = new SGID(0, 0, 0, fRowKey); } return sgid; }
From source file:Main.java
public static byte[] uuidToBytes(String uuidStr) { UUID uuid = stringToUuid(uuidStr); ByteBuffer bb = ByteBuffer.allocate(16); bb.order(ByteOrder.LITTLE_ENDIAN); bb.putLong(uuid.getLeastSignificantBits()); bb.putLong(uuid.getMostSignificantBits()); return bb.array(); }
From source file:org.brekka.phalanx.core.services.impl.AbstractCryptoService.java
/** * From http://stackoverflow.com/questions/772802/storing-uuid-as-base64-string. * @param uuid/*from w w w .j a v a 2s .c o m*/ * @return */ public static byte[] toBytes(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; }
From source file:com.intellectualcrafters.plot.uuid.UUIDFetcher.java
@SuppressWarnings("unused") public static byte[] toBytes(final UUID uuid) { final ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); byteBuffer.putLong(uuid.getMostSignificantBits()); byteBuffer.putLong(uuid.getLeastSignificantBits()); return byteBuffer.array(); }
From source file:Main.java
/** * check if full style or short (16bits) style UUID matches * * @param src the UUID to be compared/* ww w.j a v a2s .co m*/ * @param dst the UUID to be compared * @return true if the both of UUIDs matches */ public static boolean matches(@NonNull final UUID src, @NonNull final UUID dst) { if (isShortUuid(src) || isShortUuid(dst)) { // at least one instance is short style: check only 16bits long srcShortUUID = src.getMostSignificantBits() & 0x0000ffff00000000L; long dstShortUUID = dst.getMostSignificantBits() & 0x0000ffff00000000L; return srcShortUUID == dstShortUUID; } else { return src.equals(dst); } }