List of usage examples for com.google.common.primitives Longs toByteArray
public static byte[] toByteArray(long value)
From source file:org.apache.sysml.utils.TensorboardLogger.java
/** * Writes scalar of given value in tensorboard format * // w w w . j a va 2s . c o m * @param logDir log directory of tensorboard * @param tag scalar tag (for example: training_loss, validation_loss, ...) * @param step usually the iteration number * @param value value of the scalar */ public static void writeScalar(String logDir, String tag, long step, float value) { String filePath = logDir + File.separator + "tfevents.event_systemml_scalar"; try { FileOutputStream outputStream = new FileOutputStream(filePath, true); Event event = Event.newBuilder().setWallTime(System.currentTimeMillis() / 1e3).setStep(step) .setSummary(Summary.newBuilder() .addValue(Summary.Value.newBuilder().setTag(tag).setSimpleValue(value)).build()) .build(); byte[] eventString = event.toByteArray(); byte[] header = reverse(Longs.toByteArray((long) eventString.length)); write(outputStream, header); write(outputStream, eventString); outputStream.close(); } catch (IOException e) { throw new RuntimeException("Error writing event in tensorboard directory:" + filePath, e); } }
From source file:com.prealpha.minelib.nbt.DoubleTag.java
@Override public ByteBuffer toBytes() { long longBits = Double.doubleToLongBits(value); return ByteBuffer.wrap(Longs.toByteArray(longBits)); }
From source file:com.github.benmanes.caffeine.cache.simulator.membership.bloom.AddThisBloomFilter.java
@Override public boolean mightContain(long e) { return bloomFilter.isPresent(Longs.toByteArray(e)); }
From source file:io.warp10.continuum.DirectoryUtil.java
private static long computeHash(long k0, long k1, long timestamp, List<String> classSelectors, List<Map<String, String>> labelsSelectors) { ////from ww w . j a va2 s. c om // Create a ByteArrayOutputStream into which the content will be dumped // ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Add timestamp try { baos.write(Longs.toByteArray(timestamp)); if (null != classSelectors) { for (String classSelector : classSelectors) { baos.write(classSelector.getBytes(Charsets.UTF_8)); } } if (null != labelsSelectors) { for (Map<String, String> map : labelsSelectors) { TreeMap<String, String> tm = new TreeMap<String, String>(); tm.putAll(map); for (Entry<String, String> entry : tm.entrySet()) { baos.write(entry.getKey().getBytes(Charsets.UTF_8)); baos.write(entry.getValue().getBytes(Charsets.UTF_8)); } } } } catch (IOException ioe) { return 0L; } // Compute hash byte[] data = baos.toByteArray(); long hash = SipHashInline.hash24(k0, k1, data, 0, data.length); return hash; }
From source file:net.derquinse.bocas.BocasExerciser.java
public static MemoryByteSource data() { byte[] deterministic = Longs.toByteArray(INDEX.incrementAndGet()); byte[] data = RandomSupport.getBytes(RandomSupport.nextInt(1024, 10240)); for (int i = 0; i < deterministic.length; i++) { data[i] = deterministic[i];/*ww w. ja v a 2s .c om*/ } return MemoryByteSource.wrap(data); }
From source file:com.facebook.util.digest.LongDigestFunction.java
@Override public long computeDigest(Long input) { byte[] bytes = Longs.toByteArray(input); return new BigInteger(digest.get().digest(bytes)).longValue(); }
From source file:ws.moor.swissvault.util.Obfuscator.java
public String obfuscateLong(long unobfuscated) { try {//from w w w .j a va 2s . c o m Cipher cipher = Cipher.getInstance("Blowfish/ECB/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, secret); byte[] encrypted = cipher.doFinal(Longs.toByteArray(unobfuscated)); return encoding.encode(encrypted); } catch (Exception e) { throw new RuntimeException(String.valueOf(unobfuscated), e); } }
From source file:com.ebay.pulsar.analytics.metricstore.druid.postaggregator.ConstantPostAggregator.java
@Override public byte[] cacheKey() { // Depending on the Number subclass type if (this.value instanceof Long) { ByteBuffer buffer = ByteBuffer.allocate(1 + 8).put(PostAggregatorCacheHelper.CONSTANT_CACHE_ID) .put(Longs.toByteArray((Long) value)); return buffer.array(); } else if (this.value instanceof Integer) { ByteBuffer buffer = ByteBuffer.allocate(1 + 4).put(PostAggregatorCacheHelper.CONSTANT_CACHE_ID) .put(Ints.toByteArray((Integer) value)); return buffer.array(); } else if (this.value instanceof Short) { ByteBuffer buffer = ByteBuffer.allocate(1 + 2).put(PostAggregatorCacheHelper.CONSTANT_CACHE_ID) .put(Shorts.toByteArray((Short) value)); return buffer.array(); } else if (this.value instanceof Byte) { ByteBuffer buffer = ByteBuffer.allocate(1 + 1).put(PostAggregatorCacheHelper.CONSTANT_CACHE_ID) .put((Byte) value); return buffer.array(); } else if (this.value instanceof Double) { ByteBuffer buffer = ByteBuffer.allocate(1 + 8).put(PostAggregatorCacheHelper.CONSTANT_CACHE_ID) .putDouble((Double) value); return buffer.array(); } else if (this.value instanceof Float) { ByteBuffer buffer = ByteBuffer.allocate(1 + 4).put(PostAggregatorCacheHelper.CONSTANT_CACHE_ID) .putFloat((Float) value); return buffer.array(); } else if (this.value instanceof BigDecimal) { Double bigDouble = this.value.doubleValue(); ByteBuffer buffer = ByteBuffer.allocate(1 + 8).put(PostAggregatorCacheHelper.CONSTANT_CACHE_ID) .putDouble((Double) bigDouble); return buffer.array(); } else if (this.value instanceof BigInteger) { byte[] bigIntBytes = ((BigInteger) this.value).toByteArray(); int len = bigIntBytes.length; ByteBuffer buffer = ByteBuffer.allocate(1 + len).put(PostAggregatorCacheHelper.CONSTANT_CACHE_ID) .put(bigIntBytes);//from w w w . j a v a 2 s. c o m return buffer.array(); } else if (this.value instanceof AtomicInteger) { int intVal = this.value.intValue(); ByteBuffer buffer = ByteBuffer.allocate(1 + 4).put(PostAggregatorCacheHelper.CONSTANT_CACHE_ID) .put(Ints.toByteArray(intVal)); return buffer.array(); } else { long longVal = this.value.longValue(); ByteBuffer buffer = ByteBuffer.allocate(1 + 8).put(PostAggregatorCacheHelper.CONSTANT_CACHE_ID) .put(Longs.toByteArray(longVal)); return buffer.array(); } }
From source file:com.github.benmanes.caffeine.cache.simulator.membership.bloom.AddThisBloomFilter.java
@Override public boolean put(long e) { byte[] bytes = Longs.toByteArray(e); if (bloomFilter.isPresent(bytes)) { return false; }/*from ww w. j ava2s . com*/ bloomFilter.add(bytes); return true; }
From source file:co.cask.tephra.visibility.WriteFence.java
@Override public void startTx(Transaction tx) { this.tx = tx; if (inProgressChanges == null) { inProgressChanges = new TreeSet<>(UnsignedBytes.lexicographicalComparator()); for (long inProgressTx : tx.getInProgress()) { inProgressChanges.add(Bytes.concat(fenceId, Longs.toByteArray(inProgressTx))); }/* w w w . j av a2s . c o m*/ } }