List of usage examples for java.nio ByteBuffer putLong
public abstract ByteBuffer putLong(long value);
From source file:org.apache.airavata.gfac.core.GFacUtils.java
public static byte[] longToBytes(long x) { ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.putLong(x); return buffer.array(); }
From source file:org.lab41.hbase.TitanHbaseIdSplitter.java
public byte[] longToBytes(long x) { ByteBuffer buffer = ByteBuffer.allocate(8); buffer.putLong(x); return buffer.array(); }
From source file:com.linkedin.databus.core.DbusEventV2.java
public static void setKey(ByteBuffer buf, DbusEventKey key) { switch (key.getKeyType()) { case STRING://w w w . j a v a 2s . c o m byte[] keyBytes = key.getStringKeyInBytes(); buf.putInt(keyBytes.length).put(keyBytes); break; case LONG: buf.putLong(key.getLongKey()); break; case SCHEMA: key.getSchemaKey().encode(buf); break; default: throw new UnsupportedOperationException("Unimplemented key type:" + key.getKeyType()); } }
From source file:org.apache.cassandra.db.marshal.TypeCompareTest.java
License:asdf
@Test public void testTimeUUID() { // two different UUIDs w/ the same timestamp UUID uuid1 = UUID.fromString("1077e700-c7f2-11de-86d5-f5bcc793a028"); byte[] bytes1 = new byte[16]; ByteBuffer bb1 = ByteBuffer.wrap(bytes1); bb1.putLong(uuid1.getMostSignificantBits()); bb1.putLong(uuid1.getLeastSignificantBits()); UUID uuid2 = UUID.fromString("1077e700-c7f2-11de-982e-6fad363d5f29"); byte[] bytes2 = new byte[16]; ByteBuffer bb2 = ByteBuffer.wrap(bytes2); bb2.putLong(uuid2.getMostSignificantBits()); bb2.putLong(uuid2.getLeastSignificantBits()); assert new TimeUUIDType().compare(bytes1, bytes2) != 0; }
From source file:edu.tsinghua.lumaqq.qq.packets.out._05.RequestAgentPacket.java
@Override protected void putBody(ByteBuffer buf) { buf.putLong(0x0100000000000000L); buf.putInt(0);/* w w w. j a va2 s. c o m*/ buf.putChar((char) user.getFileAgentToken().length); buf.put(user.getFileAgentToken()); buf.put((byte) 0x04); buf.put((byte) 0x4C); buf.putInt(clusterId); buf.putInt(imageLength); buf.put(md5); buf.put(md5(fileName.getBytes())); buf.putChar((char) 0); }
From source file:org.gtri.totp.java
/** getCode * Calculates the code for the provided time and shared secret. *///w w w . j a v a2 s.co m public int getCode(String sharedSecret, long time) throws NoSuchAlgorithmException, InvalidKeyException { byte[] secret = new Base32().decode(sharedSecret); SecretKeySpec signKey = new SecretKeySpec(secret, "HmacSHA1"); ByteBuffer buffer = ByteBuffer.allocate(8); buffer.putLong(time); byte[] timeBytes = buffer.array(); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(signKey); byte[] hash = mac.doFinal(timeBytes); int offset = hash[19] & 0xf; long truncatedHash = hash[offset] & 0x7f; for (int i = 1; i < 4; i++) { truncatedHash <<= 8; truncatedHash |= hash[offset + i] & 0xff; } return (int) (truncatedHash %= 1000000); }
From source file:com.delphix.session.service.ServiceUUID.java
@Override public byte[] getBytes() { ByteBuffer buffer = ByteBuffer.wrap(new byte[16]); buffer.putLong(uuid.getMostSignificantBits()); buffer.putLong(uuid.getLeastSignificantBits()); return buffer.array(); }
From source file:gobblin.writer.SimpleDataWriter.java
/** * Write a source record to the staging file * * @param record data record to write/*from w w w . ja va 2 s . c o m*/ * @throws java.io.IOException if there is anything wrong writing the record */ @Override public void write(byte[] record) throws IOException { Preconditions.checkNotNull(record); byte[] toWrite = record; if (this.recordDelimiter.isPresent()) { toWrite = Arrays.copyOf(record, record.length + 1); toWrite[toWrite.length - 1] = this.recordDelimiter.get(); } if (this.prependSize) { long recordSize = toWrite.length; ByteBuffer buf = ByteBuffer.allocate(Longs.BYTES); buf.putLong(recordSize); toWrite = ArrayUtils.addAll(buf.array(), toWrite); } this.stagingFileOutputStream.write(toWrite); this.bytesWritten += toWrite.length; this.recordsWritten++; }
From source file:org.apache.hadoop.hdfs.hoss.db.HotStore.java
/** * //from w ww. ja v a 2s . c om * @param objId * @param createTime * @param lastTime * @param size object size(unit:MB) * @return */ public boolean put(long objId, long createTime, long lastTime, long size) { final WriteBuffer wbuf = fbs.set((int) objId); final ByteBuffer buf = wbuf.buf(); // create time buf.putLong(createTime); // last access time buf.putLong(lastTime); long sizeMB = size < 0 ? -1 : convertMB(size); // object size(unit:MB) buf.putLong(sizeMB); buf.flip(); boolean ret = wbuf.save(); return ret; }
From source file:com.github.sebhoss.identifier.service.SuppliedIdentifiers.java
private String convertUuidToBase64(final UUID uuid) { final ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return removePadding(encoder.encodeToString(bb.array())); }