當前位置: 首頁>>代碼示例>>Java>>正文


Java TextFormat類代碼示例

本文整理匯總了Java中com.google.protobuf.TextFormat的典型用法代碼示例。如果您正苦於以下問題:Java TextFormat類的具體用法?Java TextFormat怎麽用?Java TextFormat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TextFormat類屬於com.google.protobuf包,在下文中一共展示了TextFormat類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: get

import com.google.protobuf.TextFormat; //導入依賴的package包/類
synchronized long get() throws IOException {
  try {
    currentStat = zkc.exists(path, false);
    if (currentStat == null) {
      return 0;
    } else {

      byte[] bytes = zkc.getData(path, false, currentStat);

      MaxTxIdProto.Builder builder = MaxTxIdProto.newBuilder();
      TextFormat.merge(new String(bytes, UTF_8), builder);
      if (!builder.isInitialized()) {
        throw new IOException("Invalid/Incomplete data in znode");
      }

      return builder.build().getTxId();
    }
  } catch (KeeperException e) {
    throw new IOException("Error reading the max tx id from zk", e);
  } catch (InterruptedException ie) {
    throw new IOException("Interrupted while reading thr max tx id", ie);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:24,代碼來源:MaxTxId.java

示例2: parseMessage

import com.google.protobuf.TextFormat; //導入依賴的package包/類
public ApplicationLog parseMessage(String messageString) throws InvalidProtocolBufferException, TextFormat
        .ParseException {
    LogMessages.Message.Builder builder = LogMessages.Message.newBuilder();
    TextFormat.merge(messageString, builder);
    LogMessages.Message message = builder.build();

    return createApplicationLog(message);
}
 
開發者ID:SAP,項目名稱:cf-java-client-sap,代碼行數:9,代碼來源:LoggregatorMessageParser.java

示例3: findInCache

import com.google.protobuf.TextFormat; //導入依賴的package包/類
@Override public Optional<Group> findInCache(String cacheKey) {

    logger.info("{}", kvp("op", "findInCache", "group", cacheKey));

    @SuppressWarnings("unchecked")
    Optional<String> maybe = (Optional<String>) new RedisCacheCommand<Optional<String>>(
        "GroupCacheGet",
        () -> redisCache.get(cacheKey),
        Optional::empty,
        hystrixConfiguration,
        metrics).execute();

    if (maybe.isPresent()) {
      Group cached = GroupSupport.toGroup(maybe.get());
      logger.info("{} /group=[{}]",
          kvp("op", "findInCache", "key", cacheKey, "result", "cache_hit"),
          TextFormat.shortDebugString(cached));
      return Optional.of(cached);
    }

    logger.info("{}", kvp("op", "findInCache", "key", cacheKey, "result", "cache_miss"));

    return Optional.empty();
  }
 
開發者ID:dehora,項目名稱:outland,代碼行數:25,代碼來源:DefaultGroupCache.java

示例4: findInCache

import com.google.protobuf.TextFormat; //導入依賴的package包/類
@Override public Optional<Feature> findInCache(String cacheKey) {
  //noinspection unchecked
  Optional<String> maybe = (Optional<String>) new RedisCacheCommand<Optional<String>>("CacheGet",
      () -> redisCache.get(cacheKey),
      Optional::empty,
      hystrixConfiguration,
      metrics).execute();

  if (maybe.isPresent()) {
    Feature cached = FeatureSupport.toFeature(maybe.get());
    logger.info("{} /feature=[{}]",
        kvp("op", "findInCache", "key", cacheKey, "result", "cache_hit"),
        TextFormat.shortDebugString(cached));
    return Optional.of(cached);
  }

  logger.info("{}", kvp("op", "findInCache", "key", cacheKey, "result", "cache_miss"));

  return Optional.empty();
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:21,代碼來源:DefaultFeatureCache.java

示例5: parseRequest

import com.google.protobuf.TextFormat; //導入依賴的package包/類
@Override public Request parseRequest(byte[] bytes) throws IOException {
  ByteString byteString = UnsafeByteOperations.unsafeWrap(bytes);
  CodedInputStream inputStream = byteString.newCodedInput();
  // Enable aliasing to avoid an extra copy to get at the serialized Request inside of the
  // WireMessage.
  inputStream.enableAliasing(true);
  WireMessage wireMsg = WireMessage.parseFrom(inputStream);

  String serializedMessageClassName = wireMsg.getName();

  try {
    RequestTranslator translator = getParserForRequest(serializedMessageClassName);

    // The ByteString should be logical offsets into the original byte array
    return translator.transform(wireMsg.getWrappedMessage());
  } catch (RuntimeException e) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Failed to parse request message '{}'", TextFormat.shortDebugString(wireMsg));
    }
    throw e;
  }
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:23,代碼來源:ProtobufTranslationImpl.java

示例6: mapToString

import com.google.protobuf.TextFormat; //導入依賴的package包/類
public static <K> String mapToString(
    Map<K, ? extends Message> map) {
  StringBuilder sb = new StringBuilder();
  boolean first = true;
  for (Map.Entry<K, ? extends Message> e : map.entrySet()) {
    if (!first) {
      sb.append("\n");
    }
    first = false;
    sb.append(e.getKey()).append(": ")
      .append(TextFormat.shortDebugString(e.getValue()));
  }
  return sb.toString();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:15,代碼來源:QuorumCall.java

示例7: getSegmentInfo

import com.google.protobuf.TextFormat; //導入依賴的package包/類
/**
 * @return the current state of the given segment, or null if the
 * segment does not exist.
 */
@VisibleForTesting
SegmentStateProto getSegmentInfo(long segmentTxId)
    throws IOException {
  EditLogFile elf = fjm.getLogFile(segmentTxId);
  if (elf == null) {
    return null;
  }
  if (elf.isInProgress()) {
    elf.scanLog();
  }
  if (elf.getLastTxId() == HdfsConstants.INVALID_TXID) {
    LOG.info("Edit log file " + elf + " appears to be empty. " +
        "Moving it aside...");
    elf.moveAsideEmptyFile();
    return null;
  }
  SegmentStateProto ret = SegmentStateProto.newBuilder()
      .setStartTxId(segmentTxId)
      .setEndTxId(elf.getLastTxId())
      .setIsInProgress(elf.isInProgress())
      .build();
  LOG.info("getSegmentInfo(" + segmentTxId + "): " + elf + " -> " +
      TextFormat.shortDebugString(ret));
  return ret;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:30,代碼來源:Journal.java

示例8: replayWALFlushCannotFlushMarker

import com.google.protobuf.TextFormat; //導入依賴的package包/類
private void replayWALFlushCannotFlushMarker(FlushDescriptor flush, long replaySeqId) {
  synchronized (writestate) {
    if (this.lastReplayedOpenRegionSeqId > replaySeqId) {
      LOG.warn(getRegionInfo().getEncodedName() + " : " + "Skipping replaying flush event :"
          + TextFormat.shortDebugString(flush) + " because its sequence id " + replaySeqId
          + " is smaller than this regions " + "lastReplayedOpenRegionSeqId of "
          + lastReplayedOpenRegionSeqId);
      return;
    }

    // If we were waiting for observing a flush or region opening event for
    // not showing partial
    // data after a secondary region crash, we can allow reads now. This event
    // means that the
    // primary was not able to flush because memstore is empty when we
    // requested flush. By the
    // time we observe this, we are guaranteed to have up to date seqId with
    // our previous
    // assignment.
    this.setReadsEnabled(true);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:23,代碼來源:HRegion.java

示例9: register

import com.google.protobuf.TextFormat; //導入依賴的package包/類
@Override public Optional<Group> register(Group group) {
  logger.info("{} /group[{}]", kvp("op", "register"), TextFormat.shortDebugString(group));
  new GroupValidator().validateRegistrationThrowing(group);
  final Optional<Group> registration = processRegistration(group);

  registration.ifPresent(this::addToCache);
  return registration;
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:9,代碼來源:DefaultGroupService.java

示例10: add

import com.google.protobuf.TextFormat; //導入依賴的package包/類
@Override public Group add(Group group, MemberAccess member) {
  logger.info("{} /group[{}]/mbr[{}]", kvp("op", "add.member"),
      TextFormat.shortDebugString(group), TextFormat.shortDebugString(member));

  final Group update = processUpdate(group,
      builder -> {
        AccessCollection.Builder accessBuilder = newGrantCollectionBuilder();
        accessBuilder.addAllMembers(groupUpdateProcessor.mergeMembers(group, member));
        accessBuilder.addAllServices(group.getGranted().getServicesList());
        builder.setGranted(accessBuilder.buildPartial());
      });
  addToCache(update);
  return update;
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:15,代碼來源:DefaultGroupService.java

示例11: writeBulkLoadMarkerAndSync

import com.google.protobuf.TextFormat; //導入依賴的package包/類
/**
 * Write a log marker that a bulk load has succeeded and is about to be committed.
 *
 * @param wal        The log to write into.
 * @param htd        A description of the table that we are bulk loading into.
 * @param hri       A description of the region in the table that we are bulk loading into.
 * @param desc A protocol buffers based description of the client's bulk loading request
 * @return txid of this transaction or if nothing to do, the last txid
 * @throws IOException We will throw an IOException if we can not append to the HLog.
 */
public static long writeBulkLoadMarkerAndSync(final WAL wal, final HTableDescriptor htd,
    final HRegionInfo hri, final WALProtos.BulkLoadDescriptor desc,
    final MultiVersionConcurrencyControl mvcc)
throws IOException {
  long trx = writeMarker(wal, htd, hri, WALEdit.createBulkLoadEvent(hri, desc), mvcc, true);
  if (LOG.isTraceEnabled()) {
    LOG.trace("Appended Bulk Load marker " + TextFormat.shortDebugString(desc));
  }
  return trx;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:21,代碼來源:WALUtil.java

示例12: toBuildFarmServerConfig

import com.google.protobuf.TextFormat; //導入依賴的package包/類
private static BuildFarmServerConfig toBuildFarmServerConfig(InputStream inputStream, BuildFarmServerOptions options) throws IOException {
  BuildFarmServerConfig.Builder builder = BuildFarmServerConfig.newBuilder();
  String data = new String(Encoding.convertFromLatin1(ByteStreams.toByteArray(inputStream)));
  TextFormat.merge(data, builder);
  if (options.port > 0) {
      builder.setPort(options.port);
  }
  return builder.build();
}
 
開發者ID:bazelbuild,項目名稱:bazel-buildfarm,代碼行數:10,代碼來源:BuildFarmServer.java

示例13: unescape

import com.google.protobuf.TextFormat; //導入依賴的package包/類
private static ByteString unescape(String toUnescape) {
    try {
        return TextFormat.unescapeBytes(toUnescape);
    } catch (TextFormat.InvalidEscapeSequenceException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:ocraft,項目名稱:ocraft-s2client,代碼行數:8,代碼來源:Images.java

示例14: read

import com.google.protobuf.TextFormat; //導入依賴的package包/類
static EditLogLedgerMetadata read(ZooKeeper zkc, String path)
    throws IOException, KeeperException.NoNodeException  {
  try {
    byte[] data = zkc.getData(path, false, null);

    EditLogLedgerProto.Builder builder = EditLogLedgerProto.newBuilder();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Reading " + path + " data: " + new String(data, UTF_8));
    }
    TextFormat.merge(new String(data, UTF_8), builder);
    if (!builder.isInitialized()) {
      throw new IOException("Invalid/Incomplete data in znode");
    }
    EditLogLedgerProto ledger = builder.build();

    int dataLayoutVersion = ledger.getDataLayoutVersion();
    long ledgerId = ledger.getLedgerId();
    long firstTxId = ledger.getFirstTxId();
    if (ledger.hasLastTxId()) {
      long lastTxId = ledger.getLastTxId();
      return new EditLogLedgerMetadata(path, dataLayoutVersion,
                                       ledgerId, firstTxId, lastTxId);
    } else {
      return new EditLogLedgerMetadata(path, dataLayoutVersion,
                                       ledgerId, firstTxId);
    }
  } catch(KeeperException.NoNodeException nne) {
    throw nne;
  } catch(KeeperException ke) {
    throw new IOException("Error reading from zookeeper", ke);
  } catch (InterruptedException ie) {
    throw new IOException("Interrupted reading from zookeeper", ie);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:35,代碼來源:EditLogLedgerMetadata.java

示例15: toWorkerConfig

import com.google.protobuf.TextFormat; //導入依賴的package包/類
private static WorkerConfig toWorkerConfig(InputStream inputStream, WorkerOptions options) throws IOException {
  WorkerConfig.Builder builder = WorkerConfig.newBuilder();
  String data = new String(Encoding.convertFromLatin1(ByteStreams.toByteArray(inputStream)));
  TextFormat.merge(data, builder);
  if (!Strings.isNullOrEmpty(options.root)) {
    builder.setRoot(options.root);
  }

  if (!Strings.isNullOrEmpty(options.casCacheDirectory)) {
    builder.setCasCacheDirectory(options.casCacheDirectory);
  }
  return builder.build();
}
 
開發者ID:bazelbuild,項目名稱:bazel-buildfarm,代碼行數:14,代碼來源:Worker.java


注:本文中的com.google.protobuf.TextFormat類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。