本文整理了Java中com.google.protobuf.ByteString.newOutput()
方法的一些代码示例,展示了ByteString.newOutput()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteString.newOutput()
方法的具体详情如下:
包路径:com.google.protobuf.ByteString
类名称:ByteString
方法名:newOutput
[英]Creates a new Output. Call Output#toByteString() to create the ByteString instance.
A ByteString.Output offers the same functionality as a ByteArrayOutputStream, except that it returns a ByteStringrather than a byte array.
[中]创建新的输出。调用Output#toByteString()创建ByteString实例。
旁听环。输出提供与ByteArrayOutputStream相同的功能,只是它返回ByTestRing而不是字节数组。
代码示例来源:origin: MovingBlocks/Terasology
private EntityData.PackedEntity.Builder serializeEntityFull(EntityRef entityRef, FieldSerializeCheck<Component> fieldCheck) {
EntityData.PackedEntity.Builder entity = EntityData.PackedEntity.newBuilder();
ByteString.Output fieldIds = ByteString.newOutput();
ByteString.Output componentFieldCounts = ByteString.newOutput();
for (Component component : entityRef.iterateComponents()) {
if (!componentSerializeCheck.serialize(componentLibrary.getMetadata(component.getClass()))) {
continue;
}
serializeComponentFull(component, false, fieldCheck, entity, fieldIds, componentFieldCounts, true);
}
entity.setFieldIds(fieldIds.toByteString());
entity.setComponentFieldCounts(componentFieldCounts.toByteString());
return entity;
}
代码示例来源:origin: MovingBlocks/Terasology
private EntityData.PackedEntity.Builder serializeEntityDelta(EntityRef entityRef, Prefab prefab, FieldSerializeCheck<Component> fieldCheck) {
EntityData.PackedEntity.Builder entity = EntityData.PackedEntity.newBuilder();
entity.setParentPrefabUri(prefab.getName());
Set<Class<? extends Component>> presentClasses = Sets.newHashSet();
ByteString.Output fieldIds = ByteString.newOutput();
ByteString.Output componentFieldCounts = ByteString.newOutput();
for (Component component : entityRef.iterateComponents()) {
if (!componentSerializeCheck.serialize(componentLibrary.getMetadata(component.getClass()))) {
continue;
}
presentClasses.add(component.getClass());
Component prefabComponent = prefab.getComponent(component.getClass());
if (prefabComponent == null) {
serializeComponentFull(component, false, fieldCheck, entity, fieldIds, componentFieldCounts, true);
} else {
serializeComponentDelta(prefabComponent, component, fieldCheck, entity, fieldIds, componentFieldCounts, true);
}
}
entity.setFieldIds(fieldIds.toByteString());
entity.setComponentFieldCounts(componentFieldCounts.toByteString());
for (Component prefabComponent : prefab.iterateComponents()) {
if (!presentClasses.contains(prefabComponent.getClass()) && componentSerializeCheck.serialize(componentLibrary.getMetadata(prefabComponent.getClass()))) {
entity.addRemovedComponent(idTable.get(prefabComponent.getClass()));
}
}
return entity;
}
代码示例来源:origin: googleapis/google-cloud-java
/** Converts the value to a quoted regular expression. */
public static ByteString literalRegex(ByteString value) {
ByteString.Output output = ByteString.newOutput(value.size() * 2);
ByteIterator it = value.iterator();
writeLiteralRegex(it, output);
return output.toByteString();
}
代码示例来源:origin: apache/hive
private void checkSignature(SignableVertexSpec vertex, ByteString vertexBinary,
SubmitWorkRequestProto request, String tokenUserName) throws SecurityException, IOException {
if (!request.hasWorkSpecSignature()) {
logSecurityErrorRarely(tokenUserName);
throw new SecurityException("Unsigned fragment not allowed");
}
if (vertexBinary == null) {
ByteString.Output os = ByteString.newOutput();
vertex.writeTo(os);
vertexBinary = os.toByteString();
}
try {
signer.checkSignature(vertexBinary.toByteArray(),
request.getWorkSpecSignature().toByteArray(), (int)vertex.getSignatureKeyId());
} catch (SecurityException ex) {
logSecurityErrorRarely(tokenUserName);
throw ex;
}
if (!vertex.hasUser() || !vertex.getUser().equals(tokenUserName)) {
logSecurityErrorRarely(tokenUserName);
throw new SecurityException("LLAP token is for " + tokenUserName
+ " but the fragment is for " + (vertex.hasUser() ? vertex.getUser() : null));
}
}
代码示例来源:origin: MovingBlocks/Terasology
EntityData.PackedEntity.Builder entity = EntityData.PackedEntity.newBuilder();
ByteString.Output fieldIds = ByteString.newOutput();
ByteString.Output componentFieldCounts = ByteString.newOutput();
for (Class<? extends Component> componentType : added) {
Component component = entityRef.getComponent(componentType);
代码示例来源:origin: MovingBlocks/Terasology
private void serializeEventInfo(NetData.ServerInfoMessage.Builder serverInfoMessageBuilder) {
Map<Class<? extends Event>, Integer> eventIdTable = eventSerializer.getIdMapping();
for (Map.Entry<Class<? extends Event>, Integer> eventMapping : eventIdTable.entrySet()) {
ByteString.Output fieldIds = ByteString.newOutput();
EventMetadata<?> metadata = eventLibrary.getMetadata(eventMapping.getKey());
NetData.SerializationInfo.Builder info = NetData.SerializationInfo.newBuilder()
.setId(eventMapping.getValue())
.setName(metadata.getUri().toString());
for (FieldMetadata<?, ?> field : metadata.getFields()) {
fieldIds.write(field.getId());
info.addFieldName(field.getName());
}
info.setFieldIds(fieldIds.toByteString());
serverInfoMessageBuilder.addEvent(info);
}
}
代码示例来源:origin: MovingBlocks/Terasology
private void serializeComponentInfo(NetData.ServerInfoMessage.Builder serverInfoMessageBuilder) {
Map<Class<? extends Component>, Integer> componentIdTable = entitySerializer.getIdMapping();
for (Map.Entry<Class<? extends Component>, Integer> componentIdMapping : componentIdTable.entrySet()) {
ByteString.Output fieldIds = ByteString.newOutput();
ComponentMetadata<?> metadata = componentLibrary.getMetadata(componentIdMapping.getKey());
NetData.SerializationInfo.Builder info = NetData.SerializationInfo.newBuilder()
.setId(componentIdMapping.getValue())
.setName(metadata.getUri().toString());
for (FieldMetadata<?, ?> field : metadata.getFields()) {
fieldIds.write(field.getId());
info.addFieldName(field.getName());
}
info.setFieldIds(fieldIds.toByteString());
serverInfoMessageBuilder.addComponent(info);
}
}
代码示例来源:origin: MovingBlocks/Terasology
/**
* Serializes an event.
*
* @param event
* @return The serialized event
* @throws org.terasology.persistence.typeHandling.SerializationException if an error occurs during serialization
*/
public EntityData.Event serialize(Event event) {
EventMetadata<?> eventMetadata = eventLibrary.getMetadata(event.getClass());
if (eventMetadata == null) {
throw new SerializationException("Unregistered event type: " + event.getClass());
} else if (!eventMetadata.isConstructable()) {
throw new SerializationException("Cannot serialize event '" + eventMetadata + "' - lacks default constructor so cannot be deserialized");
}
EntityData.Event.Builder eventData = EntityData.Event.newBuilder();
serializeEventType(event, eventData);
Serializer eventSerializer = typeSerializationLibrary.getSerializerFor(eventMetadata);
ByteString.Output fieldIds = ByteString.newOutput();
for (ReplicatedFieldMetadata field : eventMetadata.getFields()) {
if (field.isReplicated()) {
EntityData.Value serializedValue = ((ProtobufPersistedData) eventSerializer.serialize(field, event, serializationContext)).getValue();
if (serializedValue != null) {
eventData.addFieldValue(serializedValue);
fieldIds.write(field.getId());
}
}
}
eventData.setFieldIds(fieldIds.toByteString());
return eventData.build();
}
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
Builder(int maxDataLength) {
out = ByteString.newOutput(64*1024);
cos = CodedOutputStream.newInstance(out);
this.maxDataLength = maxDataLength;
}
代码示例来源:origin: com.google.cloud.bigtable/bigtable-hbase
/**
* <p>quoteRegularExpression.</p>
*
* @param unquoted an array of byte.
* @return an array of byte.
* @throws java.io.IOException if any.
*/
public static ByteString quoteRegularExpression(byte[] unquoted) throws IOException {
ByteString.Output output = ByteString.newOutput(unquoted.length * 2);
writeQuotedRegularExpression(output, unquoted);
return output.toByteString();
}
代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client
private void addPartialCellChunk(ReadRowsResponse.CellChunk chunk) throws IOException {
if (outputStream == null) {
outputStream = ByteString.newOutput();
}
chunk.getValue().writeTo(outputStream);
}
代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client
/**
* <p>quoteRegularExpression.</p>
*
* @param unquoted an array of byte.
* @return an array of byte.
* @throws java.io.IOException if any.
*/
public static ByteString quoteRegularExpression(byte[] unquoted) throws IOException {
ByteString.Output output = ByteString.newOutput(unquoted.length * 2);
writeQuotedRegularExpression(output, unquoted);
return output.toByteString();
}
代码示例来源:origin: org.apache.tez/tez-api
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);
}
}
代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client
/** Converts the value to a quoted regular expression. */
public static ByteString literalRegex(ByteString value) {
Output output = ByteString.newOutput(value.size() * 2);
ByteIterator it = value.iterator();
try {
writeLiteralRegex(it, output);
} catch (IOException e) {
throw new RuntimeException("Unexpected io error converting regex", e);
}
return output.toByteString();
}
代码示例来源:origin: com.google.cloud/google-cloud-bigtable
/** Converts the value to a quoted regular expression. */
public static ByteString literalRegex(ByteString value) {
ByteString.Output output = ByteString.newOutput(value.size() * 2);
ByteIterator it = value.iterator();
writeLiteralRegex(it, output);
return output.toByteString();
}
代码示例来源:origin: org.apache.tez/tez-mapreduce
@InterfaceStability.Evolving
@InterfaceAudience.LimitedPrivate({"hive, pig"})
public static MRRuntimeProtos.MRSplitProto createSplitProto(
org.apache.hadoop.mapred.InputSplit oldSplit) throws IOException {
MRRuntimeProtos.MRSplitProto.Builder builder = MRRuntimeProtos.MRSplitProto.newBuilder();
builder.setSplitClassName(oldSplit.getClass().getName());
ByteString.Output os = ByteString
.newOutput(SPLIT_SERIALIZED_LENGTH_ESTIMATE);
oldSplit.write(new NonSyncDataOutputStream(os));
ByteString splitBs = os.toByteString();
builder.setSplitBytes(splitBs);
return builder.build();
}
代码示例来源:origin: com.google.cloud.bigtable/bigtable-hbase
/**
* {@inheritDoc}
*/
@Override
public Filter adapt(FilterAdapterContext context, PrefixFilter filter)
throws IOException {
ByteString.Output output = ByteString.newOutput(filter.getPrefix().length * 2);
ReaderExpressionHelper.writeQuotedRegularExpression(output, filter.getPrefix());
// Unquoted all bytes:
output.write(ReaderExpressionHelper.ALL_QUALIFIERS_BYTES);
return FILTERS.key().regex(output.toByteString());
}
代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client
/**
* {@inheritDoc}
*/
@Override
public Filter adapt(FilterAdapterContext context, PrefixFilter filter)
throws IOException {
ByteString.Output output = ByteString.newOutput(filter.getPrefix().length * 2);
ReaderExpressionHelper.writeQuotedRegularExpression(output, filter.getPrefix());
// Unquoted all bytes:
output.write(ReaderExpressionHelper.ALL_QUALIFIERS_BYTES);
return FILTERS.key().regex(output.toByteString());
}
代码示例来源:origin: com.google.cloud.bigtable/bigtable-hbase
/** {@inheritDoc} */
@Override
public Filter adapt(FilterAdapterContext context, ColumnPrefixFilter filter)
throws IOException {
byte[] prefix = filter.getPrefix();
// Quoting for RE2 can result in at most length * 2 characters written. Pre-allocate
// that much space in the ByteString.Output to prevent reallocation later.
ByteString.Output outputStream = ByteString.newOutput(prefix.length * 2);
ReaderExpressionHelper.writeQuotedExpression(outputStream, prefix);
outputStream.write(ReaderExpressionHelper.ALL_QUALIFIERS_BYTES);
Filter qualifierFilter = FILTERS.qualifier().regex(outputStream.toByteString());
return FILTERS.chain().filter(qualifierFilter);
}
代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client
/** {@inheritDoc} */
@Override
public Filter adapt(FilterAdapterContext context, ColumnPrefixFilter filter)
throws IOException {
byte[] prefix = filter.getPrefix();
// Quoting for RE2 can result in at most length * 2 characters written. Pre-allocate
// that much space in the ByteString.Output to prevent reallocation later.
ByteString.Output outputStream = ByteString.newOutput(prefix.length * 2);
ReaderExpressionHelper.writeQuotedExpression(outputStream, prefix);
outputStream.write(ReaderExpressionHelper.ALL_QUALIFIERS_BYTES);
Filter qualifierFilter = FILTERS.qualifier().regex(outputStream.toByteString());
return FILTERS.chain().filter(qualifierFilter);
}
内容来源于网络,如有侵权,请联系作者删除!