Java 类com.google.protobuf.ByteString 实例源码

项目:okwallet    文件:PaymentProtocol.java   
/**
 * Create a payment request. You may want to sign the request using {@link #signPaymentRequest}. Use
 * {@link org.bitcoin.protocols.payments.Protos.PaymentRequest.Builder#build} to get the actual payment request.
 * 
 * @param params network parameters
 * @param outputs list of outputs to request coins to
 * @param memo arbitrary, user readable memo, or null if none
 * @param paymentUrl URL to send payment message to, or null if none
 * @param merchantData arbitrary merchant data, or null if none
 * @return created payment request, in its builder form
 */
public static Protos.PaymentRequest.Builder createPaymentRequest(NetworkParameters params,
        List<Protos.Output> outputs, @Nullable String memo, @Nullable String paymentUrl,
        @Nullable byte[] merchantData) {
    final Protos.PaymentDetails.Builder paymentDetails = Protos.PaymentDetails.newBuilder();
    paymentDetails.setNetwork(params.getPaymentProtocolId());
    for (Protos.Output output : outputs)
        paymentDetails.addOutputs(output);
    if (memo != null)
        paymentDetails.setMemo(memo);
    if (paymentUrl != null)
        paymentDetails.setPaymentUrl(paymentUrl);
    if (merchantData != null)
        paymentDetails.setMerchantData(ByteString.copyFrom(merchantData));
    paymentDetails.setTime(Utils.currentTimeSeconds());

    final Protos.PaymentRequest.Builder paymentRequest = Protos.PaymentRequest.newBuilder();
    paymentRequest.setSerializedPaymentDetails(paymentDetails.build().toByteString());
    return paymentRequest;
}
项目:hadoop    文件:PBHelper.java   
public static SnapshottableDirectoryStatusProto convert(
    SnapshottableDirectoryStatus status) {
  if (status == null) {
    return null;
  }
  int snapshotNumber = status.getSnapshotNumber();
  int snapshotQuota = status.getSnapshotQuota();
  byte[] parentFullPath = status.getParentFullPath();
  ByteString parentFullPathBytes = ByteString.copyFrom(
      parentFullPath == null ? DFSUtil.EMPTY_BYTES : parentFullPath);
  HdfsFileStatusProto fs = convert(status.getDirStatus());
  SnapshottableDirectoryStatusProto.Builder builder = 
      SnapshottableDirectoryStatusProto
      .newBuilder().setSnapshotNumber(snapshotNumber)
      .setSnapshotQuota(snapshotQuota).setParentFullpath(parentFullPathBytes)
      .setDirStatus(fs);
  return builder.build();
}
项目:Juice    文件:SchedulerCalls.java   
@NotNull
public static Call ackUpdate(
        @NotNull final FrameworkID frameworkId,
        @NotNull final ByteString uuid,
        @NotNull final AgentID agentId,
        @NotNull final TaskID taskId
) {
    return Call.newBuilder()
            .setFrameworkId(frameworkId)
            .setType(Call.Type.ACKNOWLEDGE)
            .setAcknowledge(
                    Call.Acknowledge.newBuilder()
                            .setUuid(uuid)
                            .setAgentId(agentId)
                            .setTaskId(taskId)
                            .build()
            )
            .build();
}
项目:seldon-core    文件:TestPredictionProto.java   
@Test
public void customBytesRequest() throws InvalidProtocolBufferException
{
    String customData = "{\"c\":1.0}";
    SeldonMessage.Builder b = SeldonMessage.newBuilder();
    b.setBinData(ByteString.copyFrom(customData.getBytes()));
    SeldonMessage request = b.build();

    String json = ProtoBufUtils.toJson(request);

    System.out.println(json);

    SeldonMessage.Builder b2 = SeldonMessage.newBuilder();
    ProtoBufUtils.updateMessageBuilderFromJson(b2, json);

    SeldonMessage request2 = b2.build();
    String custom = request2.getBinData().toString(StandardCharsets.UTF_8);
    System.out.println(custom);

    String json2 = ProtoBufUtils.toJson(request2);

    System.out.println(json2);

    Assert.assertEquals(json, json2);
}
项目:sstore-soft    文件:HStoreCoordinator.java   
/**
 * Tell all remote partitions to start the map phase for this txn
 * @param ts
 */
