@Override public int getChunkId() { // The chunkId is embedded at the 0th offset of the bytebuffer return ByteBufferUtils.toInt(buf, 0); }
@Override public int getValueLength() { return ByteBufferUtils.toInt(this.buf, this.offset + Bytes.SIZEOF_INT); }
@Override public int getChunkId() { // The chunkId is embedded at the 0th offset of the bytebuffer return ByteBufferUtils.toInt(buf, 0); } }
int getKeyLength() { return ByteBufferUtils.toInt(this.buf, this.offset); }
/** * Reads a BigDecimal value at the given buffer's offset. * @param buffer * @param offset * @return BigDecimal value at offset */ public static BigDecimal toBigDecimal(ByteBuffer buffer, int offset, int length) { if (buffer == null || length < Bytes.SIZEOF_INT + 1 || (offset + length > buffer.limit())) { return null; } int scale = toInt(buffer, offset); byte[] tcBytes = new byte[length - Bytes.SIZEOF_INT]; copyFromBufferToArray(tcBytes, buffer, offset + Bytes.SIZEOF_INT, 0, length - Bytes.SIZEOF_INT); return new BigDecimal(new BigInteger(tcBytes), scale); }
private int getInt(int index, int itemIndex) { ByteBuffer item = items[itemIndex]; int offsetInItem = index - this.itemBeginPos[itemIndex]; int remainingLen = item.limit() - offsetInItem; if (remainingLen >= Bytes.SIZEOF_INT) { return ByteBufferUtils.toInt(item, offsetInItem); } if (items.length - 1 == itemIndex) { // means cur item is the last one and we wont be able to read a int. Throw exception throw new BufferUnderflowException(); } int l = 0; for (int i = 0; i < Bytes.SIZEOF_INT; i++) { l <<= 8; l ^= get(index + i) & 0xFF; } return l; }
int chunkId = ByteBufferUtils.toInt(block, offsetInBytes); Chunk chunk = ChunkCreator.getInstance().getChunk(chunkId); if (chunk == null) { int offsetOfCell = ByteBufferUtils.toInt(block, offsetInBytes + Bytes.SIZEOF_INT); int lengthOfCell = ByteBufferUtils.toInt(block, offsetInBytes + 2*Bytes.SIZEOF_INT);
/** * Converts the value bytes of the given cell into a int value * @param cell * @return value as int */ public static int getValueAsInt(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toInt(((ByteBufferExtendedCell) cell).getValueByteBuffer(), ((ByteBufferExtendedCell) cell).getValuePosition()); } return Bytes.toInt(cell.getValueArray(), cell.getValueOffset()); }
/** * Converts the rowkey bytes of the given cell into an int value * @param cell * @return rowkey as int */ public static int getRowAsInt(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toInt(((ByteBufferExtendedCell) cell).getRowByteBuffer(), ((ByteBufferExtendedCell) cell).getRowPosition()); } return Bytes.toInt(cell.getRowArray(), cell.getRowOffset()); }
@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)); }
@Override public int getValueLength() { return ByteBufferUtils.toInt(this.buf, this.offset + Bytes.SIZEOF_INT); }
int getKeyLength() { return ByteBufferUtils.toInt(this.buf, this.offset); }
private int getKeyLen() { return ByteBufferUtils.toInt(this.buf, this.offset); }
@Override public int getValueLength() { return ByteBufferUtils.toInt(this.buf, this.offset + Bytes.SIZEOF_INT); }
/** * Converts the rowkey bytes of the given cell into an int value * @param cell * @return rowkey as int */ public static int getRowAsInt(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toInt(((ByteBufferExtendedCell) cell).getRowByteBuffer(), ((ByteBufferExtendedCell) cell).getRowPosition()); } return Bytes.toInt(cell.getRowArray(), cell.getRowOffset()); }
/** * Converts the value bytes of the given cell into a int value * @param cell * @return value as int */ public static int getValueAsInt(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toInt(((ByteBufferExtendedCell) cell).getValueByteBuffer(), ((ByteBufferExtendedCell) cell).getValuePosition()); } return Bytes.toInt(cell.getValueArray(), cell.getValueOffset()); }
/** * Converts the rowkey bytes of the given cell into an int value * @param cell * @return rowkey as int */ public static int getRowAsInt(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toInt(((ByteBufferExtendedCell) cell).getRowByteBuffer(), ((ByteBufferExtendedCell) cell).getRowPosition()); } return Bytes.toInt(cell.getRowArray(), cell.getRowOffset()); }
/** * Converts the value bytes of the given cell into a int value * @param cell * @return value as int */ public static int getValueAsInt(Cell cell) { if (cell instanceof ByteBufferExtendedCell) { return ByteBufferUtils.toInt(((ByteBufferExtendedCell) cell).getValueByteBuffer(), ((ByteBufferExtendedCell) cell).getValuePosition()); } return Bytes.toInt(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)); }
@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)); }