/** * Reads a big-endian 8-byte long from the begining of the given array. * @param b The array to read from. * @return A long integer. * @throws IndexOutOfBoundsException if the byte array is too small. */ public static long getLong(final byte[] b) { return getLong(b, 0); }
/** * Extracts the value of a cell containing a data point. * * @param value The contents of a cell in HBase. * @param value_idx The offset inside {@code values} at which the value * starts. * @param flags The flags for this value. * @return The value of the cell. */ static double extractFloatingPointValue(final byte[] values, final int value_idx, final byte flags) { switch (flags & Const.LENGTH_MASK) { case 7: return Double.longBitsToDouble(Bytes.getLong(values, value_idx)); case 3: return Float.intBitsToFloat(Bytes.getInt(values, value_idx)); } throw new IllegalDataException("Floating point value @ " + value_idx + " not on 8 or 4 bytes in " + Arrays.toString(values)); }
@Override Object deserialize(final ChannelBuffer buf, int cell_size) { final MutateResponse resp = readProtobuf(buf, MutateResponse.PARSER); // An increment must always produce a result, so we shouldn't need to // check whether the `result' field is set here. final ArrayList<KeyValue> kvs = GetRequest.convertResult(resp.getResult(), buf, cell_size); if (kvs.size() != 1) { throw new InvalidResponseException("Atomic increment returned " + kvs.size() + " KeyValue(s), but we expected exactly one. kvs=" + kvs, resp); } return Bytes.getLong(kvs.get(0).value()); }
@Override Object deserialize(final ChannelBuffer buf, int cell_size) { final MutateResponse resp = readProtobuf(buf, MutateResponse.PARSER); // An increment must always produce a result, so we shouldn't need to // check whether the `result' field is set here. final ArrayList<KeyValue> kvs = GetRequest.convertResult(resp.getResult(), buf, cell_size); Map<byte[], Long> updatedValues = Maps.newHashMap(); for (KeyValue kv : kvs) { updatedValues.put(kv.qualifier(), Bytes.getLong(kv.value())); } return updatedValues; }
/** * Extracts the value of a cell containing a data point. * * @param value The contents of a cell in HBase. * @param value_idx The offset inside {@code values} at which the value * starts. * @param flags The flags for this value. * @return The value of the cell. */ static long extractIntegerValue(final byte[] values, final int value_idx, final byte flags) { switch (flags & Const.LENGTH_MASK) { case 7: return Bytes.getLong(values, value_idx); case 3: return Bytes.getInt(values, value_idx); case 1: return Bytes.getShort(values, value_idx); case 0: return values[value_idx]; } throw new IllegalDataException("Integer value @ " + value_idx + " not on 8/4/2/1 bytes in " + Arrays.toString(values)); }
+ ": should be on 8 bytes: "); } else { uids.maxid = Bytes.getLong(value); LOG.info("Maximum ID for " + kind + ": " + uids.maxid);
qualifiers[size] = qualifier; values[size] = (value.length == 8 ? Bytes.getLong(value) : Bytes.getInt(value) & 0x00000000FFFFFFFFL); size++;