public static byte[] toBytes(long value) { return Longs.toByteArray(value); }
@Override public byte[] serialize(Long value) { return Longs.toByteArray(value); }
private void writeLong(OutputStream out, long longValue) throws IOException { out.write(Longs.toByteArray(longValue)); }
/** * Writes a {@code long} as specified by {@link DataOutputStream#writeLong(long)}, except using * little-endian byte order. * * @throws IOException if an I/O error occurs */ @Override public void writeLong(long v) throws IOException { byte[] bytes = Longs.toByteArray(Long.reverseBytes(v)); write(bytes, 0, bytes.length); }
@Override public byte[] serialize(Double value) { return Longs.toByteArray(Double.doubleToRawLongBits(value)); }
/** * Writes a {@code long} as specified by {@link DataOutputStream#writeLong(long)}, except using * little-endian byte order. * * @throws IOException if an I/O error occurs */ @Override public void writeLong(long v) throws IOException { byte[] bytes = Longs.toByteArray(Long.reverseBytes(v)); write(bytes, 0, bytes.length); }
@Override public void removeInode(Long key) { try { mBatch.delete(mInodesColumn, Longs.toByteArray(key)); } catch (RocksDBException e) { throw new RuntimeException(e); } }
@Override public void removeBlock(long id) { try { mDb.delete(mBlockMetaColumn, Longs.toByteArray(id)); } catch (RocksDBException e) { throw new RuntimeException(e); } }
@Override public void remove(Long inodeId) { try { byte[] id = Longs.toByteArray(inodeId); mDb.delete(mInodesColumn, mDisableWAL, id); } catch (RocksDBException e) { throw new RuntimeException(e); } }
/** * Writes a {@code long} as specified by {@link DataOutputStream#writeLong(long)}, except using * little-endian byte order. * * @throws IOException if an I/O error occurs */ @Override public void writeLong(long v) throws IOException { byte[] bytes = Longs.toByteArray(Long.reverseBytes(v)); write(bytes, 0, bytes.length); }
@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); } return filterCacheKey.array(); }
public void testToByteArray() { assertByteArrayEquals( new byte[] {0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19}, Longs.toByteArray(0x1213141516171819L)); assertByteArrayEquals( new byte[] { (byte) 0xFF, (byte) 0xEE, (byte) 0xDD, (byte) 0xCC, (byte) 0xBB, (byte) 0xAA, (byte) 0x99, (byte) 0x88 }, Longs.toByteArray(0xFFEEDDCCBBAA9988L)); }
@Override public void addChild(long parentId, String childName, Long childId) { try { mDb.put(mEdgesColumn, mDisableWAL, RocksUtils.toByteArray(parentId, childName), Longs.toByteArray(childId)); } catch (RocksDBException e) { throw new RuntimeException(e); } }
@Override public void addChild(Long parentId, String childName, Long childId) { try { mBatch.put(mEdgesColumn, RocksUtils.toByteArray(parentId, childName), Longs.toByteArray(childId)); } catch (RocksDBException e) { throw new RuntimeException(e); } }
@Override public void putBlock(long id, BlockMeta meta) { try { // Overwrites the key if it already exists. mDb.put(mBlockMetaColumn, Longs.toByteArray(id), meta.toByteArray()); } catch (RocksDBException e) { throw new RuntimeException(e); } }
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 void writeInode(MutableInode<?> inode) { try { mDb.put(mInodesColumn, mDisableWAL, Longs.toByteArray(inode.getId()), inode.toProto().toByteArray()); } catch (RocksDBException e) { throw new RuntimeException(e); } }
@Override public void writeInode(MutableInode<?> inode) { try { mBatch.put(mInodesColumn, Longs.toByteArray(inode.getId()), inode.toProto().toByteArray()); } catch (RocksDBException e) { throw new RuntimeException(e); } }
@Override public boolean hasChildren(InodeDirectoryView inode) { RocksIterator iter = mDb.newIterator(mEdgesColumn, mReadPrefixSameAsStart); iter.seek(Longs.toByteArray(inode.getId())); return iter.isValid(); }
@Override public List<BlockLocation> getLocations(long id) { RocksIterator iter = mDb.newIterator(mBlockLocationsColumn, new ReadOptions().setPrefixSameAsStart(true)); iter.seek(Longs.toByteArray(id)); List<BlockLocation> locations = new ArrayList<>(); for (; iter.isValid(); iter.next()) { try { locations.add(BlockLocation.parseFrom(iter.value())); } catch (Exception e) { throw new RuntimeException(e); } } return locations; }