com.google.common.primitives.Bytes.concat()方法的使用及代码示例

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

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

Bytes.concat介绍

[英]Returns the values from each provided array combined into a single array. For example, concat(new byte[] {a, b}, new byte[] {}, new byte[] {c}} returns the array {a, b, c}}.
[中]返回组合到单个数组中的每个提供数组的值。例如,concat(新字节[]{a,b},新字节[]{},新字节[]{c}}返回数组{a,b,c}。

代码示例

代码示例来源:origin: apache/incubator-shardingsphere

/**
   * Get auth plugin data.
   * 
   * @return auth plugin data
   */
  public byte[] getAuthPluginData() {
    return Bytes.concat(authPluginDataPart1, authPluginDataPart2);
  }
}

代码示例来源:origin: apache/incubator-shardingsphere

/**
   * Get auth plugin data.
   * 
   * @return auth plugin data
   */
  public byte[] getAuthPluginData() {
    return Bytes.concat(authPluginDataPart1, authPluginDataPart2);
  }
}

代码示例来源:origin: apache/incubator-druid

@Override
public byte[] getCacheKey()
{
 byte[] cacheKey = new byte[]{ExtractionCacheHelper.CACHE_TYPE_ID_CASCADE};
 return Bytes.concat(cacheKey, chainedExtractionFn.getCacheKey());
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

public String buildCacheKey() {
 return UUID.nameUUIDFromBytes(
   Bytes.concat(kind.getBytes(), identifier, password)).toString();
}

代码示例来源:origin: MovingBlocks/Terasology

/**
 * Generates a symmetric encryption key from the master secret
 *
 * @param masterSecret
 * @param clientRandom
 * @param serverRandom
 * @return
 */
public static SecretKeySpec generateSymmetricKey(byte[] masterSecret, byte[] clientRandom, byte[] serverRandom) {
  return new SecretKeySpec(SecretGenerator.generate(masterSecret, SecretGenerator.KEY_EXPANSION,
      Bytes.concat(clientRandom, serverRandom), IdentityConstants.SYMMETRIC_ENCRYPTION_KEY_LENGTH), IdentityConstants.SYMMETRIC_ENCRYPTION_ALGORITHM);
}

代码示例来源:origin: MovingBlocks/Terasology

/**
 * Generates the master secret, a common secret between the server and client used to generate a symmetric encryption key
 *
 * @param preMasterSecret
 * @param clientRandom
 * @param serverRandom
 * @return
 */
public static byte[] generateMasterSecret(byte[] preMasterSecret, byte[] clientRandom, byte[] serverRandom) {
  return SecretGenerator.generate(preMasterSecret, SecretGenerator.MASTER_SECRET_LABEL, Bytes.concat(clientRandom, serverRandom), SecretGenerator.MASTER_SECRET_LENGTH);
}

代码示例来源:origin: apache/incubator-druid

public byte[] getCacheKey()
{
 byte[] fnCacheKey = fn.getCacheKey();
 return (child != null) ? Bytes.concat(fnCacheKey, child.getCacheKey()) : fnCacheKey;
}

代码示例来源:origin: google/guava

public void testConcat() {
 assertTrue(Arrays.equals(EMPTY, Bytes.concat()));
 assertTrue(Arrays.equals(EMPTY, Bytes.concat(EMPTY)));
 assertTrue(Arrays.equals(EMPTY, Bytes.concat(EMPTY, EMPTY, EMPTY)));
 assertTrue(Arrays.equals(ARRAY1, Bytes.concat(ARRAY1)));
 assertNotSame(ARRAY1, Bytes.concat(ARRAY1));
 assertTrue(Arrays.equals(ARRAY1, Bytes.concat(EMPTY, ARRAY1, EMPTY)));
 assertTrue(
   Arrays.equals(
     new byte[] {(byte) 1, (byte) 1, (byte) 1}, Bytes.concat(ARRAY1, ARRAY1, ARRAY1)));
 assertTrue(
   Arrays.equals(
     new byte[] {(byte) 1, (byte) 2, (byte) 3, (byte) 4}, Bytes.concat(ARRAY1, ARRAY234)));
}

代码示例来源:origin: prontera/spring-cloud-rest-tcc

/**
 * Get request body.
 *
 * @return Bytes with the request body contents.
 * @throws IOException In case stream reqding fails.
 */
public byte[] getRequestBody() throws IOException {
  final byte[] resultBytes;
  if (bufferFilled) {
    // 已经填入则直接返回
    resultBytes = Arrays.copyOf(requestBody, requestBody.length);
  } else {
    // 未填入则进行处理
    InputStream inputStream = super.getInputStream();
    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = inputStream.read(buffer)) != -1) {
      requestBody = Bytes.concat(this.requestBody, Arrays.copyOfRange(buffer, 0, bytesRead));
    }
    // 置标志位
    bufferFilled = true;
    resultBytes = Arrays.copyOf(requestBody, requestBody.length);
  }
  return resultBytes;
}

代码示例来源:origin: MovingBlocks/Terasology

/**
   * Create a set of data to sign to bu
   *
   * @param serverHello
   * @param clientHello
   * @return
   */
  public static byte[] getSignatureData(NetData.HandshakeHello serverHello, NetData.HandshakeHello clientHello) {
    return Bytes.concat(serverHello.toByteArray(), clientHello.toByteArray());
  }
}

代码示例来源:origin: MovingBlocks/Terasology

/**
 * Generates a client hello from clientRandom file, time, and the public client certificate. Sends the clients hello and certificate back to the server via network channel.
 * @param helloMessage Message from server to client.
 * @param ctx Channel Handler Context.
 */