public void transactionMap(LocalTransaction ts, RpcCallback<TransactionMapResponse> callback) {
    ByteString paramBytes = null;
    try {
        ByteBuffer b = ByteBuffer.wrap(FastSerializer.serialize(ts.getProcedureParameters()));
        paramBytes = ByteString.copyFrom(b.array()); 
    } catch (Exception ex) {
        throw new RuntimeException("Unexpected error when serializing StoredProcedureInvocation", ex);
    }

    TransactionMapRequest request = TransactionMapRequest.newBuilder()
                                                 .setTransactionId(ts.getTransactionId())
                                                 .setClientHandle(ts.getClientHandle())
                                                 .setBasePartition(ts.getBasePartition())
                                                 .setProcedureId(ts.getProcedure().getId())
                                                 .setParams(paramBytes)
                                                 .build();

    PartitionSet partitions = ts.getPredictTouchedPartitions();
    if (debug.val){
        LOG.debug(String.format("Notifying partitions %s that %s is in Map Phase", partitions, ts));
        if (trace.val) LOG.trace("<HStoreCoordinator.TransactionMap> is executing to sendMessages to all partitions");
    }
    this.transactionMap_handler.sendMessages(ts, request, callback, partitions);
}
项目:sctalk    文件:PduAttachData.java   
public PduAttachData(ByteString bytes) {

    buffer.writeBytes(bytes.toByteArray());

    this.type = buffer.readInt();
    this.handle = buffer.readLong();
    this.serviceType = buffer.readInt();
    this.pduLength = buffer.readInt();
    ByteBuf buf = buffer.readBytes(this.pduLength);

    if (buf.hasArray()) {
        this.pdu = ByteString.copyFrom(buf.array());
    } else {
        byte[] content = new byte[buf.capacity()];
        buf.readBytes(content);
        this.pdu = ByteString.copyFrom(content);
    }
}
项目:hashsdn-controller    文件:SnapshotTrackerTest.java   
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);

    data = new HashMap<>();
    data.put("key1", "value1");
    data.put("key2", "value2");
    data.put("key3", "value3");

    byteString = ByteString.copyFrom(SerializationUtils.serialize((Serializable) data));
    chunk1 = getNextChunk(byteString, 0, 10);
    chunk2 = getNextChunk(byteString, 10, 10);
    chunk3 = getNextChunk(byteString, 20, byteString.size());

    fbos = spy(new FileBackedOutputStream(100000000, "target"));
    FileBackedOutputStreamFactory mockFactory = mock(FileBackedOutputStreamFactory.class);
    doReturn(fbos).when(mockFactory).newInstance();
    doReturn(mockFactory).when(mockContext).getFileBackedOutputStreamFactory();
}
项目:hadoop-oss    文件:SaslRpcClient.java   
@Override
public void write(byte[] buf, int off, int len) throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("wrapping token of length:" + len);
  }
  buf = saslClient.wrap(buf, off, len);
  RpcSaslProto saslMessage = RpcSaslProto.newBuilder()
      .setState(SaslState.WRAP)
      .setToken(ByteString.copyFrom(buf, 0, buf.length))
      .build();
  RpcRequestMessageWrapper request =
      new RpcRequestMessageWrapper(saslHeader, saslMessage);
  DataOutputStream dob = new DataOutputStream(out);
  dob.writeInt(request.getLength());
  request.write(dob);
 }
项目:creacoinj    文件:ChannelConnectionTest.java   
@Test
public void testClientRefusesNonCanonicalKey() throws Exception {
    ChannelTestUtils.RecordingPair pair = ChannelTestUtils.makeRecorders(serverWallet, mockBroadcaster);
    PaymentChannelServer server = pair.server;
    PaymentChannelClient client = new PaymentChannelClient(wallet, myKey, COIN, Sha256Hash.ZERO_HASH, null, clientChannelProperties, pair.clientRecorder);
    client.connectionOpen();
    server.connectionOpen();
    server.receiveMessage(pair.clientRecorder.checkNextMsg(MessageType.CLIENT_VERSION));
    client.receiveMessage(pair.serverRecorder.checkNextMsg(MessageType.SERVER_VERSION));
    Protos.TwoWayChannelMessage.Builder initiateMsg = Protos.TwoWayChannelMessage.newBuilder(pair.serverRecorder.checkNextMsg(MessageType.INITIATE));
    ByteString brokenKey = initiateMsg.getInitiate().getMultisigKey();
    brokenKey = ByteString.copyFrom(Arrays.copyOf(brokenKey.toByteArray(), brokenKey.size() + 1));
    initiateMsg.getInitiateBuilder().setMultisigKey(brokenKey);
    client.receiveMessage(initiateMsg.build());
    pair.clientRecorder.checkNextMsg(MessageType.ERROR);
    assertEquals(CloseReason.REMOTE_SENT_INVALID_MESSAGE, pair.clientRecorder.q.take());
}
项目:s-store    文件:HStoreCoordinator.java   
/**
 * Tell all remote partitions to start the map phase for this txn
 * @param ts
 */
