com.google.protobuf.ByteString#newOutput ( )源码实例Demo

下面列出了com.google.protobuf.ByteString#newOutput ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: kogito-runtimes   文件: PersisterHelper.java
private static void writeStrategiesIndex(MarshallerWriteContext context,
                                          ProtobufMessages.Header.Builder _header) throws IOException {
     for( Entry<ObjectMarshallingStrategy,Integer> entry : context.usedStrategies.entrySet() ) {
Builder _strat = ProtobufMessages.Header.StrategyIndex.newBuilder()
                                  .setId( entry.getValue().intValue() )
                                  .setName( entry.getKey().getName()  );

         Context ctx = context.strategyContext.get( entry.getKey() );
         if( ctx != null ) {
             Output os = ByteString.newOutput();
             ctx.write( new DroolsObjectOutputStream( os ) );
             _strat.setData( os.toByteString() );
             os.close();
         }
         _header.addStrategy( _strat.build() );
     }
 }
 
源代码2 项目: bazel   文件: GenQueryOutputStream.java
private void maybeStartCompression(int additionalBytes) throws IOException {
  if (!compressionEnabled) {
    return;
  }

  if (compressed) {
    return;
  }

  if (bytesWritten + additionalBytes < COMPRESSION_THRESHOLD) {
    return;
  }

  ByteString.Output compressedBytesOut = ByteString.newOutput();
  GZIPOutputStream gzipOut = new GZIPOutputStream(compressedBytesOut);
  bytesOut.writeTo(gzipOut);
  bytesOut = compressedBytesOut;
  out = gzipOut;
  compressed = true;
}
 
源代码3 项目: jelectrum   文件: RocksDBMapMutationSet.java
private ByteString getDBKey(ByteString key)
{
  try
  {
    ByteString.Output out = ByteString.newOutput(100);
    out.write(name_bytes);
    out.write(key.toByteArray());
    out.write(sep);
    ByteString w = out.toByteString();
    return w;
  }
  catch(java.io.IOException e)
  {
    throw new RuntimeException(e);
  }
}
 
源代码4 项目: jelectrum   文件: SimpleUtxoMgr.java
public static ByteString getKey(ByteString scriptHash, Sha256Hash tx_id, int idx)
{
  try
  {
    ByteString.Output key_out = ByteString.newOutput(32+32+4);

    key_out.write(scriptHash.toByteArray());
    key_out.write(tx_id.getBytes());

    ByteBuffer bb = ByteBuffer.allocate(4);
    bb.order(java.nio.ByteOrder.LITTLE_ENDIAN);
    bb.putInt(idx);
    key_out.write(bb.array());
    return key_out.toByteString();
  }
  catch(java.io.IOException e)
  {
    throw new RuntimeException(e);
  }

}
 
源代码5 项目: dremio-oss   文件: ProtobufByteStringSerDe.java
/**
 * Serialize the given value to byte string using the given mapper, employing the given codec algorithm.
 *
 * @param mapper object mapper
 * @param value  value to serialize
 * @param codec  codec
 * @return serialized bytes
 * @throws JsonGenerationException in case of serialization errors
 */
public static ByteString writeValue(ObjectMapper mapper, Object value, Codec codec)
    throws JsonGenerationException {
  final Output output = ByteString.newOutput();

  try {
    final OutputStream os = codec.compress(output);
    try {
      mapper.writer()
          .without(SerializationFeature.INDENT_OUTPUT)
          .writeValue(os, value);
    } finally {
      os.close();
    }
  } catch (IOException e) {
    // Should not happen but...
    throw new JsonGenerationException(e, null);
  }

  // Javadoc says data is copied, but it's more of a transfer of ownership!
  return output.toByteString();
}
 
