/** * Reads a double value at the given buffer's offset. * @param buffer * @param offset offset where double is * @return double value at offset */ public static double toDouble(ByteBuffer buffer, int offset) { return Double.longBitsToDouble(toLong(buffer, offset)); }
@Override public int compareTo(ByteBuffer value, int offset, int length) { long that = ByteBufferUtils.toLong(value, offset); return Long.compare(longValue, that); }
long getTimestamp(int keyLength) { int offset = getTimestampOffset(keyLength); return ByteBufferUtils.toLong(this.buf, offset); }
@Override public long getTimestamp() { return ByteBufferUtils.toLong(this.buf, getTimestampOffset()); }
private long getLong(int index, int itemIndex) { ByteBuffer item = items[itemIndex]; int offsetInItem = index - this.itemBeginPos[itemIndex]; int remainingLen = item.limit() - offsetInItem; if (remainingLen >= Bytes.SIZEOF_LONG) { return ByteBufferUtils.toLong(item, offsetInItem); } if (items.length - 1 == itemIndex) { // means cur item is the last one and we wont be able to read a long. Throw exception throw new BufferUnderflowException(); } long l = 0; for (int i = 0; i < Bytes.SIZEOF_LONG; i++) { l <<= 8; l ^= get(index + i) & 0xFF; } return l; }
/** * Converts the value bytes of the given cell into a long value * @param cell * @return value as long */ public static long getValueAsLong(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toLong(((ByteBufferExtendedCell) cell).getValueByteBuffer(), ((ByteBufferExtendedCell) cell).getValuePosition()); } return Bytes.toLong(cell.getValueArray(), cell.getValueOffset()); }
@Test public void testToPrimitiveTypes() { ByteBuffer buffer = ByteBuffer.allocate(15); long l = 988L; int i = 135; short s = 7; buffer.putLong(l); buffer.putShort(s); buffer.putInt(i); assertEquals(l, ByteBufferUtils.toLong(buffer, 0)); assertEquals(s, ByteBufferUtils.toShort(buffer, 8)); assertEquals(i, ByteBufferUtils.toInt(buffer, 10)); }
/** * Converts the value bytes of the given tag into a long value * @param tag The Tag * @return value as long */ public static long getValueAsLong(Tag tag) { if (tag.hasArray()) { return Bytes.toLong(tag.getValueArray(), tag.getValueOffset(), tag.getValueLength()); } return ByteBufferUtils.toLong(tag.getValueByteBuffer(), tag.getValueOffset()); }
long cellSeqID = ByteBufferUtils.toLong(block, offsetInBytes + 3*Bytes.SIZEOF_INT);
@Override public int compareTo(ByteBuffer value, int offset, int length) { long that = ByteBufferUtils.toLong(value, offset); return Long.compare(longValue, that); }
@Test public void testSubBuffer() { ByteBuffer bb1 = ByteBuffer.allocateDirect(10); ByteBuffer bb2 = ByteBuffer.allocateDirect(10); MultiByteBuff multi = new MultiByteBuff(bb1, bb2); long l1 = 1234L, l2 = 100L; multi.putLong(l1); multi.putLong(l2); multi.rewind(); ByteBuffer sub = multi.asSubByteBuffer(Bytes.SIZEOF_LONG); assertEquals(bb1, sub); assertEquals(l1, ByteBufferUtils.toLong(sub, sub.position())); multi.skip(Bytes.SIZEOF_LONG); sub = multi.asSubByteBuffer(Bytes.SIZEOF_LONG); assertNotEquals(bb1, sub); assertNotEquals(bb2, sub); assertEquals(l2, ByteBufferUtils.toLong(sub, sub.position())); multi.rewind(); ObjectIntPair<ByteBuffer> p = new ObjectIntPair<>(); multi.asSubByteBuffer(8, Bytes.SIZEOF_LONG, p); assertNotEquals(bb1, p.getFirst()); assertNotEquals(bb2, p.getFirst()); assertEquals(0, p.getSecond()); assertEquals(l2, ByteBufferUtils.toLong(sub, p.getSecond())); }
/** * Reads a double value at the given buffer's offset. * @param buffer * @param offset offset where double is * @return double value at offset */ public static double toDouble(ByteBuffer buffer, int offset) { return Double.longBitsToDouble(toLong(buffer, offset)); }
/** * Reads a double value at the given buffer's offset. * @param buffer * @param offset offset where double is * @return double value at offset */ public static double toDouble(ByteBuffer buffer, int offset) { return Double.longBitsToDouble(toLong(buffer, offset)); }
@Override public int compareTo(ByteBuffer value, int offset, int length) { long that = ByteBufferUtils.toLong(value, offset); return Long.compare(longValue, that); }
@Override public long getTimestamp() { return ByteBufferUtils.toLong(this.buf, getTimestampOffset()); }
@Override public long getTimestamp() { int offset = getTimestampOffset(getKeyLen()); return ByteBufferUtils.toLong(this.buf, offset); }
/** * Converts the value bytes of the given cell into a long value * @param cell * @return value as long */ public static long getValueAsLong(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toLong(((ByteBufferExtendedCell) cell).getValueByteBuffer(), ((ByteBufferExtendedCell) cell).getValuePosition()); } return Bytes.toLong(cell.getValueArray(), cell.getValueOffset()); }
/** * Converts the value bytes of the given cell into a long value * @param cell * @return value as long */ public static long getValueAsLong(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toLong(((ByteBufferExtendedCell) cell).getValueByteBuffer(), ((ByteBufferExtendedCell) cell).getValuePosition()); } return Bytes.toLong(cell.getValueArray(), cell.getValueOffset()); }
/** * Converts the value bytes of the given tag into a long value * @param tag The Tag * @return value as long */ public static long getValueAsLong(Tag tag) { if (tag.hasArray()) { return Bytes.toLong(tag.getValueArray(), tag.getValueOffset(), tag.getValueLength()); } return ByteBufferUtils.toLong(tag.getValueByteBuffer(), tag.getValueOffset()); }
/** * Converts the value bytes of the given tag into a long value * @param tag The Tag * @return value as long */ public static long getValueAsLong(Tag tag) { if (tag.hasArray()) { return Bytes.toLong(tag.getValueArray(), tag.getValueOffset(), tag.getValueLength()); } return ByteBufferUtils.toLong(tag.getValueByteBuffer(), tag.getValueOffset()); }