public void transactionMap(LocalTransaction ts, RpcCallback<TransactionMapResponse> callback) {
    ByteString paramBytes = null;
    try {
        ByteBuffer b = ByteBuffer.wrap(FastSerializer.serialize(ts.getProcedureParameters()));
        paramBytes = ByteString.copyFrom(b.array()); 
    } catch (Exception ex) {
        throw new RuntimeException("Unexpected error when serializing StoredProcedureInvocation", ex);
    }

    TransactionMapRequest request = TransactionMapRequest.newBuilder()
                                                 .setTransactionId(ts.getTransactionId())
                                                 .setClientHandle(ts.getClientHandle())
                                                 .setBasePartition(ts.getBasePartition())
                                                 .setProcedureId(ts.getProcedure().getId())
                                                 .setParams(paramBytes)
                                                 .build();

    PartitionSet partitions = ts.getPredictTouchedPartitions();
    if (debug.val){
        LOG.debug(String.format("Notifying partitions %s that %s is in Map Phase", partitions, ts));
        if (trace.val) LOG.trace("<HStoreCoordinator.TransactionMap> is executing to sendMessages to all partitions");
    }
    this.transactionMap_handler.sendMessages(ts, request, callback, partitions);
}
项目:Cable-Android    文件:GroupMessageProcessor.java   
private static GroupContext.Builder createGroupContext(SignalServiceGroup group) {
  GroupContext.Builder builder = GroupContext.newBuilder();
  builder.setId(ByteString.copyFrom(group.getGroupId()));

  if (group.getAvatar().isPresent() && group.getAvatar().get().isPointer()) {
    builder.setAvatar(AttachmentPointer.newBuilder()
                                       .setId(group.getAvatar().get().asPointer().getId())
                                       .setKey(ByteString.copyFrom(group.getAvatar().get().asPointer().getKey()))
                                       .setContentType(group.getAvatar().get().getContentType()));
  }

  if (group.getName().isPresent()) {
    builder.setName(group.getName().get());
  }

  if (group.getMembers().isPresent()) {
    builder.addAllMembers(group.getMembers().get());
  }

  return builder;
}
项目:flume-release-1.7.0    文件:Put.java   
@Override
void writeProtos(OutputStream out) throws IOException {
  ProtosFactory.Put.Builder putBuilder = ProtosFactory.Put.newBuilder();
  ProtosFactory.FlumeEvent.Builder eventBuilder =
      ProtosFactory.FlumeEvent.newBuilder();
  Map<String, String> headers = event.getHeaders();
  ProtosFactory.FlumeEventHeader.Builder headerBuilder =
      ProtosFactory.FlumeEventHeader.newBuilder();
  if (headers != null) {
    for (String key : headers.keySet()) {
      String value = headers.get(key);
      headerBuilder.clear();
      eventBuilder.addHeaders(headerBuilder.setKey(key)
          .setValue(value).build());
    }
  }
  eventBuilder.setBody(ByteString.copyFrom(event.getBody()));
  ProtosFactory.FlumeEvent protoEvent = eventBuilder.build();
  putBuilder.setEvent(protoEvent);
  putBuilder.setChecksum(calculateChecksum(event.getBody()));
  putBuilder.build().writeDelimitedTo(out);
}
项目:commelina    文件:NioSocketEventHandlerForAkka.java   
@Override
public CompletableFuture<Long> onLogin(ChannelHandlerContext ctx, SocketASK ask) {
    // 整个消息就是 token
    ByteString tokenArg = ask.getBody().getArgs(0);
    if (tokenArg == null) {
        logger.info("Token arg must be input.");
        return null;
    }
    String token = tokenArg.toStringUtf8();
    if (Strings.isNullOrEmpty(token)) {
        logger.info("Token arg must be input.");
        return null;
    }
    return CompletableFuture.supplyAsync(() -> {
        String parseToken = new String(BaseEncoding.base64Url().decode(token));
        List<String> tokenChars = Splitter.on('|').splitToList(parseToken);
        return Long.valueOf(tokenArg.toStringUtf8());
    });
}
项目:hadoop    文件:Server.java   
private RpcSaslProto buildSaslNegotiateResponse()
    throws IOException, InterruptedException {
  RpcSaslProto negotiateMessage = negotiateResponse;
  // accelerate token negotiation by sending initial challenge
  // in the negotiation response
  if (enabledAuthMethods.contains(AuthMethod.TOKEN)) {
    saslServer = createSaslServer(AuthMethod.TOKEN);
    byte[] challenge = saslServer.evaluateResponse(new byte[0]);
    RpcSaslProto.Builder negotiateBuilder =
        RpcSaslProto.newBuilder(negotiateResponse);
    negotiateBuilder.getAuthsBuilder(0)  // TOKEN is always first
        .setChallenge(ByteString.copyFrom(challenge));
    negotiateMessage = negotiateBuilder.build();
  }
  sentNegotiate = true;
  return negotiateMessage;
}
项目:tikv-client-lib-java    文件:KVMockServer.java   
/** */
public void rawPut(
    com.pingcap.tikv.kvproto.Kvrpcpb.RawPutRequest request,
    io.grpc.stub.StreamObserver<com.pingcap.tikv.kvproto.Kvrpcpb.RawPutResponse>
        responseObserver) {
  try {
    verifyContext(request.getContext());
    ByteString key = request.getKey();

    Kvrpcpb.RawPutResponse.Builder builder = Kvrpcpb.RawPutResponse.newBuilder();
    Integer errorCode = errorMap.get(key);
    Errorpb.Error.Builder errBuilder = Errorpb.Error.newBuilder();
    if (errorCode != null) {
      setErrorInfo(errorCode, errBuilder);
      builder.setRegionError(errBuilder.build());
      //builder.setError("");
    }
    responseObserver.onNext(builder.build());
    responseObserver.onCompleted();
  } catch (Exception e) {
    responseObserver.onError(Status.INTERNAL.asRuntimeException());
  }
}
项目:creacoinj    文件:PaymentChannelServer.java   
@Override
public void onSuccess(Transaction result) {
    // Send the successfully accepted transaction back to the client.
    final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
    msg.setType(Protos.TwoWayChannelMessage.MessageType.CLOSE);
    if (result != null) {
        // Result can be null on various error paths, like if we never actually opened
        // properly and so on.
        msg.getSettlementBuilder().setTx(ByteString.copyFrom(result.unsafeBitcoinSerialize()));
        log.info("Sending CLOSE back with broadcast settlement tx.");
    } else {
        log.info("Sending CLOSE back without broadcast settlement tx.");
    }
    conn.sendToClient(msg.build());
    conn.destroyConnection(clientRequestedClose);
}
项目:tikv-client-lib-java    文件:CatalogTransaction.java   
private List<Pair<ByteString, ByteString>> hashGetFields(ByteString key) {
  CodecDataOutput cdo = new CodecDataOutput();
  encodeHashDataKeyPrefix(cdo, key.toByteArray());
  ByteString encodedKey = cdo.toByteString();

  Iterator<Kvrpcpb.KvPair> iterator = snapshot.scan(encodedKey);
  List<Pair<ByteString, ByteString>> fields = new ArrayList<>();
  while (iterator.hasNext()) {
    Kvrpcpb.KvPair kv = iterator.next();
    if (!KeyUtils.hasPrefix(kv.getKey(), encodedKey)) {
      break;
    }
    fields.add(Pair.create(decodeHashDataKey(kv.getKey()).second, kv.getValue()));
  }

  return fields;
}
项目:spring-remoting-grpc    文件:RemotingServiceImpl.java   
@Override
public void execute(RemoteInvocationRequest request, StreamObserver<RemoteInvocationResponse> responseObserver) {
    try {
        ByteArrayInputStream in = new ByteArrayInputStream(request.getData().toByteArray());
        ObjectInputStream is = new ObjectInputStream(in);
        RemoteInvocation remoteInvocation = (RemoteInvocation) is.readObject();
        RemoteInvocationResult remoteInvocationResult = exporter.invokeForInvocation(remoteInvocation);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(out);
        os.writeObject(remoteInvocationResult);
        responseObserver.onNext(RemoteInvocationResponse.newBuilder().setData(ByteString.copyFrom(out.toByteArray())).build());
        responseObserver.onCompleted();
    } catch (Exception e) {
        responseObserver.onError(e);
    }
}
项目:PeSanKita-lib    文件:SignalServiceAccountManager.java   
public void addDevice(String deviceIdentifier,
                      ECPublicKey deviceKey,
                      IdentityKeyPair identityKeyPair,
                      String code)
    throws InvalidKeyException, IOException
{
  ProvisioningCipher cipher  = new ProvisioningCipher(deviceKey);
  ProvisionMessage   message = ProvisionMessage.newBuilder()
                                               .setIdentityKeyPublic(ByteString.copyFrom(identityKeyPair.getPublicKey().serialize()))
                                               .setIdentityKeyPrivate(ByteString.copyFrom(identityKeyPair.getPrivateKey().serialize()))
                                               .setNumber(user)
                                               .setProvisioningCode(code)
                                               .build();

  byte[] ciphertext = cipher.encrypt(message);
  this.pushServiceSocket.sendProvisioningMessage(deviceIdentifier, ciphertext);
}
项目:tikv-client-lib-java    文件:GrpcUtils.java   
public static Region makeRegion(
    long id, ByteString startKey, ByteString endKey, RegionEpoch re, Peer... peers) {
  return Region.newBuilder()
      .setId(id)
      .setStartKey(startKey)
      .setEndKey(endKey)
      .setRegionEpoch(re)
      .addAllPeers(Lists.newArrayList(peers))
      .build();
}
项目:creacoinj    文件:PaymentChannelClient.java   
/**
 * <p>Called to indicate the connection has been opened and messages can now be generated for the server.</p>
 *
 * <p>Attempts to find a channel to resume and generates a CLIENT_VERSION message for the server based on the
 * result.</p>
 */