private void sendCertificate(NetData.HandshakeHello helloMessage, ChannelHandlerContext ctx) {
  logger.info("Sending client certificate");
  PublicIdentityCertificate pubClientCert = identity.getPlayerPublicCertificate();
  clientHello = NetData.HandshakeHello.newBuilder()
      .setRandom(ByteString.copyFrom(clientRandom))
      .setCertificate(NetMessageUtil.convert(pubClientCert))
      .setTimestamp(System.currentTimeMillis())
      .build();
  byte[] dataToSign = Bytes.concat(helloMessage.toByteArray(), clientHello.toByteArray());
  byte[] signature = identity.getPlayerPrivateCertificate().sign(dataToSign);
  ctx.getChannel().write(NetData.NetMessage.newBuilder()
      .setHandshakeHello(clientHello)
      .setHandshakeVerification(NetData.HandshakeVerification.newBuilder()
          .setSignature(ByteString.copyFrom(signature)))
      .build());
}

代码示例来源:origin: runelite/runelite

break;
case CompressionType.BZ2:
  compressedData = concat(Ints.toByteArray(data.length), BZip2.compress(data));
  length = compressedData.length - 4;
  break;
case CompressionType.GZ:
  compressedData = concat(Ints.toByteArray(data.length), GZip.compress(data));
  length = compressedData.length - 4;
  break;

代码示例来源:origin: palantir/atlasdb

public static byte[] add(byte[] b1, byte[] b2, byte[] b3) {
  return Bytes.concat(b1, b2, b3);
}

代码示例来源:origin: line/armeria

@Test
public void grpcWeb() throws Exception {
  final HttpClient client = HttpClient.of(server.httpUri("/"));
  final AggregatedHttpMessage response = client.execute(
      HttpHeaders.of(HttpMethod.POST,
              UnitTestServiceGrpc.getStaticUnaryCallMethod().getFullMethodName())
            .set(HttpHeaderNames.CONTENT_TYPE, "application/grpc-web"),
      GrpcTestUtil.uncompressedFrame(GrpcTestUtil.requestByteBuf())).aggregate().get();
  final byte[] serializedStatusHeader = "grpc-status: 0\r\n".getBytes(StandardCharsets.US_ASCII);
  final byte[] serializedTrailers = Bytes.concat(
      new byte[] { ArmeriaServerCall.TRAILERS_FRAME_HEADER },
      Ints.toByteArray(serializedStatusHeader.length),
      serializedStatusHeader);
  assertThat(response.content().array()).containsExactly(
      Bytes.concat(
          GrpcTestUtil.uncompressedFrame(
              GrpcTestUtil.protoByteBuf(RESPONSE_MESSAGE)),
          serializedTrailers));
  checkRequestLog((rpcReq, rpcRes, grpcStatus) -> {
    assertThat(rpcReq.method()).isEqualTo("armeria.grpc.testing.UnitTestService/StaticUnaryCall");
    assertThat(rpcReq.params()).containsExactly(REQUEST_MESSAGE);
    assertThat(rpcRes.get()).isEqualTo(RESPONSE_MESSAGE);
  });
}

代码示例来源:origin: palantir/atlasdb

@Override
public List<byte[]> getPartitions(int numberRanges) {
  List<byte[]> ret = Lists.newArrayList();
  for (byte[] bs : nextPartition.getPartitions(numberRanges)) {
    ret.add(Bytes.concat(prefix, bs));
  }
  return ret;
}

代码示例来源:origin: palantir/atlasdb

public static byte[] encodeSizedBytes(byte[] bytes) {
  byte[] len = encodeVarLong(bytes.length);
  return Bytes.concat(len, bytes);
}

代码示例来源:origin: palantir/atlasdb

public static byte[] encodeVarLongAndFixedLong(long realmId, long v2) {
  byte[] b1 = encodeVarLong(realmId);
  byte[] b2 = PtBytes.toBytes(v2);
  return Bytes.concat(b1, b2);
}

代码示例来源:origin: palantir/atlasdb

public static final byte[] getBytesForTableRef(TableReference tableRef) {
  byte[] nameSpace = EncodingUtils.encodeVarString(tableRef.getNamespace().getName());
  byte[] table = PtBytes.toBytes(tableRef.getTablename());
  return Bytes.concat(nameSpace, table);
}

代码示例来源:origin: palantir/atlasdb

@Test
  public void testDeserializeRowFromJsonMap() throws Exception {
    JsonNode jsonNode = new ObjectMapper().readTree("{\"age\":68, \"name\":\"Smeagol\"}");
    byte[] row = AtlasDeserializers.deserializeRow(NAME_METADATA_DESCRIPTION, jsonNode);
    byte[] expectedRow = Bytes.concat(ValueType.FIXED_LONG.convertFromString("68"),
                     ValueType.STRING.convertFromString("Smeagol"));
    Assert.assertArrayEquals(expectedRow, row);
  }
}

代码示例来源:origin: palantir/atlasdb

@Test
public void testDeserializeRowFromJsonList() throws Exception {
  JsonNode jsonNode = new ObjectMapper().readTree("[68, \"Smeagol\"]");
  byte[] row = AtlasDeserializers.deserializeRow(NAME_METADATA_DESCRIPTION, jsonNode);
  byte[] expectedRow = Bytes.concat(ValueType.FIXED_LONG.convertFromString("68"),
                   ValueType.STRING.convertFromString("Smeagol"));
  Assert.assertArrayEquals(expectedRow, row);
}

相关文章