/** * Converts a byte array to a long value. Assumes there will be * {@link #SIZEOF_LONG} bytes available. * * @param bytes bytes * @param offset offset * @return the long value */ public static long toLong(byte[] bytes, int offset) { return toLong(bytes, offset, SIZEOF_LONG); }
/** * Converts a byte array to a long value. Reverses * {@link #toBytes(long)} * @param bytes array * @return the long value */ public static long toLong(byte[] bytes) { return toLong(bytes, 0, SIZEOF_LONG); }
/** * @param bytes byte array * @param offset offset where double is * @return Return double made from passed bytes. */ public static double toDouble(final byte [] bytes, final int offset) { return Double.longBitsToDouble(toLong(bytes, offset, SIZEOF_LONG)); }
@Override public int compareTo(byte[] value, int offset, int length) { long that = Bytes.toLong(value, offset, length); return Long.compare(longValue, that); }
private static double decodeDouble(byte[] bytes, int o) { checkForSufficientLength(bytes, o, Bytes.SIZEOF_LONG); long l; l = Bytes.toLong(bytes, o); l--; l ^= (~l >> Long.SIZE - 1) | Long.MIN_VALUE; return Double.longBitsToDouble(l); }
/** * Represents interval [minStamp, Long.MAX_VALUE) * @param minStamp the minimum timestamp value, inclusive * @deprecated This is made @InterfaceAudience.Private in the 2.0 line and above and may be * changed to private or removed in 3.0. */ @Deprecated @InterfaceAudience.Private public TimeRange(byte [] minStamp) { this(Bytes.toLong(minStamp)); }
@Override public long getTimestamp() { int tsOffset = getTimestampOffset(); return Bytes.toLong(this.bytes, tsOffset); }
@Override public List<Values> toValues(ITuple tuple, Result result) throws Exception { List<Values> values = new ArrayList<Values>(); Cell[] cells = result.rawCells(); for (Cell cell : cells) { Values value = new Values(Bytes.toString(CellUtil.cloneQualifier(cell)), Bytes.toLong(CellUtil.cloneValue(cell))); values.add(value); } return values; }
private static boolean checkTestIncrementBytes(long val, long amount) throws IOException { byte[] value = Bytes.toBytes(val); byte [] testValue = {-1, -1, -1, -1, -1, -1, -1, -1}; if (value[0] > 0) { testValue = new byte[Bytes.SIZEOF_LONG]; } System.arraycopy(value, 0, testValue, testValue.length - value.length, value.length); long incrementResult = Bytes.toLong(Bytes.incrementBytes(value, amount)); return (Bytes.toLong(testValue) + amount) == incrementResult; }
@Override public boolean verify(byte[] rowKey, byte[] cf, byte[] column, byte[] value) { if (Bytes.BYTES_COMPARATOR.compare(column, FILTER_COLUMN) == 0) { // Relies on the filter from getScanFilter being used. return Bytes.toLong(value) == ACCEPTED_VALUE; } else if (Bytes.BYTES_COMPARATOR.compare(column, VALUE_COLUMN) == 0) { return LoadTestKVGenerator.verify(value, rowKey, cf, column); } return false; // some bogus value from read, we don't expect any such thing. }
private String makeRowReadable(byte[] bytes, int length) { long rowIdx = swapLong(Bytes.toLong(bytes, 0)); String suffix = Bytes.toString(bytes, 8, length - 8); return "Row #" + rowIdx + " suffix " + suffix; } }
private OptionalLong getExpireBefore() { ChildData data = cache.getCurrentData(); if (data == null) { return OptionalLong.empty(); } byte[] bytes = data.getData(); if (bytes == null || bytes.length != Long.BYTES) { return OptionalLong.empty(); } return OptionalLong.of(Bytes.toLong(bytes)); }
public long getCellTTL() { if (!hasCellTTL()) { return 0; } else { return Bytes.toLong(lineBytes, getColumnOffset(cellTTLColumnIndex), getColumnLength(cellTTLColumnIndex)); } }
public void testToLong() throws Exception { long [] longs = {-1l, 123l, Long.MIN_VALUE, Long.MAX_VALUE}; for (int i = 0; i < longs.length; i++) { byte [] b = Bytes.toBytes(longs[i]); assertEquals(longs[i], Bytes.toLong(b)); byte [] b2 = bytesWithOffset(b); assertEquals(longs[i], Bytes.toLong(b2, 1)); assertEquals(longs[i], Bytes.toLong(b2, 1, Bytes.SIZEOF_LONG)); } }
@Override public Long decode(PositionedByteRange src) { long val = Bytes.toLong(src.getBytes(), src.getOffset() + src.getPosition()); skip(src); return val; }
/** * 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 testIncrement() throws InterruptedException, ExecutionException { AsyncTable<?> table = ASYNC_CONN.getTable(TABLE_NAME); assertEquals(1L, table.incrementColumnValue(row, FAMILY, QUALIFIER, 1L).get().longValue()); // the second call should have no effect as we always generate the same nonce. assertEquals(1L, table.incrementColumnValue(row, FAMILY, QUALIFIER, 1L).get().longValue()); Result result = table.get(new Get(row)).get(); assertEquals(1L, Bytes.toLong(result.getValue(FAMILY, QUALIFIER))); } }
/** * 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()); }
protected static void checkIncrementValueXML(String table, String row, String column, long value) throws IOException, JAXBException { Response response1 = getValueXML(table, row, column); assertEquals(200, response1.getCode()); assertEquals(Constants.MIMETYPE_XML, response1.getHeader("content-type")); CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response1.getBody())); RowModel rowModel = cellSet.getRows().get(0); CellModel cell = rowModel.getCells().get(0); assertEquals(Bytes.toString(cell.getColumn()), column); assertEquals(Bytes.toLong(cell.getValue()), value); }
private static void assertOnlyLatest(final Table incommon, final long currentTime) throws IOException { Get get = null; get = new Get(ROW); get.addColumn(FAMILY_NAME, QUALIFIER_NAME); get.setMaxVersions(3); Result result = incommon.get(get); Assert.assertEquals(1, result.size()); long time = Bytes.toLong(CellUtil.cloneValue(result.rawCells()[0])); Assert.assertEquals(time, currentTime); }