@Override
public void connectionOpen() {
    lock.lock();
    try {
        connectionOpen = true;

        StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates) wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID);
        if (channels != null)
            storedChannel = channels.getUsableChannelForServerID(serverId);

        step = InitStep.WAITING_FOR_VERSION_NEGOTIATION;

        Protos.ClientVersion.Builder versionNegotiationBuilder = Protos.ClientVersion.newBuilder()
                .setMajor(versionSelector.getRequestedMajorVersion())
                .setMinor(versionSelector.getRequestedMinorVersion())
                .setTimeWindowSecs(timeWindow);

        if (storedChannel != null) {
            versionNegotiationBuilder.setPreviousChannelContractHash(ByteString.copyFrom(storedChannel.contract.getHash().getBytes()));
            log.info("Begun version handshake, attempting to reopen channel with contract hash {}", storedChannel.contract.getHash());
        } else
            log.info("Begun version handshake creating new channel");

        conn.sendToServer(Protos.TwoWayChannelMessage.newBuilder()
                .setType(Protos.TwoWayChannelMessage.MessageType.CLIENT_VERSION)
                .setClientVersion(versionNegotiationBuilder)
                .build());
    } finally {
        lock.unlock();
    }
}
项目:tikv-client-lib-java    文件:Comparables.java   
@Override
public int compareTo(@Nonnull ComparableByteString other) {
  requireNonNull(other, "other is null");
  ByteString otherBytes = other.bytes;
  int n = Math.min(bytes.size(), otherBytes.size());
  for (int i = 0, j = 0; i < n; i++, j++) {
    int cmp = UnsignedBytes.compare(bytes.byteAt(i), otherBytes.byteAt(j));
    if (cmp != 0) return cmp;
  }
  // one is the prefix of other then the longer is larger
  return bytes.size() - otherBytes.size();
}
项目:tikv-client-lib-java    文件:ScanIterator.java   
public ScanIterator(
    ByteString startKey,
    int batchSize,
    KeyRange range,
    TiSession session,
    RegionManager rm,
    long version) {
  this.startKey = startKey;
  this.batchSize = batchSize;
  this.scanRange = KeyRangeUtils.toRange(range);
  this.session = session;
  this.regionCache = rm;
  this.version = version;
}
项目:tcp-gateway    文件:TestNotify.java   
public boolean send(long seq, String sessionId, int cmd, ByteString body) throws Exception {
    boolean success = false;
    MessageBuf.JMTransfer.Builder builder = generateNotify(sessionId, seq, cmd, body);
    if (builder != null) {
        MessageWrapper wrapper = new MessageWrapper(MessageWrapper.MessageProtocol.NOTIFY, sessionId, builder);
        int ret = notify.notify(seq, wrapper, timeout);
        if (ret == Constants.NOTIFY_SUCCESS) {
            success = true;
        } else if (ret == Constants.NOTIFY_NO_SESSION) {
            /** no session on this machine **/
            success = true;
        }
    }
    return success;
}
项目:ditb    文件:WALKey.java   
public org.apache.hadoop.hbase.protobuf.generated.WALProtos.WALKey.Builder getBuilder(
    WALCellCodec.ByteStringCompressor compressor) throws IOException {
  org.apache.hadoop.hbase.protobuf.generated.WALProtos.WALKey.Builder builder =
      org.apache.hadoop.hbase.protobuf.generated.WALProtos.WALKey.newBuilder();
  if (compressionContext == null) {
    builder.setEncodedRegionName(ByteStringer.wrap(this.encodedRegionName));
    builder.setTableName(ByteStringer.wrap(this.tablename.getName()));
  } else {
    builder.setEncodedRegionName(compressor.compress(this.encodedRegionName,
        compressionContext.regionDict));
    builder.setTableName(compressor.compress(this.tablename.getName(),
        compressionContext.tableDict));
  }
  builder.setLogSequenceNumber(this.logSeqNum);
  builder.setWriteTime(writeTime);
  if (this.origLogSeqNum > 0) {
    builder.setOrigSequenceNumber(this.origLogSeqNum);
  }
  if (this.nonce != HConstants.NO_NONCE) {
    builder.setNonce(nonce);
  }
  if (this.nonceGroup != HConstants.NO_NONCE) {
    builder.setNonceGroup(nonceGroup);
  }
  HBaseProtos.UUID.Builder uuidBuilder = HBaseProtos.UUID.newBuilder();
  for (UUID clusterId : clusterIds) {
    uuidBuilder.setLeastSigBits(clusterId.getLeastSignificantBits());
    uuidBuilder.setMostSigBits(clusterId.getMostSignificantBits());
    builder.addClusterIds(uuidBuilder.build());
  }
  if (scopes != null) {
    for (Map.Entry<byte[], Integer> e : scopes.entrySet()) {
      ByteString family = (compressionContext == null) ? ByteStringer.wrap(e.getKey())
          : compressor.compress(e.getKey(), compressionContext.familyDict);
      builder.addScopes(FamilyScope.newBuilder()
          .setFamily(family).setScopeType(ScopeType.valueOf(e.getValue())));
    }
  }
  return builder;
}
项目:monarch    文件:AWriterImpl.java   
private int writeFooter(long bodyLength) throws IOException {
  getStream();
  OrcProto.Footer.Builder builder = OrcProto.Footer.newBuilder();
  builder.setContentLength(bodyLength);
  builder.setHeaderLength(headerLength);
  builder.setNumberOfRows(rowCount);
  builder.setRowIndexStride(rowIndexStride);
  // populate raw data size
  rawDataSize = computeRawDataSize();
  // serialize the types
  writeTypes(builder, schema);
  // add the stripe information
  for (OrcProto.StripeInformation stripe : stripes) {
    builder.addStripes(stripe);
  }
  // add the column statistics
  writeFileStatistics(builder, treeWriter);
  // add all of the user metadata
  for (Map.Entry<String, ByteString> entry : userMetadata.entrySet()) {
    builder.addMetadata(OrcProto.UserMetadataItem.newBuilder().setName(entry.getKey())
        .setValue(entry.getValue()));
  }
  long startPosn = rawWriter.getPos();
  OrcProto.Footer footer = builder.build();
  footer.writeTo(protobufWriter);
  protobufWriter.flush();
  writer.flush();
  return (int) (rawWriter.getPos() - startPosn);
}
项目:creacoinj    文件:PaymentChannelClient.java   
@GuardedBy("lock")
private void receiveRefund(Protos.TwoWayChannelMessage refundMsg, @Nullable KeyParameter userKey) throws VerificationException {
    checkState(majorVersion == 1);
    checkState(step == InitStep.WAITING_FOR_REFUND_RETURN && refundMsg.hasReturnRefund());
    log.info("Got RETURN_REFUND message, providing signed contract");
    Protos.ReturnRefund returnedRefund = refundMsg.getReturnRefund();
    // Cast is safe since we've checked the version number
    ((PaymentChannelV1ClientState)state).provideRefundSignature(returnedRefund.getSignature().toByteArray(), userKey);
    step = InitStep.WAITING_FOR_CHANNEL_OPEN;

    // Before we can send the server the contract (ie send it to the network), we must ensure that our refund
    // transaction is safely in the wallet - thus we store it (this also keeps it up-to-date when we pay)
    state.storeChannelInWallet(serverId);

    Protos.ProvideContract.Builder contractMsg = Protos.ProvideContract.newBuilder()
            .setTx(ByteString.copyFrom(state.getContract().unsafeBitcoinSerialize()));
    try {
        // Make an initial payment of the dust limit, and put it into the message as well. The size of the
        // server-requested dust limit was already sanity checked by this point.
        PaymentChannelClientState.IncrementedPayment payment = state().incrementPaymentBy(Coin.valueOf(minPayment), userKey);
        Protos.UpdatePayment.Builder initialMsg = contractMsg.getInitialPaymentBuilder();
        initialMsg.setSignature(ByteString.copyFrom(payment.signature.encodeToBitcoin()));
        initialMsg.setClientChangeValue(state.getValueRefunded().getValue());
    } catch (ValueOutOfRangeException e) {
        throw new IllegalStateException(e);  // This cannot happen.
    }

    final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
    msg.setProvideContract(contractMsg);
    msg.setType(Protos.TwoWayChannelMessage.MessageType.PROVIDE_CONTRACT);
    conn.sendToServer(msg.build());
}
项目:s-store    文件:TestPartitionExecutor.java   
/**
 * testBuildPartitionResult
 */
