本文整理了Java中co.cask.cdap.api.common.Bytes
类的一些代码示例,展示了Bytes
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes
类的具体详情如下:
包路径:co.cask.cdap.api.common.Bytes
类名称:Bytes
[英]Utility class that handles byte arrays, conversions to/from other types, comparisons, hash code generation, manufacturing keys for HashMaps or HashSets, etc.
[中]用于处理字节数组、与其他类型的转换、比较、哈希代码生成、为哈希映射或哈希集制造键等的实用程序类。
代码示例来源:origin: cdapio/cdap
@Override
public synchronized Integer getServiceInstance(final String serviceName) {
String count = Bytes.toString(table.get(Bytes.toBytes(serviceName)));
return (count != null) ? Integer.valueOf(count) : null;
}
代码示例来源: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: cdapio/cdap
@Override
public String toString() {
return "(" + (start == null ? "null" : "'" + Bytes.toStringBinary(start)) + "'"
+ ".." + (stop == null ? "null" : "'" + Bytes.toStringBinary(stop) + "'") + ")";
}
}
代码示例来源:origin: cdapio/cdap
private long incrementValue(long value, @Nullable byte[] existingValue, byte[] row, byte[] col) {
if (existingValue == null) {
return value;
}
if (existingValue.length != Bytes.SIZEOF_LONG) {
throw new NumberFormatException("Attempted to increment a value that is not convertible to long," +
" row: " + Bytes.toStringBinary(row) +
" column: " + Bytes.toStringBinary(col));
}
return value + Bytes.toLong(existingValue);
}
代码示例来源:origin: caskdata/cdap
private byte[] getRowKey(LogPathIdentifier identifier, long eventTime, long currentTime) {
return Bytes.concat(LoggingStoreTableUtil.NEW_FILE_META_ROW_KEY_PREFIX,
identifier.getRowkey().getBytes(StandardCharsets.UTF_8),
Bytes.toBytes(eventTime),
Bytes.toBytes(currentTime));
}
}
代码示例来源:origin: cdapio/cdap
private byte[][] createDeltaCache(int rollTime) {
byte[][] deltas = new byte[rollTime + 1][];
for (int i = 0; i <= rollTime; i++) {
deltas[i] = Bytes.toBytes((short) i);
}
return deltas;
}
}
代码示例来源:origin: co.cask.cdap/cdap-data-fabric
@Override
public EntityName load(EntityId key) throws Exception {
// Lookup the reverse mapping
byte[] rowKey = Bytes.concat(Bytes.toBytes(key.getType()), DOT, Bytes.toBytes(key.getId()));
byte[] result = table.get(rowKey, NAME);
if (result == null) {
throw new IllegalArgumentException("Entity name not found for type " + key.getType() + ", id " + key.getId());
}
return new EntityName(key.getType(), Bytes.toString(result));
}
};
代码示例来源:origin: caskdata/cdap
@Override
public ResourceAssignment decode(byte[] data) throws IOException {
return GSON.fromJson(Bytes.toString(data), ResourceAssignment.class);
}
};
代码示例来源:origin: cdapio/cdap
private long getCounts(String word, TimeseriesTable tsTable) {
long result = 0;
Iterator<TimeseriesTable.Entry> itor = tsTable.read(Bytes.toBytes(word), 0, Long.MAX_VALUE);
while (itor.hasNext()) {
result += Bytes.toLong(itor.next().getValue());
}
return result;
}
}
代码示例来源:origin: co.cask.cdap/cdap-app-fabric
private Scan scanPlugins(Id.Artifact parentArtifactId, @Nullable String type) {
byte[] startRow = Bytes.toBytes(Joiner.on(":").skipNulls().join(PLUGIN_PREFIX,
parentArtifactId.getNamespace().getId(),
parentArtifactId.getName(), type) + ":");
return new Scan(startRow, Bytes.stopKeyForPrefix(startRow));
}
代码示例来源:origin: cdapio/cdap
private void checkOutputData(DataSetManager<KeyValueTable> manager) {
KeyValueTable count = manager.get();
//read output and verify result
byte[] val = count.read(Bytes.toBytes(TEST_STRING_1));
Assert.assertTrue(val != null);
Assert.assertEquals(Bytes.toInt(val), TEST_STRING_1.length());
val = count.read(Bytes.toBytes(TEST_STRING_2));
Assert.assertTrue(val != null);
Assert.assertEquals(Bytes.toInt(val), TEST_STRING_2.length());
}
代码示例来源:origin: co.cask.cdap/cdap-data-fabric
/**
* @param stateValue value of the state column
* @return write pointer of the latest change of the state value
*/
public static long getStateWritePointer(byte[] stateValue) {
return Bytes.toLong(stateValue, 0, Longs.BYTES);
}
代码示例来源:origin: cdapio/cdap
public int getKeyLength() {
if (keyLength == 0) {
keyLength = Bytes.toInt(this.bytes, this.offset);
}
return keyLength;
}
代码示例来源:origin: co.cask.cdap/cdap-watchdog
private byte[] getNextContextStartKey(byte[] rowkey) {
// rowkey : <prefix-bytes>:context:event-ts(8):creation-time(8)
int contextLength = rowkey.length -
(LoggingStoreTableUtil.NEW_FILE_META_ROW_KEY_PREFIX.length + 2 * Bytes.SIZEOF_LONG);
Preconditions.checkState(contextLength > 0, String.format("Invalid row-key with length %s", rowkey.length));
byte[] context = new byte[contextLength];
System.arraycopy(rowkey, LoggingStoreTableUtil.NEW_FILE_META_ROW_KEY_PREFIX.length, context, 0, contextLength);
return Bytes.stopKeyForPrefix(context);
}
代码示例来源:origin: cdapio/cdap
@Override
public int compare(byte [] left, byte [] right) {
return compareTo(left, right);
}
}
代码示例来源:origin: caskdata/cdap
@Override
public CloseableIterator<Entry> fetch(TopicMetadata metadata, MessageId messageId, boolean inclusive,
final int limit, @Nullable final Transaction transaction) throws IOException {
byte[] topic = MessagingUtils.toDataKeyPrefix(metadata.getTopicId(), metadata.getGeneration());
byte[] startRow = new byte[topic.length + Bytes.SIZEOF_LONG + Bytes.SIZEOF_SHORT];
Bytes.putBytes(startRow, 0, topic, 0, topic.length);
Bytes.putLong(startRow, topic.length, messageId.getPublishTimestamp());
Bytes.putShort(startRow, topic.length + Bytes.SIZEOF_LONG, messageId.getSequenceId());
byte[] stopRow = Bytes.stopKeyForPrefix(topic);
final CloseableIterator<RawMessageTableEntry> scanner = read(startRow, stopRow);
return new FetchIterator(scanner, limit, inclusive ? null : startRow, transaction);
}
代码示例来源: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: caskdata/cdap
@Override
public CloseableIterator<Entry> fetch(TopicMetadata metadata, long startTime, int limit,
@Nullable Transaction transaction) throws IOException {
byte[] topic = MessagingUtils.toDataKeyPrefix(metadata.getTopicId(), metadata.getGeneration());
byte[] startRow = new byte[topic.length + Bytes.SIZEOF_LONG];
Bytes.putBytes(startRow, 0, topic, 0, topic.length);
Bytes.putLong(startRow, topic.length, startTime);
byte[] stopRow = Bytes.stopKeyForPrefix(topic);
final CloseableIterator<RawMessageTableEntry> scanner = read(startRow, stopRow);
return new FetchIterator(scanner, limit, null, transaction);
}
代码示例来源:origin: cdapio/cdap
private ImmutablePair<byte[], byte[]> getFuzzyKeyFor(MDSKey key) {
byte[] keyBytes = key.getKey();
// byte array is automatically initialized to 0, which implies fixed match in fuzzy info
// the row key after targetId doesn't need to be a match.
// Workaround for HBASE-15676, need to have at least one 1 in the fuzzy filter
byte[] infoBytes = new byte[keyBytes.length + 1];
infoBytes[infoBytes.length - 1] = 1;
// the key array size and mask array size has to be equal so increase the size by 1
return new ImmutablePair<>(Bytes.concat(keyBytes, new byte[1]), infoBytes);
}
代码示例来源:origin: cdapio/cdap
/**
* Write a value to a column.
* @param column column to write to
* @param value value to write
* @return instance of this {@link co.cask.cdap.api.dataset.table.Put}
*/
public Put add(String column, short value) {
return add(Bytes.toBytes(column), Bytes.toBytes(value));
}
内容来源于网络,如有侵权,请联系作者删除!