本文整理了Java中org.apache.hadoop.hbase.util.Bytes.toShort()
方法的一些代码示例,展示了Bytes.toShort()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.toShort()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.util.Bytes
类名称:Bytes
方法名:toShort
[英]Converts a byte array to a short value
[中]将字节数组转换为短值
代码示例来源:origin: apache/hbase
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);
}
代码示例来源:origin: apache/hbase
/**
* 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);
}
代码示例来源:origin: apache/hbase
/**
* 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);
}
代码示例来源:origin: apache/hbase
/**
* Read a {@code short} value from the buffer {@code buff}.
*/
public short decodeShort(byte[] buff, int offset) {
return Bytes.toShort(buff, offset);
}
代码示例来源:origin: apache/hbase
/**
* 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);
}
代码示例来源:origin: apache/hbase
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;
}
代码示例来源:origin: alibaba/canal
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;
}
代码示例来源:origin: apache/hbase
/**
* @return Row length
*/
@Override
public short getRowLength() {
return Bytes.toShort(this.bytes, getKeyOffset());
}
代码示例来源:origin: apache/hbase
/**
* 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);
}
代码示例来源:origin: apache/hbase
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;
}
代码示例来源:origin: apache/hbase
/**
* @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];
}
代码示例来源:origin: apache/hbase
/**
* 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);
}
代码示例来源:origin: apache/hbase
@Override
public Short decode(PositionedByteRange src) {
short val = Bytes.toShort(src.getBytes(), src.getOffset() + src.getPosition());
skip(src);
return val;
}
代码示例来源:origin: apache/flink
return value[0];
case 3:
return Bytes.toShort(value);
case 4:
return Bytes.toInt(value);
代码示例来源:origin: apache/hbase
/**
* 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);
}
代码示例来源:origin: alibaba/canal
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);
代码示例来源:origin: alibaba/canal
res = Bytes.toShort(bytes);
代码示例来源:origin: apache/hbase
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());
}
}
代码示例来源:origin: apache/hbase
@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));
}
代码示例来源:origin: apache/hbase
private static short getTagValuePartAsShort(Tag t, int offset) {
if (t.hasArray()) {
return Bytes.toShort(t.getValueArray(), offset);
}
return ByteBufferUtils.toShort(t.getValueByteBuffer(), offset);
}
内容来源于网络,如有侵权,请联系作者删除!