public void testBuildPartitionResult() throws Exception {
    Table catalog_tbl = this.getTable(TM1Constants.TABLENAME_SPECIAL_FACILITY); 
    VoltTable vt = CatalogUtil.getVoltTable(catalog_tbl);
    assertNotNull(vt);
    int num_rows = 50;
    for (int i = 0; i < num_rows; i++) {
        Object row[] = new Object[catalog_tbl.getColumns().size()];
        for (int j = 0; j < row.length; j++) {
            VoltType vtype = VoltType.get(catalog_tbl.getColumns().get(j).getType());
            row[j] = VoltTypeUtil.getRandomValue(vtype, rand);
        } // FOR
        vt.addRow(row);
    } // FOR

    int dep_id = 10001;
    DependencySet result = new DependencySet(new int[]{ dep_id }, new VoltTable[]{ vt });

    RemoteTransaction ts = new RemoteTransaction(hstore_site);
    WorkResult partitionResult = executor.buildWorkResult(ts, result, Status.OK, null);
    assertNotNull(partitionResult);
    assertEquals(result.size(), partitionResult.getDepDataCount());

    assertEquals(1, partitionResult.getDepDataCount());
    for (int i = 0; i < partitionResult.getDepDataCount(); i++) {
        assertEquals(dep_id, partitionResult.getDepId(i));

        ByteString bs = partitionResult.getDepData(i);
        assertFalse(bs.isEmpty());
        System.err.println("SIZE: " + StringUtil.md5sum(bs.asReadOnlyByteBuffer()));

        byte serialized[] = bs.toByteArray();
        VoltTable clone = FastDeserializer.deserialize(serialized, VoltTable.class);
        assertNotNull(clone);
        assertEquals(vt.getRowCount(), clone.getRowCount());
        assertEquals(vt.getColumnCount(), clone.getColumnCount());
    } // FOR

}
项目:okwallet    文件:PaymentChannelClient.java   
/**
 * Increments the total value which we pay the server. Note that the amount of money sent may not be the same as the
 * amount of money actually requested. It can be larger if the amount left over in the channel would be too small to
 * be accepted by the Bitcoin network. ValueOutOfRangeException will be thrown, however, if there's not enough money
 * left in the channel to make the payment at all. Only one payment can be in-flight at once. You have to ensure
 * you wait for the previous increase payment future to complete before incrementing the payment again.
 *
 * @param size How many satoshis to increment the payment by (note: not the new total).
 * @param info Information about this update, used to extend this protocol.
 * @param userKey Key derived from a user password, needed for any signing when the wallet is encrypted.
 *                The wallet KeyCrypter is assumed.
 * @return a future that completes when the server acknowledges receipt and acceptance of the payment.
 * @throws ValueOutOfRangeException If the size is negative or would pay more than this channel's total value
 *                                  ({@link PaymentChannelClientConnection#state()}.getTotalValue())
 * @throws IllegalStateException If the channel has been closed or is not yet open
 *                               (see {@link PaymentChannelClientConnection#getChannelOpenFuture()} for the second)
 * @throws ECKey.KeyIsEncryptedException If the keys are encrypted and no AES key has been provided,
 */
