co.cask.cdap.api.common.Bytes.toBytes()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中co.cask.cdap.api.common.Bytes.toBytes()方法的一些代码示例,展示了Bytes.toBytes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.toBytes()方法的具体详情如下:
包路径:co.cask.cdap.api.common.Bytes
类名称:Bytes
方法名:toBytes

Bytes.toBytes介绍

[英]Serialize a double as the IEEE 754 double format output. The resultant array will be 8 bytes long.
[中]

代码示例

代码示例来源: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: 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));
}

代码示例来源: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, float value) {
 return add(Bytes.toBytes(column), Bytes.toBytes(value));
}

代码示例来源:origin: cdapio/cdap

@Override
@Nullable
public String getString(String column) {
 return getString(Bytes.toBytes(column));
}

代码示例来源: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(byte[] column, String value) {
 return add(column, Bytes.toBytes(value));
}

代码示例来源: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(byte[] column, double value) {
 return add(column, Bytes.toBytes(value));
}

代码示例来源:origin: cdapio/cdap

/**
 * Write at least one value in a column of a row.
 * @param row row to write to
 * @param column column to write to
 * @param value value to write
 */
public Put(String row, String column, boolean value) {
 this(Bytes.toBytes(row));
 add(column, value);
}

代码示例来源:origin: cdapio/cdap

/**
 * Write at least one value in a column of a row.
 * @param row row to write to
 * @param column column to write to
 * @param value value to write
 */
public Put(String row, String column, long value) {
 this(Bytes.toBytes(row));
 add(column, value);
}

代码示例来源:origin: cdapio/cdap

/**
 * Write at least one value in a column of a row.
 * @param row row to write to
 * @param column column to write to
 * @param value value to write
 */
public Put(String row, String column, float value) {
 this(Bytes.toBytes(row));
 add(column, value);
}

代码示例来源: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: cdapio/cdap

/**
 * Convert {@link TopicId} to byte array to be used a message tables row key prefix.
 *
 * @param topicId {@link TopicId}
 * @return byte array representation for the topic id
 */
public static byte[] toMetadataRowKey(TopicId topicId) {
 String topic = topicId.getNamespace() + ":" + topicId.getTopic() + ":";
 return Bytes.toBytes(topic);
}

代码示例来源:origin: caskdata/cdap

private byte[][] getCategories(List<String> categories) {
  byte[][] byteCategories = new byte[categories.size()][];
  for (int i = 0; i < categories.size(); i++) {
   byteCategories[i] = Bytes.toBytes(categories.get(i));
  }
  return byteCategories;
 }
}

代码示例来源:origin: cdapio/cdap

@WriteOnly
@Override
public void write(String key, T object) {
 kvTable.write(Bytes.toBytes(key), encode(object));
}

代码示例来源:origin: cdapio/cdap

@Override
 public Tuple2<byte[], byte[]> call(Tuple2<String, Integer> input) throws Exception {
  return new Tuple2<>(Bytes.toBytes(input._1()), Bytes.toBytes(input._2()));
 }
});

代码示例来源:origin: cdapio/cdap

@Override
public void delete(final ProgramId serviceId) throws NotFoundException {
 Transactionals.execute(transactional, context -> {
  byte[] key = Bytes.toBytes(ServiceDiscoverable.getName(serviceId));
  KeyValueTable kvTable = getRouteTable(context);
  if (kvTable.read(key) == null) {
   throw new NotFoundException(String.format("Route Config for Service %s was not found.", serviceId));
  }
  kvTable.delete(key);
 }, NotFoundException.class);
}

代码示例来源:origin: caskdata/cdap

private Set<Field<?>> generateFieldsSet() {
  return ImmutableSet.of(
   Fields.bytesField("bytes", Bytes.toBytes("bytesval")),
   Fields.stringField("string", "strval"),
   Fields.doubleField("double", 100.0),
   Fields.intField("int", 30),
   Fields.bytesField("double-bytes", Bytes.toBytes(100.0)),
   Fields.bytesField("long-bytes", Bytes.toBytes(600L))
  );
 }
}

代码示例来源:origin: cdapio/cdap

public Builder putValue(String namespace, String name, String data) {
 SecureStoreMetadata meta = new SecureStoreMetadata(name, "desc", System.currentTimeMillis(),
                           Collections.emptyMap());
 return putValue(namespace, name, new SecureStoreData(meta, Bytes.toBytes(data)));
}

代码示例来源:origin: cdapio/cdap

private void prepareInputData(DataSetManager<ObjectStore<String>> manager) {
 ObjectStore<String> keys = manager.get();
 keys.write(Bytes.toBytes(TEST_STRING_1), TEST_STRING_1);
 keys.write(Bytes.toBytes(TEST_STRING_2), TEST_STRING_2);
 manager.flush();
}

代码示例来源: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: caskdata/cdap

private void checkData(CloseableIterator<PayloadTable.Entry> entries, int payload, Set<Long> acceptablePtrs,
            int expectedCount) {
 int count = 0;
 while (entries.hasNext()) {
  PayloadTable.Entry entry = entries.next();
  Assert.assertTrue(acceptablePtrs.contains(entry.getTransactionWritePointer()));
  Assert.assertArrayEquals(Bytes.toBytes(payload), entry.getPayload());
  count++;
 }
 Assert.assertEquals(expectedCount, count);
}

相关文章