当前位置: 首页>>代码示例>>Java>>正文


Java Output类代码示例

本文整理汇总了Java中com.google.protobuf.ByteString.Output的典型用法代码示例。如果您正苦于以下问题:Java Output类的具体用法?Java Output怎么用?Java Output使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Output类属于com.google.protobuf.ByteString包,在下文中一共展示了Output类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeMessageList

import com.google.protobuf.ByteString.Output; //导入依赖的package包/类
/**
 * Creates a {@link ByteString} by serializing the list of protos. Use
 * {@link #readMessageList(ByteString, Parser)} to deserialize.
 */
public static <T extends MessageLite> ByteString writeMessageList(List<T> protos) {
    Output output = ByteString.newOutput();
    try {
        writeMessageListTo(output, protos);
    } catch (IOException ex) {
        throw new IllegalStateException("Unable to write protobufs to memory");
    }

    return output.toByteString();
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:15,代码来源:ProtoListUtil.java

示例2: testNewOutput_ArrayWrite

import com.google.protobuf.ByteString.Output; //导入依赖的package包/类
public void testNewOutput_ArrayWrite() throws IOException {
  byte[] bytes = getTestBytes();
  int length = bytes.length;
  int[] bufferSizes = {128, 256, length / 2, length - 1, length, length + 1,
                       2 * length, 3 * length};
  int[] writeSizes = {1, 4, 5, 7, 23, bytes.length};

  for (int bufferSize : bufferSizes) {
    for (int writeSize : writeSizes) {
      // Test writing the entire output writeSize bytes at a time.
      ByteString.Output output = ByteString.newOutput(bufferSize);
      for (int i = 0; i < length; i += writeSize) {
        output.write(bytes, i, Math.min(writeSize, length - i));
      }
      ByteString byteString = output.toByteString();
      assertTrue("String built from newOutput() must contain the expected bytes",
          isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
    }
  }
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:21,代码来源:ByteStringTest.java

示例3: testNewOutput_WriteChar

import com.google.protobuf.ByteString.Output; //导入依赖的package包/类
public void testNewOutput_WriteChar() throws IOException {
  byte[] bytes = getTestBytes();
  int length = bytes.length;
  int[] bufferSizes = {0, 1, 128, 256, length / 2,
                       length - 1, length, length + 1,
                       2 * length, 3 * length};
  for (int bufferSize : bufferSizes) {
    ByteString.Output output = ByteString.newOutput(bufferSize);
    for (byte byteValue : bytes) {
      output.write(byteValue);
    }
    ByteString byteString = output.toByteString();
    assertTrue("String built from newOutput() must contain the expected bytes",
        isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
  }
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:17,代码来源:ByteStringTest.java

示例4: testNewOutput_Mutating

import com.google.protobuf.ByteString.Output; //导入依赖的package包/类
public void testNewOutput_Mutating() throws IOException {
  Output os = ByteString.newOutput(5);
  os.write(new byte[] {1, 2, 3, 4, 5});
  EvilOutputStream eos = new EvilOutputStream();
  os.writeTo(eos);
  byte[] capturedArray = eos.capturedArray;
  ByteString byteString = os.toByteString();
  byte[] oldValue = byteString.toByteArray();
  Arrays.fill(capturedArray, (byte) 0);
  byte[] newValue = byteString.toByteArray();
  assertTrue("Output must not provide access to the underlying byte array",
      Arrays.equals(oldValue, newValue));
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:14,代码来源:ByteStringTest.java

示例5: testNewOutput_ArrayWrite

import com.google.protobuf.ByteString.Output; //导入依赖的package包/类
public void testNewOutput_ArrayWrite() {
  byte[] bytes = getTestBytes();
  int length = bytes.length;
  int[] bufferSizes = {128, 256, length / 2, length - 1, length, length + 1,
                       2 * length, 3 * length};
  int[] writeSizes = {1, 4, 5, 7, 23, bytes.length};

  for (int bufferSize : bufferSizes) {
    for (int writeSize : writeSizes) {
      // Test writing the entire output writeSize bytes at a time.
      ByteString.Output output = ByteString.newOutput(bufferSize);
      for (int i = 0; i < length; i += writeSize) {
        output.write(bytes, i, Math.min(writeSize, length - i));
      }
      ByteString byteString = output.toByteString();
      assertTrue("String built from newOutput() must contain the expected bytes",
          isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
    }
  }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:21,代码来源:ByteStringTest.java

示例6: testNewOutput_WriteChar

import com.google.protobuf.ByteString.Output; //导入依赖的package包/类
public void testNewOutput_WriteChar() {
  byte[] bytes = getTestBytes();
  int length = bytes.length;
  int[] bufferSizes = {0, 1, 128, 256, length / 2,
                       length - 1, length, length + 1,
                       2 * length, 3 * length};
  for (int bufferSize : bufferSizes) {
    ByteString.Output output = ByteString.newOutput(bufferSize);
    for (byte byteValue : bytes) {
      output.write(byteValue);
    }
    ByteString byteString = output.toByteString();
    assertTrue("String built from newOutput() must contain the expected bytes",
        isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
  }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:17,代码来源:ByteStringTest.java

示例7: testNewOutput_InitialCapacity

import com.google.protobuf.ByteString.Output; //导入依赖的package包/类
public void testNewOutput_InitialCapacity() throws IOException {
  byte[] bytes = getTestBytes();
  ByteString.Output output = ByteString.newOutput(bytes.length + 100);
  output.write(bytes);
  ByteString byteString = output.toByteString();
  assertTrue(
      "String built from newOutput(int) must contain the expected bytes",
      isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:10,代码来源:ByteStringTest.java

示例8: testNewOutput_Mixed

import com.google.protobuf.ByteString.Output; //导入依赖的package包/类
public void testNewOutput_Mixed() throws IOException {
  Random rng = new Random(1);
  byte[] bytes = getTestBytes();
  int length = bytes.length;
  int[] bufferSizes = {0, 1, 128, 256, length / 2,
                       length - 1, length, length + 1,
                       2 * length, 3 * length};

  for (int bufferSize : bufferSizes) {
    // Test writing the entire output using a mixture of write sizes and
    // methods;
    ByteString.Output output = ByteString.newOutput(bufferSize);
    int position = 0;
    while (position < bytes.length) {
      if (rng.nextBoolean()) {
        int count = 1 + rng.nextInt(bytes.length - position);
        output.write(bytes, position, count);
        position += count;
      } else {
        output.write(bytes[position]);
        position++;
      }
      assertEquals("size() returns the right value", position, output.size());
      assertTrue("newOutput() substring must have correct bytes",
          isArrayRange(output.toByteString().toByteArray(),
              bytes, 0, position));
    }
    ByteString byteString = output.toByteString();
    assertTrue("String built from newOutput() must contain the expected bytes",
        isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
  }
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:33,代码来源:ByteStringTest.java

示例9: testNewOutput_Mixed

import com.google.protobuf.ByteString.Output; //导入依赖的package包/类
public void testNewOutput_Mixed() {
  Random rng = new Random(1);
  byte[] bytes = getTestBytes();
  int length = bytes.length;
  int[] bufferSizes = {0, 1, 128, 256, length / 2,
                       length - 1, length, length + 1,
                       2 * length, 3 * length};

  for (int bufferSize : bufferSizes) {
    // Test writing the entire output using a mixture of write sizes and
    // methods;
    ByteString.Output output = ByteString.newOutput(bufferSize);
    int position = 0;
    while (position < bytes.length) {
      if (rng.nextBoolean()) {
        int count = 1 + rng.nextInt(bytes.length - position);
        output.write(bytes, position, count);
        position += count;
      } else {
        output.write(bytes[position]);
        position++;
      }
      assertEquals("size() returns the right value", position, output.size());
      assertTrue("newOutput() substring must have correct bytes",
          isArrayRange(output.toByteString().toByteArray(),
              bytes, 0, position));
    }
    ByteString byteString = output.toByteString();
    assertTrue("String built from newOutput() must contain the expected bytes",
        isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
  }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:33,代码来源:ByteStringTest.java

示例10: convertCredentialsToProto

import com.google.protobuf.ByteString.Output; //导入依赖的package包/类
public static ByteString convertCredentialsToProto(Credentials credentials) {
  if (credentials == null) {
    return null;
  }
  Output output = ByteString.newOutput();
  DataOutputStream dos = new DataOutputStream(output);
  try {
    credentials.writeTokenStorageToStream(dos);
    return output.toByteString();
  } catch (IOException e) {
    throw new TezUncheckedException("Failed to serialize Credentials", e);
  }
}
 
开发者ID:apache,项目名称:incubator-tez,代码行数:14,代码来源:DagTypeConverters.java

示例11: buildHashKey

import com.google.protobuf.ByteString.Output; //导入依赖的package包/类
public AttributeValue buildHashKey(T item) {
  boolean empty = true;

  Message.Builder key = newBuilder();
  for (AttributeMapping hashKeyField : hashKeyFields) {
    if (item.hasField(hashKeyField.field)) {
      Object value = item.getField(hashKeyField.field);
      key.setField(hashKeyField.field, value);
      empty = false;
    }
  }

  if (empty) {
    return null;
  }

  try {
    Output output = ByteString.newOutput();

    output.write(Ints.toByteArray(typeMetadata.getId()));
    key.buildPartial().writeTo(output);

    return toAttributeValue(output.toByteString());
  } catch (IOException e) {
    throw new IllegalArgumentException("Error building hash key", e);
  }
}
 
开发者ID:justinsb,项目名称:cloudata,代码行数:28,代码来源:DynamodbDataStore.java

示例12: buildRangeKey

import com.google.protobuf.ByteString.Output; //导入依赖的package包/类
public RangeSpecifier buildRangeKey(T item) {
  try {
    boolean empty = true;
    boolean complete = true;

    Output output = ByteString.newOutput();

    Message.Builder key = newBuilder();
    for (AttributeMapping rangeKeyField : rangeKeyFields) {
      if (item.hasField(rangeKeyField.field)) {
        Object value = item.getField(rangeKeyField.field);
        key.setField(rangeKeyField.field, value);
        empty = false;
      } else {
        complete = false;
        break;
      }
    }

    if (empty) {
      return null;
    } else {
      key.buildPartial().writeTo(output);
      RangeSpecifier specifier = new RangeSpecifier();
      if (complete) {
        specifier.exact = toAttributeValue(output.toByteString());
      } else {
        specifier.prefix = toAttributeValue(output.toByteString());
      }
      return specifier;
    }
  } catch (IOException e) {
    throw new IllegalArgumentException("Error building range key", e);
  }
}
 
开发者ID:justinsb,项目名称:cloudata,代码行数:36,代码来源:DynamodbDataStore.java


注:本文中的com.google.protobuf.ByteString.Output类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。