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

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

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

Bytes.fromHexString介绍

[英]Returns a byte[] by decoding from the given hexadecimal string. The string must be have an even length.
[中]通过解码给定的十六进制字符串返回字节[]。字符串的长度必须为偶数。

代码示例

代码示例来源:origin: co.cask.cdap/cdap-tms

/**
 * Returns the publish time encoded in the given message id.
 *
 * @param messageId the message id to decode
 * @return the publish time or {@code 0} if the message id is {@code null}.
 */
private long getMessagePublishTime(String messageId) {
 return new MessageId(Bytes.fromHexString(messageId)).getPublishTimestamp();
}

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

/**
 * Returns the publish time encoded in the given message id.
 *
 * @param messageId the message id to decode
 * @return the publish time or {@code 0} if the message id is {@code null}.
 */
private long getMessagePublishTime(String messageId) {
 return new MessageId(Bytes.fromHexString(messageId)).getPublishTimestamp();
}

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

private void printTopicMessageIds() throws TransactionFailureException {
 transactional.execute(context -> {
  System.out.println("Getting notification subscriber messageIds.");
  List<String> topics = ImmutableList.of(cConf.get(Constants.Scheduler.TIME_EVENT_TOPIC),
                      cConf.get(Constants.Dataset.DATA_EVENT_TOPIC));
  for (String topic : topics) {
   String messageIdString = jobQueue.retrieveSubscriberState(topic);
   String publishTimestampString = messageIdString == null ? "n/a" :
    Long.toString(new MessageId(Bytes.fromHexString(messageIdString)).getPublishTimestamp());
   System.out.println(String.format("Topic: %s, Publish Timestamp: %s", topic, publishTimestampString));
  }
 });
}

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

private long getMessagePublishTime(MonitorMessage message) {
 return new MessageId(Bytes.fromHexString(message.getMessageId())).getPublishTimestamp();
}

代码示例来源:origin: co.cask.wrangler/wrangler-core

/**
 * Retrieves schema provided a schema id and version of the schema.
 *
 * @param id of the schema.
 * @param version of the schema.
 * @return {@link Response} of the schema.
 * @throws URISyntaxException thrown if there are issue with construction of url.
 * @throws IOException throw when there are issues connecting to the service.
 * @throws RestClientException thrown when there are issues with request or response returned.
 */
public byte[] getSchema(String id, long version)
 throws URISyntaxException, IOException, RestClientException {
 URL url = concat(new URI(baseUrl), String.format("schemas/%s/versions/%d", id, version)).toURL();
 Response<SchemaInfo> response = request(url, "GET", new TypeToken<Response<SchemaInfo>>(){}.getType());
 if (response.getCount() == 1) {
  return Bytes.fromHexString(response.getValues().get(0).getSpecification());
 }
 return null;
}

代码示例来源:origin: co.cask.cdap/cdap-app-fabric

private long getMessagePublishTime(MonitorMessage message) {
 return new MessageId(Bytes.fromHexString(message.getMessageId())).getPublishTimestamp();
}

代码示例来源:origin: co.cask.wrangler/wrangler-core

/**
 * Retrieves schema provided a schema id. It provides the latest, current version of schema.
 *
 * @param id of the schema.
 * @return {@link SchemaInfo} of the schema if ok, else null.
 * @throws URISyntaxException thrown if there are issue with construction of url.
 * @throws IOException throw when there are issues connecting to the service.
 * @throws RestClientException thrown when there are issues with request or response returned.
 */
public byte[] getSchema(String id)
 throws URISyntaxException, IOException, RestClientException {
 URL url = concat(new URI(baseUrl), String.format("schemas/%s", id)).toURL();
 Response<SchemaInfo> response = request(url, "GET", new TypeToken<Response<SchemaInfo>>(){}.getType());
 if (response.getCount() == 1) {
  return Bytes.fromHexString(response.getValues().get(0).getSpecification());
 }
 return null;
}

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

@Override
public CloseableIterator<Message> fetch(String namespace, String topic, int limit,
                    @Nullable String afterMessageId) throws IOException, TopicNotFoundException {
 co.cask.cdap.messaging.MessageFetcher fetcher = messagingService
  .prepareFetch(new NamespaceId(namespace).topic(topic))
  .setLimit(limit);
 if (afterMessageId != null) {
  fetcher.setStartMessage(Bytes.fromHexString(afterMessageId), false);
 }
 if (transaction != null) {
  fetcher.setTransaction(transaction);
 }
 return new MessageIterator(fetcher.fetch());
}

代码示例来源:origin: co.cask.cdap/cdap-tms

@Override
public CloseableIterator<Message> fetch(String namespace, String topic, int limit,
                    @Nullable String afterMessageId) throws IOException, TopicNotFoundException {
 co.cask.cdap.messaging.MessageFetcher fetcher = messagingService
  .prepareFetch(new NamespaceId(namespace).topic(topic))
  .setLimit(limit);
 if (afterMessageId != null) {
  fetcher.setStartMessage(Bytes.fromHexString(afterMessageId), false);
 }
 if (transaction != null) {
  fetcher.setTransaction(transaction);
 }
 return new MessageIterator(fetcher.fetch());
}

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

@Nullable
private MessageId getLastMessageId(final TopicId topic) {
 return Transactionals.execute(transactional, context -> {
  JobQueueDataset jobQueue = context.getDataset(Schedulers.JOB_QUEUE_DATASET_ID.getNamespace(),
                         Schedulers.JOB_QUEUE_DATASET_ID.getDataset());
  String id = jobQueue.retrieveSubscriberState(topic.getTopic());
  if (id == null) {
   return null;
  }
  byte[] bytes = Bytes.fromHexString(id);
  return new MessageId(bytes);
 });
}

相关文章