本文整理汇总了Java中com.google.protobuf.ByteString.Output.toByteString方法的典型用法代码示例。如果您正苦于以下问题:Java Output.toByteString方法的具体用法?Java Output.toByteString怎么用?Java Output.toByteString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.ByteString.Output
的用法示例。
在下文中一共展示了Output.toByteString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例2: 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));
}
示例3: 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);
}
}