@Override
public ListenableFuture<PaymentIncrementAck> incrementPayment(Coin size, @Nullable ByteString info, @Nullable KeyParameter userKey)
        throws ValueOutOfRangeException, IllegalStateException, ECKey.KeyIsEncryptedException {
    lock.lock();
    try {
        if (state() == null || !connectionOpen || step != InitStep.CHANNEL_OPEN)
            throw new IllegalStateException("Channel is not fully initialized/has already been closed");
        if (increasePaymentFuture != null)
            throw new IllegalStateException("Already incrementing paying, wait for previous payment to complete.");
        if (wallet.isEncrypted() && userKey == null)
            throw new ECKey.KeyIsEncryptedException();

        PaymentChannelV1ClientState.IncrementedPayment payment = state().incrementPaymentBy(size, userKey);
        Protos.UpdatePayment.Builder updatePaymentBuilder = Protos.UpdatePayment.newBuilder()
                .setSignature(ByteString.copyFrom(payment.signature.encodeToBitcoin()))
                .setClientChangeValue(state.getValueRefunded().value);
        if (info != null) updatePaymentBuilder.setInfo(info);

        increasePaymentFuture = SettableFuture.create();
        increasePaymentFuture.addListener(new Runnable() {
            @Override
            public void run() {
                lock.lock();
                increasePaymentFuture = null;
                lock.unlock();
            }
        }, MoreExecutors.directExecutor());

        conn.sendToServer(Protos.TwoWayChannelMessage.newBuilder()
                .setUpdatePayment(updatePaymentBuilder)
                .setType(Protos.TwoWayChannelMessage.MessageType.UPDATE_PAYMENT)
                .build());
        lastPaymentActualAmount = payment.amount;
        return increasePaymentFuture;
    } finally {
        lock.unlock();
    }
}
项目:seldon-core    文件:QuantityUtils.java   
private ByteString toByteString(MessageOrBuilder message) {
  if (message instanceof Message) {
    return ((Message) message).toByteString();
  } else {
    return ((Message.Builder) message).build().toByteString();
  }
}
项目:bazel-buildfarm    文件:ByteStreamService.java   
private void readBlob(
    ReadRequest request,
    StreamObserver<ReadResponse> responseObserver) {
  String resourceName = request.getResourceName();

  Instance instance;
  try {
    instance = instances.getFromBlob(resourceName);
  } catch (InstanceNotFoundException ex) {
    responseObserver.onError(BuildFarmInstances.toStatusException(ex));
    return;
  }

  Digest digest = UrlPath.parseBlobDigest(resourceName);

  ByteString blob = instance.getBlob(
      digest, request.getReadOffset(), request.getReadLimit());
  if (blob == null) {
    responseObserver.onError(new StatusException(Status.NOT_FOUND));
    return;
  }

  while (!blob.isEmpty()) {
    ByteString chunk;
    if (blob.size() < DEFAULT_CHUNK_SIZE) {
      chunk = blob;
      blob = ByteString.EMPTY;
    } else {
      chunk = blob.substring(0, (int) DEFAULT_CHUNK_SIZE);
      blob = blob.substring((int) DEFAULT_CHUNK_SIZE);
    }
    responseObserver.onNext(ReadResponse.newBuilder()
        .setData(chunk)
        .build());
  }

  responseObserver.onCompleted();
}
项目:ditb    文件:AuthenticationTokenIdentifier.java   
public byte[] toBytes() {
  AuthenticationProtos.TokenIdentifier.Builder builder =
      AuthenticationProtos.TokenIdentifier.newBuilder();
  builder.setKind(AuthenticationProtos.TokenIdentifier.Kind.HBASE_AUTH_TOKEN);
  if (username != null) {
    builder.setUsername(ByteString.copyFromUtf8(username));
  }
  builder.setIssueDate(issueDate)
      .setExpirationDate(expirationDate)
      .setKeyId(keyId)
      .setSequenceNumber(sequenceNumber);
  return builder.build().toByteArray();
}
项目:hadoop    文件:PBHelper.java   
public static TokenProto convert(Token<?> tok) {
  return TokenProto.newBuilder().
            setIdentifier(ByteString.copyFrom(tok.getIdentifier())).
            setPassword(ByteString.copyFrom(tok.getPassword())).
            setKind(tok.getKind().toString()).
            setService(tok.getService().toString()).build(); 
}
项目:sstore-soft    文件:ProtoRpcController.java   
private void finishRpc(Protocol.Status status, ByteString response, String errorText) {
    assert this.status == Protocol.Status.INVALID :
        String.format("Trying to invoke finishRPC more than once [status=%s, errorText=%s]\n%s",
                      this.status, errorText, response);
    assert callback != null;

    assert status != Protocol.Status.INVALID;
    boolean success = status == Protocol.Status.OK;
    if (success) {
        assert response != null;
        assert errorText == null;
    } else {
        assert response == null;
        assert errorText != null;
    }

    // Set the status and reset state before we invoke the callback
    this.status = status;
    this.errorText = errorText;
    eventLoop = null;
    Message.Builder tempBuilder = builder;        
    builder = null;
    RpcCallback<Message> tempCallback = callback;
    callback = null;

    Message result = null;
    if (success) {
        try {
            tempBuilder.mergeFrom(response);
            result = tempBuilder.build();
        } catch (InvalidProtocolBufferException e) {
            System.err.println("RESPONSE: " + StringUtil.hexDump(response));
            System.err.println("BUILDER:  " + tempBuilder.toString());
            throw new RuntimeException(e);
        }
    }
    tempCallback.run(result);
}
项目:Cable-Android    文件:GroupManager.java   
private static GroupActionResult sendGroupUpdate(@NonNull  Context      context,
                                                 @NonNull  MasterSecret masterSecret,
                                                 @NonNull  byte[]       groupId,
                                                 @NonNull  Set<String>  e164numbers,
                                                 @Nullable String       groupName,
                                                 @Nullable byte[]       avatar)
{
  Attachment avatarAttachment = null;
  String     groupRecipientId = GroupUtil.getEncodedId(groupId);
  Recipients groupRecipient   = RecipientFactory.getRecipientsFromString(context, groupRecipientId, false);

  GroupContext.Builder groupContextBuilder = GroupContext.newBuilder()
                                                         .setId(ByteString.copyFrom(groupId))
                                                         .setType(GroupContext.Type.UPDATE)
                                                         .addAllMembers(e164numbers);
  if (groupName != null) groupContextBuilder.setName(groupName);
  GroupContext groupContext = groupContextBuilder.build();

  if (avatar != null) {
    Uri avatarUri = SingleUseBlobProvider.getInstance().createUri(avatar);
    avatarAttachment = new UriAttachment(avatarUri, MediaUtil.IMAGE_PNG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length, null, false);
  }

  OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(groupRecipient, groupContext, avatarAttachment, System.currentTimeMillis(), 0);
  long                      threadId        = MessageSender.send(context, masterSecret, outgoingMessage, -1, false, null);

  return new GroupActionResult(groupRecipient, threadId);
}
项目:bazel-buildfarm    文件:Digests.java   
public static Digest computeDigest(ByteString blob) {
  try {
    return buildDigest(
        new ByteSource() {
          @Override
          public InputStream openStream() throws IOException {
            return blob.newInput();
          }
        }.hash(Hashing.sha1()).toString(),
        blob.size());
  } catch(IOException ex) {
    /* impossible */
    return null;
  }
}
项目:s-store    文件:TransactionRedirectResponseCallback.java   
@Override
    public void run(ClientResponseImpl parameter) {
        if (debug.val)
            LOG.debug(String.format("Got ClientResponse callback for txn #%d! Sending back to %s",
                      parameter.getTransactionId(), HStoreThreadManager.formatSiteName(this.destSiteId)));
        FastSerializer fs = new FastSerializer();
        try {
            parameter.writeExternal(fs);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        ByteString bs = ByteString.copyFrom(fs.getBuffer());
        TransactionRedirectResponse response = TransactionRedirectResponse.newBuilder()
                                                              .setSenderSite(this.sourceSiteId)
                                                              .setOutput(bs)
                                                              .build();
        this.orig_callback.run(response);
        if (debug.val)
            LOG.debug(String.format("Sent back ClientResponse for txn #%d to %s [bytes=%d]",
                      parameter.getTransactionId(), HStoreThreadManager.formatSiteName(this.destSiteId),
                      bs.size()));

        // IMPORTANT: Since we're the only one that knows that we're finished (and actually even
        // cares), we need to be polite and clean-up after ourselves...
//        try {
//            this.finish();
//            hstore_site.getObjectPools().CALLBACKS_TXN_REDIRECT_RESPONSE.returnObject(this);
//        } catch (Exception ex) {
//            throw new RuntimeException("Funky failure", ex);
//        }
    }
项目:seldon-core    文件:IntOrStringUtils.java   
private ByteString toByteString(MessageOrBuilder message) {
  if (message instanceof Message) {
    return ((Message) message).toByteString();
  } else {
    return ((Message.Builder) message).build().toByteString();
  }
}
项目:s-store    文件:AbstractTransaction.java   
/**
 * Attach prefetchable WorkFragments for this transaction
 * This should be invoked on the remote side of the initialization request.
 * That is, it is not the transaction's base partition that is storing this information,
 * it's coming from over the network
 * @param fragments
 * @param rawParameters
 */
public void attachPrefetchQueries(List<WorkFragment> fragments, List<ByteString> rawParameters) {
    assert(this.prefetch.fragments == null) :
        "Trying to attach Prefetch WorkFragments more than once!";

    // Simply copy the references so we don't allocate more objects
    this.prefetch.fragments = fragments;
    this.prefetch.paramsRaw = rawParameters;
}
项目:dremio-oss    文件:RpcBus.java   
public static <T> T get(ByteString pBody, Parser<T> parser) throws RpcException {
  try {
    return parser.parseFrom(pBody);
  } catch (InvalidProtocolBufferException e) {
    throw new RpcException(String.format("Failure while decoding message with parser of type. %s", parser.getClass().getCanonicalName()), e);
  }
}