本文整理了Java中co.cask.cdap.api.common.Bytes.toShort()
方法的一些代码示例,展示了Bytes.toShort()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.toShort()
方法的具体详情如下:
包路径:co.cask.cdap.api.common.Bytes
类名称:Bytes
方法名:toShort
[英]Converts a byte array to a short value.
[中]将字节数组转换为短值。
代码示例来源:origin: co.cask.cdap/cdap-api-common
/**
* 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: cdapio/cdap
/**
* 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: cdapio/cdap
/**
* 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: co.cask.cdap/cdap-api-common
/**
* 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: cdapio/cdap
/**
* @return Row length
*/
public short getRowLength() {
return Bytes.toShort(this.bytes, getKeyOffset());
}
代码示例来源:origin: cdapio/cdap
@Override
@Nullable
public Short getShort(byte[] column) {
byte[] val = get(column);
return val == null ? null : Bytes.toShort(columns.get(column));
}
代码示例来源:origin: co.cask.cdap/cdap-data-fabric
/**
* @return Row length
*/
public short getRowLength() {
return Bytes.toShort(this.bytes, getKeyOffset());
}
代码示例来源:origin: cdapio/cdap
public int compare(byte[] left, int loffset, int llength, byte[] right,
int roffset, int rlength) {
// Compare row
short lrowlength = Bytes.toShort(left, loffset);
short rrowlength = Bytes.toShort(right, roffset);
int compare = compareRows(left, loffset + Bytes.SIZEOF_SHORT,
lrowlength, right, roffset + Bytes.SIZEOF_SHORT, rrowlength);
if (compare != 0) {
return compare;
}
// 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(0, left, loffset, llength, right, roffset,
rlength, rrowlength);
}
代码示例来源:origin: co.cask.cdap/cdap-tms
/**
* Creates a instance based on the given raw id bytes. The provided byte array will be store as is without
* copying.
*/
public MessageId(byte[] rawId) {
this.rawId = rawId;
int offset = 0;
this.publishTimestamp = Bytes.toLong(rawId, offset);
offset += Bytes.SIZEOF_LONG;
this.sequenceId = Bytes.toShort(rawId, offset);
offset += Bytes.SIZEOF_SHORT;
this.writeTimestamp = Bytes.toLong(rawId, offset);
offset += Bytes.SIZEOF_LONG;
this.payloadSequenceId = Bytes.toShort(rawId, offset);
}
代码示例来源:origin: caskdata/cdap
/**
* Creates a instance based on the given raw id bytes. The provided byte array will be store as is without
* copying.
*/
public MessageId(byte[] rawId) {
this.rawId = rawId;
int offset = 0;
this.publishTimestamp = Bytes.toLong(rawId, offset);
offset += Bytes.SIZEOF_LONG;
this.sequenceId = Bytes.toShort(rawId, offset);
offset += Bytes.SIZEOF_SHORT;
this.writeTimestamp = Bytes.toLong(rawId, offset);
offset += Bytes.SIZEOF_LONG;
this.payloadSequenceId = Bytes.toShort(rawId, offset);
}
代码示例来源:origin: co.cask.cdap/cdap-data-fabric
public int compare(byte[] left, int loffset, int llength, byte[] right,
int roffset, int rlength) {
// Compare row
short lrowlength = Bytes.toShort(left, loffset);
short rrowlength = Bytes.toShort(right, roffset);
int compare = compareRows(left, loffset + Bytes.SIZEOF_SHORT,
lrowlength, right, roffset + Bytes.SIZEOF_SHORT, rrowlength);
if (compare != 0) {
return compare;
}
// 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(0, left, loffset, llength, right, roffset,
rlength, rrowlength);
}
代码示例来源:origin: cdapio/cdap
public long getTimestamp(byte[] rowKey, byte[] column) {
// timebase is encoded as int after the encoded agg group
int timebase = Bytes.toInt(rowKey, VERSION.length + entityTable.getIdSize());
// time leftover is encoded as 2 byte column name
int leftover = Bytes.toShort(column) * resolution;
return timebase + leftover;
}
代码示例来源:origin: co.cask.cdap/cdap-data-fabric
public long getTimestamp(byte[] rowKey, byte[] column) {
// timebase is encoded as int after the encoded agg group
int timebase = Bytes.toInt(rowKey, VERSION.length + entityTable.getIdSize());
// time leftover is encoded as 2 byte column name
int leftover = Bytes.toShort(column) * resolution;
return timebase + leftover;
}
代码示例来源:origin: caskdata/cdap
public ImmutableMessageTableEntry(byte[] row, @Nullable byte[] payload, @Nullable byte[] txPtr) {
this.topicId = MessagingUtils.toTopicId(row, 0,
row.length - Bytes.SIZEOF_SHORT - Bytes.SIZEOF_LONG - Bytes.SIZEOF_INT);
this.generation = Bytes.toInt(row, row.length - Bytes.SIZEOF_SHORT - Bytes.SIZEOF_LONG - Bytes.SIZEOF_INT);
int topicLength = MessagingUtils.getTopicLengthMessageEntry(row.length);
this.publishTimestamp = Bytes.toLong(row, topicLength);
this.sequenceId = Bytes.toShort(row, topicLength + Bytes.SIZEOF_LONG);
this.transactional = (txPtr != null);
// since we mark tx as negative when tx is rolled back, we return the absolute value of tx
this.transactionWritePointer = txPtr == null ? -1 : Math.abs(Bytes.toLong(txPtr));
this.payload = payload;
}
代码示例来源:origin: co.cask.cdap/cdap-tms
public ImmutableMessageTableEntry(byte[] row, @Nullable byte[] payload, @Nullable byte[] txPtr) {
this.topicId = MessagingUtils.toTopicId(row, 0,
row.length - Bytes.SIZEOF_SHORT - Bytes.SIZEOF_LONG - Bytes.SIZEOF_INT);
this.generation = Bytes.toInt(row, row.length - Bytes.SIZEOF_SHORT - Bytes.SIZEOF_LONG - Bytes.SIZEOF_INT);
int topicLength = MessagingUtils.getTopicLengthMessageEntry(row.length);
this.publishTimestamp = Bytes.toLong(row, topicLength);
this.sequenceId = Bytes.toShort(row, topicLength + Bytes.SIZEOF_LONG);
this.transactional = (txPtr != null);
// since we mark tx as negative when tx is rolled back, we return the absolute value of tx
this.transactionWritePointer = txPtr == null ? -1 : Math.abs(Bytes.toLong(txPtr));
this.payload = payload;
}
代码示例来源:origin: caskdata/cdap
public ImmutablePayloadTableEntry(byte[] row, byte[] payload) {
this.topicId = MessagingUtils.toTopicId(row, 0, row.length - Bytes.SIZEOF_SHORT - (2 * Bytes.SIZEOF_LONG)
- Bytes.SIZEOF_INT);
this.generation = Bytes.toInt(row, row.length - Bytes.SIZEOF_SHORT - (2 * Bytes.SIZEOF_LONG) - Bytes.SIZEOF_INT);
this.transactionWriterPointer = Bytes.toLong(row, row.length - Bytes.SIZEOF_SHORT - (2 * Bytes.SIZEOF_LONG));
this.writeTimestamp = Bytes.toLong(row, row.length - Bytes.SIZEOF_SHORT - Bytes.SIZEOF_LONG);
this.sequenceId = Bytes.toShort(row, row.length - Bytes.SIZEOF_SHORT);
this.payload = payload;
}
代码示例来源:origin: co.cask.cdap/cdap-tms
public ImmutablePayloadTableEntry(byte[] row, byte[] payload) {
this.topicId = MessagingUtils.toTopicId(row, 0, row.length - Bytes.SIZEOF_SHORT - (2 * Bytes.SIZEOF_LONG)
- Bytes.SIZEOF_INT);
this.generation = Bytes.toInt(row, row.length - Bytes.SIZEOF_SHORT - (2 * Bytes.SIZEOF_LONG) - Bytes.SIZEOF_INT);
this.transactionWriterPointer = Bytes.toLong(row, row.length - Bytes.SIZEOF_SHORT - (2 * Bytes.SIZEOF_LONG));
this.writeTimestamp = Bytes.toLong(row, row.length - Bytes.SIZEOF_SHORT - Bytes.SIZEOF_LONG);
this.sequenceId = Bytes.toShort(row, row.length - Bytes.SIZEOF_SHORT);
this.payload = payload;
}
代码示例来源:origin: cdapio/cdap
int valLen = Bytes.toInt(bytes, splitOffset);
splitOffset += Bytes.SIZEOF_INT;
short rowLen = Bytes.toShort(bytes, splitOffset);
splitOffset += Bytes.SIZEOF_SHORT;
byte [] row = new byte[rowLen];
代码示例来源:origin: cdapio/cdap
public static String keyToString(final byte [] b, final int o, final int l) {
if (b == null) {
return "";
}
int rowlength = Bytes.toShort(b, o);
String row = Bytes.toStringBinary(b, o + Bytes.SIZEOF_SHORT, rowlength);
int columnoffset = o + Bytes.SIZEOF_SHORT + 1 + rowlength;
int familylength = b[columnoffset - 1];
int columnlength = l - ((columnoffset - o) + TIMESTAMP_TYPE_SIZE);
String family = familylength == 0 ? "" :
Bytes.toStringBinary(b, columnoffset, familylength);
String qualifier = columnlength == 0 ? "" :
Bytes.toStringBinary(b, columnoffset + familylength,
columnlength - familylength);
long timestamp = Bytes.toLong(b, o + (l - TIMESTAMP_TYPE_SIZE));
String timestampStr = humanReadableTimestamp(timestamp);
byte type = b[o + l - 1];
return row + "/" + family +
(family != null && family.length() > 0 ? ":" : "") +
qualifier + "/" + timestampStr + "/" + Type.codeToType(type);
}
代码示例来源:origin: co.cask.cdap/cdap-data-fabric
public static String keyToString(final byte [] b, final int o, final int l) {
if (b == null) {
return "";
}
int rowlength = Bytes.toShort(b, o);
String row = Bytes.toStringBinary(b, o + Bytes.SIZEOF_SHORT, rowlength);
int columnoffset = o + Bytes.SIZEOF_SHORT + 1 + rowlength;
int familylength = b[columnoffset - 1];
int columnlength = l - ((columnoffset - o) + TIMESTAMP_TYPE_SIZE);
String family = familylength == 0 ? "" :
Bytes.toStringBinary(b, columnoffset, familylength);
String qualifier = columnlength == 0 ? "" :
Bytes.toStringBinary(b, columnoffset + familylength,
columnlength - familylength);
long timestamp = Bytes.toLong(b, o + (l - TIMESTAMP_TYPE_SIZE));
String timestampStr = humanReadableTimestamp(timestamp);
byte type = b[o + l - 1];
return row + "/" + family +
(family != null && family.length() > 0 ? ":" : "") +
qualifier + "/" + timestampStr + "/" + Type.codeToType(type);
}
内容来源于网络,如有侵权,请联系作者删除!