源代码6 项目: bazel-buildfarm   文件: MemoryWriteOutputStream.java
MemoryWriteOutputStream(
    ContentAddressableStorage storage,
    Digest digest,
    ListenableFuture<ByteString> writtenFuture) {
  this.storage = storage;
  this.digest = digest;
  this.writtenFuture = writtenFuture;
  if (digest.getSizeBytes() > Integer.MAX_VALUE) {
    throw new IllegalArgumentException(
        String.format(
            "content size %d exceeds maximum of %d", digest.getSizeBytes(), Integer.MAX_VALUE));
  }
  out = ByteString.newOutput((int) digest.getSizeBytes());
  hashOut = DigestUtil.forDigest(digest).newHashingOutputStream(out);
  addListener(
      () -> {
        future.set(null);
        try {
          hashOut.close();
        } catch (IOException e) {
          // ignore
        }
      },
      directExecutor());
}
 
源代码7 项目: tez   文件: MRInputHelpers.java
@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();
}
 
源代码8 项目: flink-dataflow   文件: FlinkStateInternals.java
@Override
public void persistState(StateCheckpointWriter checkpointBuilder) throws IOException {
	if (!isClear) {
		// serialize the coder.
		byte[] coder = InstantiationUtil.serializeObject(accumCoder);

		// serialize the combiner.
		byte[] combiner = InstantiationUtil.serializeObject(combineFn);

		// encode the accumulator into a ByteString
		ByteString.Output stream = ByteString.newOutput();
		accumCoder.encode(accum, stream, Coder.Context.OUTER);
		ByteString data = stream.toByteString();

		// put the flag that the next serialized element is an accumulator
		checkpointBuilder.addAccumulatorBuilder()
			.setTag(stateKey)
			.setData(coder)
			.setData(combiner)
			.setData(data);
	}
}
 
源代码9 项目: flink-dataflow   文件: FlinkStateInternals.java
@Override
public void persistState(StateCheckpointWriter checkpointBuilder) throws IOException {
	if (!contents.isEmpty()) {
		// serialize the coder.
		byte[] coder = InstantiationUtil.serializeObject(elemCoder);

		checkpointBuilder.addListUpdatesBuilder()
				.setTag(stateKey)
				.setData(coder)
				.writeInt(contents.size());

		for (T item : contents) {
			// encode the element
			ByteString.Output stream = ByteString.newOutput();
			elemCoder.encode(item, stream, Coder.Context.OUTER);
			ByteString data = stream.toByteString();

			// add the data to the checkpoint.
			checkpointBuilder.setData(data);
		}
	}
}
 
源代码10 项目: bazel   文件: ObjectCodecs.java
private static ByteString serializeToByteString(Object subject, SerializeCall wrapped)
    throws SerializationException {
  ByteString.Output resultOut = ByteString.newOutput();
  CodedOutputStream codedOut = CodedOutputStream.newInstance(resultOut);
  wrapped.serialize(subject, codedOut);
  try {
    codedOut.flush();
    return resultOut.toByteString();
  } catch (IOException e) {
    throw new SerializationException("Failed to serialize " + subject, e);
  }
}
 
源代码11 项目: bazel   文件: TestUtils.java
public static <T> ByteString toBytes(SerializationContext serializationContext, T value)
    throws IOException, SerializationException {
  ByteString.Output output = ByteString.newOutput();
  CodedOutputStream codedOut = CodedOutputStream.newInstance(output);
  serializationContext.serialize(value, codedOut);
  codedOut.flush();
  return output.toByteString();
}
 
源代码12 项目: incubator-tez   文件: TezCommonUtils.java
@Private
public static ByteString compressByteArrayToByteString(byte[] inBytes) throws IOException {
  ByteString.Output os = ByteString.newOutput();
  DeflaterOutputStream compressOs = new DeflaterOutputStream(os, new Deflater(
      Deflater.BEST_COMPRESSION));
  compressOs.write(inBytes);
  compressOs.finish();
  ByteString byteString = os.toByteString();
  return byteString;
}
 
