List of usage examples for java.nio ByteBuffer putLong
public abstract ByteBuffer putLong(long value);
From source file:org.apache.camel.converter.NIOConverter.java
@Converter public static ByteBuffer toByteBuffer(Long value) { ByteBuffer buf = ByteBuffer.allocate(8); buf.putLong(value); return buf;//from ww w . java 2 s .co m }
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:com.knewton.mapreduce.util.RandomStudentEventGenerator.java
/** * Helper method for generating decorated increasing student ids. Used by * {@link WriteSampleSSTable} for writing a sorted SSTable. * * @return A list of byte buffers with student IDs */// w w w . j av a 2 s .c om public static List<ByteBuffer> getStudentIds(int numberOfStudents) { long studentId = 1000000L; List<ByteBuffer> studentIds = Lists.newArrayListWithCapacity(numberOfStudents); for (int i = 0; i < numberOfStudents; i++) { ByteBuffer bb = ByteBuffer.wrap(new byte[8]); bb.putLong(studentId++); bb.rewind(); studentIds.add(bb); } Collections.sort(studentIds, new Comparator<ByteBuffer>() { @Override public int compare(ByteBuffer o1, ByteBuffer o2) { DecoratedKey dk1 = StorageService.getPartitioner().decorateKey(o1); DecoratedKey dk2 = StorageService.getPartitioner().decorateKey(o2); return dk1.compareTo(dk2); } }); return studentIds; }
From source file:Main.java
public static String completeJweFromSIM(String jweSIM) { // android.os.Debug.waitForDebugger(); try {//from w ww .j a v a 2s. c o m if (jweSIM != null && jweSIM.length() > 0) { String parts[] = jweSIM.split("\\."); ; if (parts != null && parts.length == 5) { // retrieve hmac key byte hmac_key[] = Base64.decode(parts[4], Base64.URL_SAFE); if (hmac_key != null && hmac_key.length == 16) { // init hash instance Mac hmac = Mac.getInstance("HmacSHA256", "SC"); hmac.init(new SecretKeySpec(hmac_key, "HmacSHA256")); byte[] aad = parts[0].getBytes(); long al = aad.length * 8; byte[] iv_key = decodeB64(parts[2]); byte[] cryptedBytes = decodeB64(parts[3]); // build data to hash byte[] hmacData = new byte[aad.length + iv_key.length + cryptedBytes.length + 8]; int offset = 0; System.arraycopy(aad, offset, hmacData, 0, aad.length); offset += aad.length; System.arraycopy(iv_key, 0, hmacData, offset, iv_key.length); offset += iv_key.length; System.arraycopy(cryptedBytes, 0, hmacData, offset, cryptedBytes.length); offset += cryptedBytes.length; ByteBuffer buffer = ByteBuffer.allocate(8); buffer.putLong(al); System.arraycopy(buffer.array(), 0, hmacData, offset, 8); // compute hac value byte[] hmacValue = hmac.doFinal(hmacData); // authentication tag byte[] auth_tag = Arrays.copyOf(hmacValue, 16); String auth_tag64 = encodeB64(auth_tag); // A.2.7. Complete Representation String finalString = parts[0] + "." + parts[1] + "." + parts[2] + "." + parts[3] + "." + auth_tag64; // // just for verification // byte jwt64 [] = decryptJWE(finalString, RsaKeyTim.privRsaKey); // if(jwt64!=null) { // String jws = new String(jwt64); // Log.d("completeJweFromSIM", "jws verify Key TIM :"+verifyJWS(jws,RsaKeyTim.pubRsaKey)); // } return finalString; } } // } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.networknt.utility.Util.java
/** * Generate UUID across the entire app and it is used for correlationId. * * @return String correlationId/*from w ww.j a v a 2s .co m*/ */ public static String getUUID() { UUID id = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(id.getMostSignificantBits()); bb.putLong(id.getLeastSignificantBits()); return Base64.encodeBase64URLSafeString(bb.array()); }
From source file:com.pushtechnology.diffusion.examples.runnable.RandomData.java
/** * Serialize a {@link RandomData} value as a {@link Binary} value. * @param randomData The {@link RandomData} value * @return The {@link Binary} value//from w ww .j a v a 2 s. com */ static Binary toBinary(RandomData randomData) { final ByteBuffer buffer = ByteBuffer.allocate(16); buffer.putInt(randomData.getId()); buffer.putLong(randomData.getTimestamp()); buffer.putInt(randomData.getRandomInt()); return Diffusion.dataTypes().binary().readValue(buffer.array()); }
From source file:Main.java
static ByteBuffer createMsg(int state, long leader, long zxid, long epoch) { byte requestBytes[] = new byte[28]; ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes); /*// w w w . j a va 2 s. com * Building notification packet to send */ requestBuffer.clear(); requestBuffer.putInt(state); requestBuffer.putLong(leader); requestBuffer.putLong(zxid); requestBuffer.putLong(epoch); return requestBuffer; }
From source file:domain.Employee.java
private static String uuidToBase64(String str) { UUID uuid = UUID.fromString(str); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return Base64.encodeBase64URLSafeString(bb.array()); }
From source file:mtmo.test.mediadrm.Utils.java
public static String accountIdToMarlinFormat(final String accountId) { ByteBuffer accountIdBuf = ByteBuffer.allocate(BYTES_OF_ACCOUNT_ID); try {//from w w w .j av a 2 s .c o m accountIdBuf.putLong(Long.valueOf(accountId)); } catch (Exception e) { return null; } accountIdBuf.order(ByteOrder.LITTLE_ENDIAN); return String.format(Locale.US, "%016x", accountIdBuf.getLong(0)); }
From source file:info.gehrels.flockDBClient.ByteHelper.java
static ByteBuffer asByteBuffer(long... destinationIds) { ByteBuffer buf = null; buf = ByteBuffer.wrap(new byte[destinationIds.length * (Long.SIZE / 8)]); buf.order(ByteOrder.LITTLE_ENDIAN); for (long destinationId : destinationIds) { buf.putLong(destinationId); }/*from w w w .ja v a 2 s .c om*/ buf.rewind(); return buf; }