List of usage examples for com.google.common.primitives Longs toByteArray
public static byte[] toByteArray(long value)
From source file:se.sics.caracaldb.utils.TimestampIdFactory.java
private TimestampIdFactory(Address adr) { this.address = new byte[6]; System.arraycopy(adr.getIp().getAddress(), 0, this.address, 0, 4); System.arraycopy(Ints.toByteArray(adr.getPort()), 2, this.address, 4, 2); byte[] tsB = new byte[bytes]; Arrays.fill(tsB, (byte) 0); System.arraycopy(Longs.toByteArray(System.currentTimeMillis()), 0, tsB, 0, 8); this.ts = new FixedInteger(tsB); this.counter = com.larskroll.math.mutable.FixedInteger.zero(bytes); this.lastId = FixedInteger.zero(bytes); }
From source file:org.apache.hadoop.mapred.nativetask.testutil.BytesFactory.java
public static <VTYPE> byte[] toBytes(VTYPE obj) { final String className = obj.getClass().getName(); if (className.equals(IntWritable.class.getName())) { return Ints.toByteArray(((IntWritable) obj).get()); } else if (className.equals(FloatWritable.class.getName())) { return BytesUtil.toBytes(((FloatWritable) obj).get()); } else if (className.equals(DoubleWritable.class.getName())) { return BytesUtil.toBytes(((DoubleWritable) obj).get()); } else if (className.equals(LongWritable.class.getName())) { return Longs.toByteArray(((LongWritable) obj).get()); } else if (className.equals(VIntWritable.class.getName())) { return Ints.toByteArray(((VIntWritable) obj).get()); } else if (className.equals(VLongWritable.class.getName())) { return Longs.toByteArray(((VLongWritable) obj).get()); } else if (className.equals(BooleanWritable.class.getName())) { return BytesUtil.toBytes(((BooleanWritable) obj).get()); } else if (className.equals(Text.class.getName())) { return ((Text) obj).copyBytes(); } else if (className.equals(ByteWritable.class.getName())) { return Ints.toByteArray((int) ((ByteWritable) obj).get()); } else if (className.equals(BytesWritable.class.getName())) { // TODO: copyBytes instead? return ((BytesWritable) obj).getBytes(); } else {/*www. j av a 2 s . c om*/ return new byte[0]; } }
From source file:cryptwallet.CryptPasswordController.java
public static void setTargetTime(Duration targetTime) { ByteString bytes = ByteString.copyFrom(Longs.toByteArray(targetTime.toMillis())); Main.bitcoin.wallet().setTag(TAG, bytes); }
From source file:io.druid.query.filter.IntervalDimFilter.java
@Override public byte[] getCacheKey() { byte[] dimensionBytes = StringUtils.toUtf8(dimension); byte[] extractionFnBytes = extractionFn == null ? new byte[0] : extractionFn.getCacheKey(); int intervalsBytesSize = intervalLongs.size() * Longs.BYTES * 2 + intervalLongs.size(); ByteBuffer filterCacheKey = ByteBuffer .allocate(3 + dimensionBytes.length + intervalsBytesSize + extractionFnBytes.length) .put(DimFilterUtils.INTERVAL_CACHE_ID).put(dimensionBytes).put(DimFilterUtils.STRING_SEPARATOR) .put(extractionFnBytes).put(DimFilterUtils.STRING_SEPARATOR); for (Pair<Long, Long> interval : intervalLongs) { filterCacheKey.put(Longs.toByteArray(interval.lhs)).put(Longs.toByteArray(interval.rhs)) .put((byte) 0xFF); }/*w w w.j a v a 2 s .c o m*/ return filterCacheKey.array(); }
From source file:com.yandex.yoctodb.v1.mutable.segment.V1FilterableIndex.java
@NotNull @Override//ww w. ja va2 s.c o m public OutputStreamWritable buildWritable() { checkNotFrozen(); freeze(); // Building the index final IndexToIndexMultiMap valueToDocumentsIndex = IndexToIndexMultiMapFactory .buildIndexToIndexMultiMap(valueToDocuments.asMap().values(), databaseDocumentsCount); final OutputStreamWritable values; if (fixedLength) { values = new FixedLengthByteArraySortedSet(valueToDocuments.keySet()); } else { values = new VariableLengthByteArraySortedSet(valueToDocuments.keySet()); } // Free memory valueToDocuments = null; return new OutputStreamWritable() { @Override public long getSizeInBytes() { return 4L + // Field name fieldName.length + 8 + // Values values.getSizeInBytes() + 8 + // Value to documents valueToDocumentsIndex.getSizeInBytes(); } @Override public void writeTo(@NotNull final OutputStream os) throws IOException { os.write(Longs.toByteArray(getSizeInBytes())); // Payload segment type os.write(Ints.toByteArray(fixedLength ? V1DatabaseFormat.SegmentType.FIXED_LENGTH_FILTER.getCode() : V1DatabaseFormat.SegmentType.VARIABLE_LENGTH_FILTER.getCode())); // Field name os.write(Ints.toByteArray(fieldName.length)); os.write(fieldName); // Values os.write(Longs.toByteArray(values.getSizeInBytes())); values.writeTo(os); // Documents os.write(Longs.toByteArray(valueToDocumentsIndex.getSizeInBytes())); valueToDocumentsIndex.writeTo(os); } }; }
From source file:org.apache.druid.query.filter.IntervalDimFilter.java
@Override public byte[] getCacheKey() { byte[] dimensionBytes = StringUtils.toUtf8(dimension); byte[] extractionFnBytes = extractionFn == null ? new byte[0] : extractionFn.getCacheKey(); int intervalsBytesSize = intervalLongs.size() * Long.BYTES * 2 + intervalLongs.size(); ByteBuffer filterCacheKey = ByteBuffer .allocate(3 + dimensionBytes.length + intervalsBytesSize + extractionFnBytes.length) .put(DimFilterUtils.INTERVAL_CACHE_ID).put(dimensionBytes).put(DimFilterUtils.STRING_SEPARATOR) .put(extractionFnBytes).put(DimFilterUtils.STRING_SEPARATOR); for (Pair<Long, Long> interval : intervalLongs) { filterCacheKey.put(Longs.toByteArray(interval.lhs)).put(Longs.toByteArray(interval.rhs)) .put((byte) 0xFF); }//from w w w .j a va 2s . com return filterCacheKey.array(); }
From source file:Model.PeerComms.java
public void leavingP2PNetwork() { byte[] buffer = new byte[256]; long msg = 999999; buffer = Longs.toByteArray(msg); DatagramPacket dPacket = new DatagramPacket(buffer, buffer.length, group, DEST_PORT); try {//from w w w.j a v a2 s .c om dSocket.send(dPacket); localPeerNode.setVectorTimeStamp(); System.out.println("send leaving notification to p2p network"); System.out.println("packet sent = " + Longs.fromByteArray(dPacket.getData())); } catch (IOException ex) { Logger.getLogger(PeerComms.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.onosproject.ipfix.DataRecordRfwdMac.java
@Override public byte[] getBytes() throws HeaderException { try {//w w w . j a va 2 s. c om byte[] data = new byte[LENGTH]; System.arraycopy(exporterIPv4Address.toOctets(), 0, data, 0, 4); System.arraycopy(exporterIPv6Address.toOctets(), 0, data, 4, 16); System.arraycopy(Longs.toByteArray(flowStartMilliseconds), 0, data, 20, 8); System.arraycopy(Longs.toByteArray(flowEndMilliseconds), 0, data, 28, 8); System.arraycopy(Longs.toByteArray(octetDeltaCount), 0, data, 36, 8); System.arraycopy(Longs.toByteArray(packetDeltaCount), 0, data, 44, 8); System.arraycopy(Ints.toByteArray(ingressInterface), 0, data, 52, 4); System.arraycopy(Ints.toByteArray(egressInterface), 0, data, 56, 4); System.arraycopy(sourceMacAddress.toBytes(), 0, data, 60, 6); System.arraycopy(destinationMacAddress.toBytes(), 0, data, 66, 6); System.arraycopy(Shorts.toByteArray(ethernetType), 0, data, 72, 2); System.arraycopy(Shorts.toByteArray(vlanId), 0, data, 74, 2); return data; } catch (Exception e) { throw new HeaderException("Error while generating the bytes: " + e.getMessage()); } }
From source file:jnetention.NObject.java
public static String UUID() { long a = (long) (Math.random() * Long.MAX_VALUE); long b = (long) (Math.random() * Long.MAX_VALUE); return Base64.getEncoder().encodeToString(Longs.toByteArray(a)).substring(0, 11) + Base64.getEncoder().encodeToString(Longs.toByteArray(b)).substring(0, 11); }
From source file:se.sics.caracaldb.utils.TimestampIdFactory.java
private void checkUpdateTs() { byte[] tsB = new byte[bytes]; Arrays.fill(tsB, (byte) 0); System.arraycopy(Longs.toByteArray(System.currentTimeMillis()), 0, tsB, 0, 8); FixedInteger nextTs = new FixedInteger(tsB); if (nextTs.compareTo(lastId) > 0) { ts = nextTs;//from w ww.j a v a 2 s. c o m counter = com.larskroll.math.mutable.FixedInteger.zero(bytes); } }