public KeyOnlyKeyValue(byte[] b, int offset, int length) { this.bytes = b; this.length = length; this.offset = offset; this.rowLen = Bytes.toShort(this.bytes, this.offset); }
/** * Converts a byte array to a short value * @param bytes byte array * @return the short value */ public static short toShort(byte[] bytes) { return toShort(bytes, 0, SIZEOF_SHORT); }
/** * Converts a byte array to a short value * @param bytes byte array * @param offset offset into array * @return the short value */ public static short toShort(byte[] bytes, int offset) { return toShort(bytes, offset, SIZEOF_SHORT); }
/** * Read a {@code short} value from the buffer {@code buff}. */ public short decodeShort(byte[] buff, int offset) { return Bytes.toShort(buff, offset); }
/** * A setter that helps to avoid object creation every time and whenever * there is a need to create new KeyOnlyKeyValue. * @param key * @param offset * @param length */ public void setKey(byte[] key, int offset, int length) { this.bytes = key; this.offset = offset; this.length = length; this.rowLen = Bytes.toShort(this.bytes, this.offset); }
public static byte[] keyOnly (byte[] b) { if (b == null) return b; int rowlength = Bytes.toShort(b, 0); byte[] result = new byte[rowlength]; System.arraycopy(b, Bytes.SIZEOF_SHORT, result, 0, rowlength); return result; }
private static short decodeUnsignedShort(byte[] b, int o) { checkForSufficientLength(b, o, Bytes.SIZEOF_SHORT); short v = Bytes.toShort(b, o); if (v < 0) { throw new RuntimeException(); } return v; }
/** * @return Row length */ @Override public short getRowLength() { return Bytes.toShort(this.bytes, getKeyOffset()); }
/** * Use this method instantiating a {@link ServerName} from bytes * gotten from a call to {@link #getVersionedBytes()}. Will take care of the * case where bytes were written by an earlier version of hbase. * @param versionedBytes Pass bytes gotten from a call to {@link #getVersionedBytes()} * @return A ServerName instance. * @see #getVersionedBytes() */ public static ServerName parseVersionedServerName(final byte [] versionedBytes) { // Version is a short. short version = Bytes.toShort(versionedBytes); if (version == VERSION) { int length = versionedBytes.length - Bytes.SIZEOF_SHORT; return valueOf(Bytes.toString(versionedBytes, Bytes.SIZEOF_SHORT, length)); } // Presume the bytes were written with an old version of hbase and that the // bytes are actually a String of the form "'<hostname>' ':' '<port>'". return valueOf(Bytes.toString(versionedBytes), NON_STARTCODE); }
private static TableDescriptor readTableDescriptor(FileSystem fs, FileStatus status) throws IOException { int len = Ints.checkedCast(status.getLen()); byte [] content = new byte[len]; FSDataInputStream fsDataInputStream = fs.open(status.getPath()); try { fsDataInputStream.readFully(content); } finally { fsDataInputStream.close(); } TableDescriptor htd = null; try { htd = TableDescriptorBuilder.parseFrom(content); } catch (DeserializationException e) { throw new IOException("content=" + Bytes.toShort(content), e); } return htd; }
/** * @param bs * @return Type from the Counts enum of this row. Reads prefix added by * {@link #addPrefixFlag(int, byte[])} */ public static Counts whichType(final byte [] bs) { int ordinal = Bytes.toShort(bs, 0, Bytes.SIZEOF_SHORT); return Counts.values()[ordinal]; }
/** * Used when a cell needs to be compared with a key byte[] such as cases of finding the index from * the index block, bloom keys from the bloom blocks This byte[] is expected to be serialized in * the KeyValue serialization format If the KeyValue (Cell's) serialization format changes this * method cannot be used. * @param comparator the cell comparator * @param left the cell to be compared * @param key the serialized key part of a KeyValue * @param offset the offset in the key byte[] * @param length the length of the key byte[] * @return an int greater than 0 if left is greater than right lesser than 0 if left is lesser * than right equal to 0 if left is equal to right * @deprecated As of HBase-2.0. Will be removed in HBase-3.0 */ @VisibleForTesting @Deprecated public static final int compare(CellComparator comparator, Cell left, byte[] key, int offset, int length) { // row short rrowlength = Bytes.toShort(key, offset); int c = comparator.compareRows(left, key, offset + Bytes.SIZEOF_SHORT, rrowlength); if (c != 0) return c; // Compare the rest of the two KVs without making any assumptions about // the common prefix. This function will not compare rows anyway, so we // don't need to tell it that the common prefix includes the row. return PrivateCellUtil.compareWithoutRow(comparator, left, key, offset, length, rrowlength); }
@Override public Short decode(PositionedByteRange src) { short val = Bytes.toShort(src.getBytes(), src.getOffset() + src.getPosition()); skip(src); return val; }
return value[0]; case 3: return Bytes.toShort(value); case 4: return Bytes.toInt(value);
/** * Used when a cell needs to be compared with a key byte[] such as cases of finding the index from * the index block, bloom keys from the bloom blocks This byte[] is expected to be serialized in * the KeyValue serialization format If the KeyValue (Cell's) serialization format changes this * method cannot be used. * @param comparator the cell comparator * @param left the cell to be compared * @param key the serialized key part of a KeyValue * @param offset the offset in the key byte[] * @param length the length of the key byte[] * @return an int greater than 0 if left is greater than right lesser than 0 if left is lesser * than right equal to 0 if left is equal to right */ @VisibleForTesting public static final int compare(CellComparator comparator, Cell left, byte[] key, int offset, int length) { // row short rrowlength = Bytes.toShort(key, offset); int c = comparator.compareRows(left, key, offset + Bytes.SIZEOF_SHORT, rrowlength); if (c != 0) return c; // Compare the rest of the two KVs without making any assumptions about // the common prefix. This function will not compare rows anyway, so we // don't need to tell it that the common prefix includes the row. return compareWithoutRow(comparator, left, key, offset, length, rrowlength); }
res = Bytes.toLong(bytes); } else if (Short.class == clazz || short.class == clazz) { res = Bytes.toShort(bytes); } else if (Boolean.class == clazz || boolean.class == clazz) { res = Bytes.toBoolean(bytes);
res = Bytes.toShort(bytes);
private static void testShort(boolean unsafe) throws Exception { setUnsafe(unsafe); try { for (short n : Arrays.asList( Short.MIN_VALUE, (short) -100, (short) -1, (short) 0, (short) 1, (short) 300, Short.MAX_VALUE)) { byte[] bytes = Bytes.toBytes(n); assertEquals(Bytes.toShort(bytes, 0, bytes.length), n); } } finally { setUnsafe(UnsafeAvailChecker.unaligned()); } }
@Test public void testCopyFromBufferToArray() { ByteBuffer buffer = ByteBuffer.allocate(15); buffer.put((byte) -1); long l = 988L; int i = 135; short s = 7; buffer.putShort(s); buffer.putInt(i); buffer.putLong(l); byte[] b = new byte[15]; ByteBufferUtils.copyFromBufferToArray(b, buffer, 1, 1, 14); assertEquals(s, Bytes.toShort(b, 1)); assertEquals(i, Bytes.toInt(b, 3)); assertEquals(l, Bytes.toLong(b, 7)); }
private static short getTagValuePartAsShort(Tag t, int offset) { if (t.hasArray()) { return Bytes.toShort(t.getValueArray(), offset); } return ByteBufferUtils.toShort(t.getValueByteBuffer(), offset); }