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

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

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

Bytes.putInt介绍

[英]Put an int value out to the specified byte array position.
[中]将int值输出到指定的字节数组位置。

代码示例

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

/**
 * Put a float value out to the specified byte array position.
 * @param bytes byte array
 * @param offset offset to write to
 * @param f float value
 * @return New offset in <code>bytes</code>
 */
public static int putFloat(byte [] bytes, int offset, float f) {
 return putInt(bytes, offset, Float.floatToRawIntBits(f));
}

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

/**
 * Put a float value out to the specified byte array position.
 * @param bytes byte array
 * @param offset offset to write to
 * @param f float value
 * @return New offset in <code>bytes</code>
 */
public static int putFloat(byte [] bytes, int offset, float f) {
 return putInt(bytes, offset, Float.floatToRawIntBits(f));
}

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

private byte[] getColumn(long groupId, int instanceId) {
 byte[] column = new byte[Longs.BYTES + Ints.BYTES];
 Bytes.putLong(column, 0, groupId);
 Bytes.putInt(column, Longs.BYTES, instanceId);
 return column;
}

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

public static KeyValue fromKey(byte[] key) {
  int len = key.length + (2 * Bytes.SIZEOF_INT);
  byte[] kvBytes = new byte[len];
  int pos = 0;
  pos = Bytes.putInt(kvBytes, pos, key.length);
  pos = Bytes.putInt(kvBytes, pos, 0);
  Bytes.putBytes(kvBytes, pos, key, 0, key.length);
  return new KeyValue(kvBytes);
 }
}

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

/**
 * Returns the column qualifier for the consumer state column. The qualifier is formed by
 * {@code <groupId><instanceId>}.
 * @param groupId Group ID of the consumer
 * @param instanceId Instance ID of the consumer
 * @return A new byte[] which is the column qualifier.
 */
private byte[] getConsumerStateColumn(long groupId, int instanceId) {
 byte[] column = new byte[Longs.BYTES + Ints.BYTES];
 Bytes.putLong(column, 0, groupId);
 Bytes.putInt(column, Longs.BYTES, instanceId);
 return column;
}

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

/**
 * Get the next row based on the given write pointer and counter. It modifies the given row byte[] in place
 * and returns it.
 */
private byte[] getNextRow(byte[] row, long writePointer, int count) {
 Bytes.putLong(row, queueRowPrefix.length, writePointer);
 Bytes.putInt(row, queueRowPrefix.length + Longs.BYTES, count + 1);
 return row;
}

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

public static KeyValue fromKey(byte[] key) {
  int len = key.length + (2 * Bytes.SIZEOF_INT);
  byte[] kvBytes = new byte[len];
  int pos = 0;
  pos = Bytes.putInt(kvBytes, pos, key.length);
  pos = Bytes.putInt(kvBytes, pos, 0);
  Bytes.putBytes(kvBytes, pos, key, 0, key.length);
  return new KeyValue(kvBytes);
 }
}

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

/**
 * Convert a BigDecimal value to a byte array.
 *
 * @param val
 * @return the byte array
 */
public static byte[] toBytes(BigDecimal val) {
 byte[] valueBytes = val.unscaledValue().toByteArray();
 byte[] result = new byte[valueBytes.length + SIZEOF_INT];
 int offset = putInt(result, 0, val.scale());
 putBytes(result, offset, valueBytes, 0, valueBytes.length);
 return result;
}

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

/**
 * Convert a BigDecimal value to a byte array.
 *
 * @param val
 * @return the byte array
 */
public static byte[] toBytes(BigDecimal val) {
 byte[] valueBytes = val.unscaledValue().toByteArray();
 byte[] result = new byte[valueBytes.length + SIZEOF_INT];
 int offset = putInt(result, 0, val.scale());
 putBytes(result, offset, valueBytes, 0, valueBytes.length);
 return result;
}

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

/**
 * Put a BigDecimal value out to the specified byte array position.
 *
 * @param bytes  the byte array
 * @param offset position in the array
 * @param val    BigDecimal to write out
 * @return incremented offset
 */
public static int putBigDecimal(byte[] bytes, int offset, BigDecimal val) {
 if (bytes == null) {
  return offset;
 }
 byte[] valueBytes = val.unscaledValue().toByteArray();
 byte[] result = new byte[valueBytes.length + SIZEOF_INT];
 offset = putInt(result, offset, val.scale());
 return putBytes(result, offset, valueBytes, 0, valueBytes.length);
}

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

/**
 * Put a BigDecimal value out to the specified byte array position.
 *
 * @param bytes  the byte array
 * @param offset position in the array
 * @param val    BigDecimal to write out
 * @return incremented offset
 */
public static int putBigDecimal(byte[] bytes, int offset, BigDecimal val) {
 if (bytes == null) {
  return offset;
 }
 byte[] valueBytes = val.unscaledValue().toByteArray();
 byte[] result = new byte[valueBytes.length + SIZEOF_INT];
 offset = putInt(result, offset, val.scale());
 return putBytes(result, offset, valueBytes, 0, valueBytes.length);
}

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

private String getMultipartKey(String... parts) {
  int sizeOfParts = Stream.of(parts).mapToInt(String::length).reduce(0, (a, b) -> a + b);

  byte[] result = new byte[sizeOfParts + (parts.length * Bytes.SIZEOF_INT)];

  int offset = 0;
  for (String part : parts) {
   Bytes.putInt(result, offset, part.length());
   offset += Bytes.SIZEOF_INT;
   Bytes.putBytes(result, offset, part.getBytes(), 0, part.length());
   offset += part.length();
  }
  return Bytes.toString(result);
 }
}

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