源代码13 项目: dremio-oss   文件: MetadataProtoUtils.java
public static ByteString toProtobuf(BytesOutput out) {
  ByteString.Output output = ByteString.newOutput();
  try {
    out.writeTo(output);
    return output.toByteString();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
源代码14 项目: bazel   文件: GenQueryOutputStream.java
@Override
public ByteString getBytes() throws IOException {
  ByteString.Output out = ByteString.newOutput(size);
  try (GZIPInputStream gzipIn = new GZIPInputStream(compressedData.newInput())) {
    ByteStreams.copy(gzipIn, out);
  }
  return out.toByteString();
}
 
源代码15 项目: tez   文件: TezUtils.java
/**
 * Convert a Configuration to compressed ByteString using Protocol buffer
 *
 * @param conf
 *          : Configuration to be converted
 * @return PB ByteString (compressed)
 * @throws java.io.IOException
 */
public static ByteString createByteStringFromConf(Configuration conf) throws IOException {
  Objects.requireNonNull(conf, "Configuration must be specified");
  ByteString.Output os = ByteString.newOutput();
  SnappyOutputStream compressOs = new SnappyOutputStream(os);
  try {
    writeConfInPB(compressOs, conf);
  } finally {
    if (compressOs != null) {
      compressOs.close();
    }
  }
  return os.toByteString();
}
 
源代码16 项目: bazel   文件: BuildOptions.java
@Override
public void serialize(
    SerializationContext context,
    OptionsDiffForReconstruction diff,
    CodedOutputStream codedOut)
    throws SerializationException, IOException {
  OptionsDiffCache cache = context.getDependency(OptionsDiffCache.class);
  ByteString bytes = cache.getBytesFromOptionsDiff(diff);
  if (bytes == null) {
    context = context.getNewNonMemoizingContext();
    ByteString.Output byteStringOut = ByteString.newOutput();
    CodedOutputStream bytesOut = CodedOutputStream.newInstance(byteStringOut);
    context.serialize(diff.differingOptions, bytesOut);
    context.serialize(diff.extraFirstFragmentClasses, bytesOut);
    context.serialize(diff.extraSecondFragments, bytesOut);
    bytesOut.writeByteArrayNoTag(diff.baseFingerprint);
    context.serialize(diff.checksum, bytesOut);
    context.serialize(diff.differingStarlarkOptions, bytesOut);
    context.serialize(diff.extraFirstStarlarkOptions, bytesOut);
    context.serialize(diff.extraSecondStarlarkOptions, bytesOut);
    bytesOut.flush();
    byteStringOut.flush();
    int optionsDiffSize = byteStringOut.size();
    bytes = byteStringOut.toByteString();
    cache.putBytesFromOptionsDiff(diff, bytes);
    logger.atFine().log(
        "Serialized OptionsDiffForReconstruction %s. Diff took %d bytes.",
        diff, optionsDiffSize);
  }
  codedOut.writeBytesNoTag(bytes);
}
 
源代码17 项目: bazel   文件: TestUtils.java
public static ByteString toBytesMemoized(Object original, ObjectCodecRegistry registry)
    throws IOException, SerializationException {
  ByteString.Output output = ByteString.newOutput();
  CodedOutputStream codedOut = CodedOutputStream.newInstance(output);
  new ObjectCodecs(registry).serializeMemoized(original, codedOut);
  codedOut.flush();
  return output.toByteString();
}
 
源代码18 项目: bazel   文件: BinTools.java
@Override
public ByteString getBytes() throws IOException {
  ByteString.Output out = ByteString.newOutput();
  writeTo(out);
  return out.toByteString();
}
 
源代码19 项目: hadoop   文件: BlockListAsLongs.java
Builder() {
  out = ByteString.newOutput(64*1024);
  cos = CodedOutputStream.newInstance(out);
}
 
源代码20 项目: bazel-buildfarm   文件: ByteStreamServiceWriter.java
public ByteStreamServiceWriter(
    String resourceName, SettableFuture<ByteString> content, int initialCapacity) {
  this.resourceName = resourceName;
  this.content = content;
  out = ByteString.newOutput(initialCapacity);
}