/** * Converts a byte array to an int value * @param bytes byte array * @return the int value */ public static int toInt(byte[] bytes) { return toInt(bytes, 0, SIZEOF_INT); }
/** * Determines the total length of the KeyValue stored in the specified * byte array and offset. Includes all headers. * @param bytes byte array * @param offset offset to start of the KeyValue * @return length of entire KeyValue, in bytes */ private static int getLength(byte [] bytes, int offset) { int klength = ROW_OFFSET + Bytes.toInt(bytes, offset); int vlength = Bytes.toInt(bytes, offset + Bytes.SIZEOF_INT); return klength + vlength; }
/** * Converts a byte array to an int value * @param bytes byte array * @param offset offset into array * @return the int value */ public static int toInt(byte[] bytes, int offset) { return toInt(bytes, offset, SIZEOF_INT); }
/** * Read an {@code int} value from the buffer {@code buff}. */ public int decodeInt(byte[] buff, int offset) { return Bytes.toInt(buff, offset); }
/** * @return Length of key portion. */ public int getKeyLength() { return Bytes.toInt(this.bytes, this.offset); }
/** * Presumes float encoded as IEEE 754 floating-point "single format" * @param bytes array to convert * @param offset offset into array * @return Float made from passed byte array. */ public static float toFloat(byte [] bytes, int offset) { return Float.intBitsToFloat(toInt(bytes, offset, SIZEOF_INT)); }
private static float decodeFloat(byte[] b, int o) { checkForSufficientLength(b, o, Bytes.SIZEOF_INT); int value; value = Bytes.toInt(b, o); value--; value ^= (~value >> Integer.SIZE - 1) | Integer.MIN_VALUE; return Float.intBitsToFloat(value); }
private static int decodeUnsignedInt(byte[] b, int o) { checkForSufficientLength(b, o, Bytes.SIZEOF_INT); int v = Bytes.toInt(b, o); if (v < 0) { throw new RuntimeException(); } return v; }
private void run(AtomicBoolean stop) throws InterruptedException, ExecutionException { while (!stop.get()) { for (int i = 0; i < COUNT; i++) { assertEquals(i, Bytes.toInt(TABLE.get(new Get(Bytes.toBytes(String.format("%03d", i)))) .get().getValue(FAMILY, QUALIFIER))); } } }
private int getCount(Table t, byte[] type) throws IOException { Get test = new Get(row); test.setAttribute("count", new byte[] {}); Result res = t.get(test); return Bytes.toInt(res.getValue(count, type)); }
@Override public Integer decode(PositionedByteRange src) { int val = Bytes.toInt(src.getBytes(), src.getOffset() + src.getPosition()); skip(src); return val; }
/** * 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()); }
@Override public boolean filterRowKey(Cell cell) throws IOException { return Bytes.toInt(cell.getRowArray(), cell.getRowOffset()) != 999; } }
@Override public ReturnCode filterCell(Cell c) throws IOException { if (Bytes.toInt(c.getRowArray(), c.getRowOffset()) == 999) { return ReturnCode.INCLUDE; } else { return ReturnCode.NEXT_COL; } } }
/** * 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()); }
protected final void verify(HBaseTestingUtility util, int start, int end) throws IOException { try (Table table = util.getConnection().getTable(TABLE_NAME)) { for (int i = start; i < end; i++) { assertEquals(i, Bytes.toInt(table.get(new Get(Bytes.toBytes(i))).getValue(CF, CQ))); } } }
private void assertResultEquals(Result result, int key, int start, int to) { assertEquals(to - start, result.size()); for (int i = start; i < to; i++) { assertEquals(key, Bytes.toInt(result.getValue(CF, Bytes.toBytes("cq" + i)))); } assertEquals(to - start == 4, result.mayHaveMoreCellsInRow()); }
@Test public void testStateMachineMultipleLevel() throws Exception { long procId = procExecutor.submitProcedure(new TestStateMachineProcedure(true)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExecutor, procId); Procedure<?> result = procExecutor.getResult(procId); ProcedureTestingUtility.assertProcNotFailed(result); assertEquals(19, Bytes.toInt(result.getResult())); assertEquals(4, procExecutor.getLastProcId()); }