List of usage examples for java.util UUID UUID
public UUID(long mostSigBits, long leastSigBits)
From source file:com.joyent.manta.serialization.EncryptedMultipartUploadSerializationHelperTest.java
public void canSerializeAndDeserializeUpload() throws IOException { final UUID uploadId = new UUID(0L, 0L); final String path = "/user/stor/myObject"; final String partsDir = "/user/uploads/0/" + uploadId; final ServerSideMultipartUpload inner = new ServerSideMultipartUpload(uploadId, path, partsDir); final EncryptionContext encryptionContext = new EncryptionContext(secretKey, cipherDetails); final EncryptionState encryptionState = new EncryptionState(encryptionContext); @SuppressWarnings("unchecked") final EncryptedMultipartUpload<ServerSideMultipartUpload> upload = (EncryptedMultipartUpload<ServerSideMultipartUpload>) newUploadInstance( inner, encryptionState);/*from w ww . j av a2 s. com*/ Field cipherStreamField = ReflectionUtils.getField(EncryptionState.class, "cipherStream"); MultipartOutputStream multipartStream = new MultipartOutputStream(cipherDetails.getBlockSizeInBytes()); OutputStream cipherStream = EncryptingEntityHelper.makeCipherOutputForStream(multipartStream, encryptionContext); try { FieldUtils.writeField(cipherStreamField, encryptionState, cipherStream); } catch (IllegalAccessException e) { throw new AssertionError(e); } final byte[] serializedData = helper.serialize(upload); final EncryptedMultipartUpload<ServerSideMultipartUpload> deserialized = helper.deserialize(serializedData); Assert.assertEquals(upload, deserialized); }
From source file:org.primeframework.mvc.parameter.convert.converters.UUIDConverter.java
protected Object stringToObject(String value, Type convertTo, Map<String, String> attributes, String expression) throws ConversionException, ConverterStateException { if (emptyIsNull && StringUtils.isBlank(value)) { return null; }/*from www .jav a2 s .co m*/ try { return UUID.fromString(value); } catch (IllegalArgumentException iae) { // Try as an integer try { long l = Long.parseLong(value); return new UUID(0, l); } catch (NumberFormatException e) { throw new ConversionException(); } } }
From source file:org.spout.engine.filesystem.fields.UUIDField.java
public UUID getValue(Tag<?> tag) throws IllegalArgumentException { ListTag<LongTag> list = getList(tag, LongTag.class, 2); long msb = list.getValue().get(0).getValue(); long lsb = list.getValue().get(1).getValue(); return new UUID(msb, lsb); }
From source file:org.apache.bookkeeper.metadata.etcd.EtcdUtils.java
static String getLedgerKey(String scope, long scopeId, long ledgerId) { UUID uuid = new UUID(scopeId, ledgerId); return String.format("%s/ledgers/%s", scope, uuid.toString()); }
From source file:com.nestedbird.util.UUIDConverter.java
/** * Converts a Base64 encoded string to a string represented UUID * * @param base64String Base64 Representation of the UUID * @return String represented UUID/*from w ww. ja v a 2 s . c om*/ * @throws NullPointerException String must not be null * @throws IllegalArgumentException String should be 22 characters long */ public static String fromBase64(final String base64String) { if (base64String == null) throw new NullPointerException("String cannot be null"); if (base64String.length() != 22) throw new IllegalArgumentException("String should be 22 characters long"); final byte[] bytes = Base64.decodeBase64(base64String); final ByteBuffer bb = ByteBuffer.wrap(bytes); final UUID uuid = new UUID(bb.getLong(), bb.getLong()); return uuid.toString(); }
From source file:com.joyent.manta.serialization.EncryptedMultipartManagerSerializationTest.java
public void canSerializeEncryptedServerSideMultipartUpload() throws IOException { final UUID uploadId = new UUID(0L, 0L); final String path = "/user/stor/myObject"; final String partsDir = "/user/uploads/0/" + uploadId; final ServerSideMultipartUpload inner = new ServerSideMultipartUpload(uploadId, path, partsDir); final EncryptionContext encryptionContext = new EncryptionContext(secretKey, cipherDetails); final EncryptionState encryptionState = new EncryptionState(encryptionContext); Field cipherStreamField = ReflectionUtils.getField(EncryptionState.class, "cipherStream"); MultipartOutputStream multipartStream = new MultipartOutputStream(cipherDetails.getBlockSizeInBytes()); OutputStream cipherStream = EncryptingEntityHelper.makeCipherOutputForStream(multipartStream, encryptionContext);//ww w .j a v a 2s . co m try { FieldUtils.writeField(cipherStreamField, encryptionState, cipherStream); } catch (IllegalAccessException e) { throw new AssertionError(e); } final EncryptedMultipartUpload<?> upload = newUploadInstance(inner, encryptionState); final byte[] serializedData; try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Output output = new Output(outputStream)) { this.kryo.writeObject(output, upload); output.flush(); serializedData = outputStream.toByteArray(); } try (Input input = new Input(serializedData)) { final EncryptedMultipartUpload<?> actual = kryo.readObject(input, EncryptedMultipartUpload.class); Assert.assertEquals(actual, upload); } }
From source file:org.lenskit.eval.traintest.DataSetBuilder.java
/** * Set the group ID for this data set. The default is the all-0 UUID. * @param group The group ID, or `null` to reset to the default group. * @return The builder (for chaining)./*w w w . j a va 2s . c o m*/ */ public DataSetBuilder setIsolationGroup(@Nullable UUID group) { isoGroup = group != null ? group : new UUID(0, 0); return this; }
From source file:ninja.eivind.hotsreplayuploader.providers.hotslogs.HotsLogsProvider.java
private static UUID getUUID(byte[] bytes) { long msb = 0; long lsb = 0; assert bytes.length == 16 : "data must be 16 bytes in length"; for (int i = 0; i < 8; i++) { msb = (msb << 8) | (bytes[i] & 0xff); }/*from w w w . j a va 2s.c o m*/ for (int i = 8; i < 16; i++) { lsb = (lsb << 8) | (bytes[i] & 0xff); } return new UUID(msb, lsb); }
From source file:info.archinnov.achilles.it.TestEntityWithCompositePartitionKey.java
@Test public void should_insert() throws Exception { //Given/* ww w. ja va 2s . c o m*/ final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); final UUID uuid = new UUID(1L, 1L); final EntityWithCompositePartitionKey entity = new EntityWithCompositePartitionKey(id, uuid, "val"); //When manager.crud().insert(entity).execute(); //Then final List<Row> rows = session .execute("SELECT * FROM entity_composite_pk WHERE id = " + id + " AND uuid = " + uuid).all(); assertThat(rows).hasSize(1); final Row row = rows.get(0); assertThat(row.getLong("id")).isEqualTo(id); assertThat(row.getUUID("uuid")).isEqualTo(uuid); assertThat(row.getString("value")).isEqualTo("val"); }
From source file:org.wso2.carbon.analytics.data.commons.utils.AnalyticsCommonUtils.java
public static String generateRecordID() { byte[] data = new byte[16]; secureRandom.get().nextBytes(data);/*from w w w. j ava 2s. c o m*/ ByteBuffer buff = ByteBuffer.wrap(data); return new UUID(buff.getLong(), buff.getLong()).toString(); }