private byte[] getMultipartKey(String... parts) {
  int sizeOfParts = 0;
  for (String part : parts) {
   sizeOfParts += part.length();
  }

  byte[] result = new byte[1 + sizeOfParts + (parts.length * Bytes.SIZEOF_INT)];
  Bytes.putByte(result, 0, Constants.ConfigStore.VERSION);

  int offset = 1;
  for (String part : parts) {
   Bytes.putInt(result, offset, part.length());
   offset += Bytes.SIZEOF_INT;
   Bytes.putBytes(result, offset, part.getBytes(), 0, part.length());
   offset += part.length();
  }
  return result;
 }
}

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

private String getMultipartKey(String... parts) {
  int sizeOfParts = Stream.of(parts).mapToInt(String::length).reduce(0, (a, b) -> a + b);

  byte[] result = new byte[sizeOfParts + (parts.length * Bytes.SIZEOF_INT)];

  int offset = 0;
  for (String part : parts) {
   Bytes.putInt(result, offset, part.length());
   offset += Bytes.SIZEOF_INT;
   Bytes.putBytes(result, offset, part.getBytes(), 0, part.length());
   offset += part.length();
  }
  return Bytes.toString(result);
 }
}

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

@Override
public void getRowKeys(Iterable<ConsumerGroupConfig> consumerGroupConfigs, QueueEntry queueEntry, byte[] rowKeyPrefix,
            long writePointer, int counter, Collection<byte[]> rowKeys) {
 byte[] rowKey = new byte[rowKeyPrefix.length + Bytes.SIZEOF_LONG + Bytes.SIZEOF_INT];
 Bytes.putBytes(rowKey, 0, rowKeyPrefix, 0, rowKeyPrefix.length);
 Bytes.putLong(rowKey, rowKeyPrefix.length, writePointer);
 Bytes.putInt(rowKey, rowKey.length - Bytes.SIZEOF_INT, counter);
 rowKeys.add(rowKeyDistributor.getDistributedKey(rowKey));
}

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

/**
 * Convert {@link TopicId} and generation id to byte array to be used for data tables (message and payload) as
 * row key prefix.
 *
 * @param topicId {@link TopicId}
 * @param generation generation id of the topic
 * @return byte array representation to be used as row key prefix for data tables
 */
public static byte[] toDataKeyPrefix(TopicId topicId, int generation) {
 byte[] metadataRowKey = toMetadataRowKey(topicId);
 byte[] keyPrefix = new byte[metadataRowKey.length + Bytes.SIZEOF_INT];
 Bytes.putBytes(keyPrefix, 0, metadataRowKey, 0, metadataRowKey.length);
 Bytes.putInt(keyPrefix, metadataRowKey.length, generation);
 return keyPrefix;
}

代码示例来源:origin: co.cask.cdap/cdap-hbase-compat-base

/**
 * Convert {@link TopicId} and generation id to byte array to be used for data tables (message and payload) as
 * row key prefix.
 *
 * @param topicId {@link TopicId}
 * @param generation generation id of the topic
 * @return byte array representation to be used as row key prefix for data tables
 */
public static byte[] toDataKeyPrefix(TopicId topicId, int generation) {
 byte[] metadataRowKey = toMetadataRowKey(topicId);
 byte[] keyPrefix = new byte[metadataRowKey.length + Bytes.SIZEOF_INT];
 Bytes.putBytes(keyPrefix, 0, metadataRowKey, 0, metadataRowKey.length);
 Bytes.putInt(keyPrefix, metadataRowKey.length, generation);
 return keyPrefix;
}

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

private byte[] getShardedKey(ConsumerGroupConfig groupConfig, int instanceId,
                byte[] originalRowKey) {
  // Need to subtract the SALT_BYTES as the row key distributor will prefix the key with salted bytes
  byte[] result = new byte[PREFIX_BYTES - SaltedHBaseQueueStrategy.SALT_BYTES + originalRowKey.length];
  Bytes.putBytes(result, PREFIX_BYTES - SaltedHBaseQueueStrategy.SALT_BYTES,
          originalRowKey, 0, originalRowKey.length);
  Bytes.putLong(result, 0, groupConfig.getGroupId());

  // Default for FIFO case.
  int shardId = groupConfig.getDequeueStrategy() == DequeueStrategy.FIFO ? -1 : instanceId;
  Bytes.putInt(result, Bytes.SIZEOF_LONG, shardId);

  return result;
 }
}

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

private byte[] encodeStateColumn(ConsumerEntryState state) {
 // State column content is encoded as (writePointer) + (instanceId) + (state)
 byte[] stateContent = new byte[Longs.BYTES + Ints.BYTES + 1];
 Bytes.putLong(stateContent, 0, transaction.getWritePointer());
 Bytes.putInt(stateContent, Longs.BYTES, getConfig().getInstanceId());
 Bytes.putByte(stateContent, Longs.BYTES + Ints.BYTES, state.getState());
 return stateContent;
}

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

/**
 * Encodes the value for the state column with the current transaction and consumer information.
 *
 * @param state The state to encode
 * @return The stateContent byte array
 */
// TODO: This method is copied from AbstractQueue2Consumer. Future effort is needed to unify them.
private byte[] encodeStateColumn(ConsumerEntryState state) {
 byte[] stateContent = new byte[Longs.BYTES + Ints.BYTES + 1];
 // State column content is encoded as (writePointer) + (instanceId) + (state)
 Bytes.putLong(stateContent, 0, transaction.getWritePointer());
 Bytes.putInt(stateContent, Longs.BYTES, consumerConfig.getInstanceId());
 Bytes.putByte(stateContent, Longs.BYTES + Ints.BYTES, state.getState());
 return stateContent;
}

相关文章