List of usage examples for com.google.common.primitives Longs toByteArray
public static byte[] toByteArray(long value)
From source file:io.warp10.crypto.CryptoUtils.java
public static byte[] addMAC(byte[] key, byte[] data) { long hash = SipHashInline.hash24_palindromic(key, data); byte[] authenticated = Arrays.copyOf(data, data.length + 8); System.arraycopy(Longs.toByteArray(hash), 0, authenticated, data.length, 8); return authenticated; }
From source file:io.druid.segment.data.DeltaLongEncodingWriter.java
public void putMeta(OutputStream metaOut, CompressedObjectStrategy.CompressionStrategy strategy) throws IOException { metaOut.write(CompressionFactory.setEncodingFlag(strategy.getId())); metaOut.write(CompressionFactory.LongEncodingFormat.DELTA.getId()); metaOut.write(CompressionFactory.DELTA_ENCODING_VERSION); metaOut.write(Longs.toByteArray(base)); metaOut.write(Ints.toByteArray(bitsPerValue)); }
From source file:org.darkware.objportal.SimplePortalProvider.java
@Override public PortalContextToken requestNewContext() { return new SimpleContextToken(Base64.getEncoder() .encodeToString(Longs.toByteArray(SimplePortalProvider.nextId.getAndIncrement()))); }
From source file:com.heliosapm.streams.serialization.TimeValuePairSerde.java
/** * {@inheritDoc}/*from w w w. j a va2s .co m*/ * @see org.apache.kafka.common.serialization.Serializer#serialize(java.lang.String, java.lang.Object) */ @Override public byte[] serialize(final String topic, final long[] data) { return Bytes.concat(Longs.toByteArray(data[0]), Longs.toByteArray(data[1])); }
From source file:com.yandex.yoctodb.util.mutable.impl.IntIndexToIndexMultiMap.java
@Override public void writeTo(@NotNull final OutputStream os) throws IOException { // Type//from w ww . j a v a 2 s . com os.write(Ints.toByteArray(V1DatabaseFormat.MultiMapType.LIST_BASED.getCode())); // Keys count os.write(Ints.toByteArray(map.size())); // Offsets long offset = 0L; for (Collection<Integer> value : map) { os.write(Longs.toByteArray(offset)); offset += 4L + 4L * value.size(); } // Sets for (Collection<Integer> value : map) { os.write(Ints.toByteArray(value.size())); for (Integer v : value) { assert v >= 0; os.write(Ints.toByteArray(v)); } } }
From source file:com.yandex.yoctodb.util.mutable.impl.BitSetIndexToIndexMultiMap.java
@Override public void writeTo(@NotNull final OutputStream os) throws IOException { // Type//w w w . j a v a 2 s.c om os.write(Ints.toByteArray(V1DatabaseFormat.MultiMapType.LONG_ARRAY_BIT_SET_BASED.getCode())); // Keys count os.write(Ints.toByteArray(map.size())); // Count longs in bit-set os.write(Ints.toByteArray(LongArrayBitSet.arraySize(documentsCount))); // Sets final ArrayBitSet docs = LongArrayBitSet.zero(documentsCount); for (Collection<Integer> ids : map) { docs.clear(); for (int docId : ids) { assert 0 <= docId && docId < documentsCount; docs.set(docId); } for (long currentWord : docs.toArray()) { os.write(Longs.toByteArray(currentWord)); } } }
From source file:com.stratio.cassandra.lucene.schema.mapping.UUIDMapper.java
/** * Returns the {@link String} representation of the specified {@link UUID}. The returned value has the same * collation as {@link UUIDType}.//from w ww . j ava2 s. c o m * * @param uuid The {@link UUID} to be serialized. * @return The {@link String} representation of the specified {@link UUID}. */ public static String serialize(UUID uuid) { StringBuilder sb = new StringBuilder(); // Get UUID type version ByteBuffer bb = UUIDType.instance.decompose(uuid); int version = (bb.get(bb.position() + 6) >> 4) & 0x0f; // Add version at the beginning sb.append(ByteBufferUtils.toHex((byte) version)); // If it's a time based UUID, add the UNIX timestamp if (version == 1) { long timestamp = uuid.timestamp(); String timestampHex = ByteBufferUtils.toHex(Longs.toByteArray(timestamp)); sb.append(timestampHex); } // Add the UUID itself sb.append(ByteBufferUtils.toHex(bb)); return sb.toString(); }
From source file:nars.util.data.Util.java
public static String UUIDbase64() { long low = UUID.randomUUID().getLeastSignificantBits(); long high = UUID.randomUUID().getMostSignificantBits(); return new String( Base64.getEncoder().encode(Bytes.concat(Longs.toByteArray(low), Longs.toByteArray(high)))); }
From source file:io.druid.segment.data.IntermediateLongSupplierSerializer.java
public void add(long value) throws IOException { tempOut.write(Longs.toByteArray(value)); ++numInserted;/* w w w . ja va 2 s. co m*/ if (uniqueValues.size() <= CompressionFactory.MAX_TABLE_SIZE && !uniqueValues.containsKey(value)) { uniqueValues.put(value, uniqueValues.size()); } if (value > maxVal) { maxVal = value; } if (value < minVal) { minVal = value; } }
From source file:cn.codepub.redis.directory.io.JedisClusterStream.java
@Override public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) { jedisCluster.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength)); Long blockSize = getBlockSize(fileLength); for (int i = 0; i < blockSize; i++) { jedisCluster.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i))); }/*from w w w . j a v a2 s . c o m*/ values.clear(); }