public static long toLong(byte[] bytes) { return Longs.fromByteArray(bytes); }
@Override public Long deserialize(byte[] bytes) { return Longs.fromByteArray(bytes); }
@Override public Double deserialize(byte[] bytes) { return Double.longBitsToDouble(Longs.fromByteArray(bytes)); }
long readLong(InputStream in) throws IOException { byte[] longBytes = new byte[Long.BYTES]; ByteStreams.readFully(in, longBytes); return Longs.fromByteArray(longBytes); }
public void testFromByteArray() { assertEquals( 0x1213141516171819L, Longs.fromByteArray(new byte[] {0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x33})); assertEquals( 0xFFEEDDCCBBAA9988L, Longs.fromByteArray( new byte[] { (byte) 0xFF, (byte) 0xEE, (byte) 0xDD, (byte) 0xCC, (byte) 0xBB, (byte) 0xAA, (byte) 0x99, (byte) 0x88 })); }
@Override public Optional<Long> getChildId(Long inodeId, String name) { byte[] id; try { id = mDb.get(mEdgesColumn, RocksUtils.toByteArray(inodeId, name)); } catch (RocksDBException e) { throw new RuntimeException(e); } if (id == null) { return Optional.empty(); } return Optional.of(Longs.fromByteArray(id)); }
public void testFromByteArrayFails() { try { Longs.fromByteArray(new byte[Longs.BYTES - 1]); fail(); } catch (IllegalArgumentException expected) { } }
public void testByteArrayRoundTrips() { Random r = new Random(5); byte[] b = new byte[Longs.BYTES]; for (int i = 0; i < 1000; i++) { long num = r.nextLong(); assertEquals(num, Longs.fromByteArray(Longs.toByteArray(num))); r.nextBytes(b); long value = Longs.fromByteArray(b); assertTrue("" + value, Arrays.equals(b, Longs.toByteArray(value))); } }
@Override public Set<MutableInode<?>> allInodes() { Set<MutableInode<?>> inodes = new HashSet<>(); RocksIterator iter = mDb.newIterator(mInodesColumn); iter.seekToFirst(); while (iter.isValid()) { inodes.add(getMutable(Longs.fromByteArray(iter.key())).get()); iter.next(); } return inodes; }
@Override public Block next() { try { return new Block(Longs.fromByteArray(iter.key()), BlockMeta.parseFrom(iter.value())); } catch (Exception e) { throw new RuntimeException(e); } finally { iter.next(); } } };
throw new RuntimeException(e); sb.append("Inode " + Longs.fromByteArray(inodeIter.key()) + ": " + inode + "\n"); inodeIter.next(); System.arraycopy(key, 0, id, 0, Longs.BYTES); System.arraycopy(key, Longs.BYTES, name, 0, key.length - Longs.BYTES); sb.append(String.format("<%s,%s>->%s%n", Longs.fromByteArray(id), new String(name), Longs.fromByteArray(edgeIter.value()))); edgeIter.next();
@Override public Set<EdgeEntry> allEdges() { Set<EdgeEntry> edges = new HashSet<>(); RocksIterator iter = mDb.newIterator(mEdgesColumn); iter.seekToFirst(); while (iter.isValid()) { long parentId = RocksUtils.readLong(iter.key(), 0); String childName = new String(iter.key(), Longs.BYTES, iter.key().length - Longs.BYTES); long childId = Longs.fromByteArray(iter.value()); edges.add(new EdgeEntry(parentId, childName, childId)); iter.next(); } return edges; }
/** * Converts a byte array to a long value. Reverses {@link #toBytes(long)} */ public static long toLong(byte[] bytes) { return Longs.fromByteArray(bytes); }
data.length); value = Longs.fromByteArray(data); } else { value = defaultVal;
@Override @Nullable public Blob getBlob(String container, String name, GetOptions options) { Blob blob = super.getBlob(container, name, options); if (blob == null) { return null; } byte[] array; try (InputStream is = blob.getPayload().openStream()) { array = ByteStreams.toByteArray(is); } catch (IOException ioe) { throw new RuntimeException(ioe); } long length = Longs.fromByteArray(array); ByteSourcePayload payload = new ByteSourcePayload( new NullByteSource().slice(0, length)); payload.setContentMetadata(blob.getPayload().getContentMetadata()); payload.getContentMetadata().setContentLength(length); payload.getContentMetadata().setContentMD5((HashCode) null); blob.setPayload(payload); return blob; }
private long spanIdToLong(final @Nullable SpanId spanId) { if (spanId == null) { return 0L; } // Attempt to minimise allocations, since SpanId#getBytes currently creates a defensive copy: spanId.copyBytesTo(spanIdBuffer, 0); return Longs.fromByteArray(spanIdBuffer); }
public static byte[] fetchChunk(byte[] hash, byte[] hashloc, boolean direct) throws IOException, DataArchivedException { byte[] data = null; long pos = -1; if (direct) { pos = Longs.fromByteArray(hashloc); } data = HCServiceProxy.hcService.fetchChunk(hash, pos).getData(); return data; }
public void increment(String path, long count) { try { ensureCounterExists(path); Long value = Longs.fromByteArray(curatorClient.getData().forPath(path)); Long newValue = value + count; curatorClient.setData().forPath(path, Longs.toByteArray(newValue)); } catch (Exception e) { throw new ZookeeperCounterException(path, e); } }
public void testFromByteArrayFails() { try { Longs.fromByteArray(new byte[Longs.BYTES - 1]); fail(); } catch (IllegalArgumentException expected) { } }
private long getMaxId(Database db) { final DatabaseEntry key = new DatabaseEntry(); final DatabaseEntry value = new DatabaseEntry(); try (Cursor cursor = db.openCursor(null, CursorConfig.DEFAULT)) { final OperationStatus status = cursor.getLast(key, value, null); if (status == OperationStatus.SUCCESS) return Longs.fromByteArray(key.getData()); else return 0; } }