本文整理匯總了Java中com.google.protobuf.TextFormat.merge方法的典型用法代碼示例。如果您正苦於以下問題:Java TextFormat.merge方法的具體用法?Java TextFormat.merge怎麽用?Java TextFormat.merge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.protobuf.TextFormat
的用法示例。
在下文中一共展示了TextFormat.merge方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
}
示例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);
}
示例3: 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);
}
}
示例4: 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();
}
示例5: 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();
}
示例6: run
import com.google.protobuf.TextFormat; //導入方法依賴的package包/類
@Override
public void run()
{
try
{
URL url = new URL(urlStr);
HttpURLConnection myURLConnection = (HttpURLConnection)url.openConnection();
if (headers != null && headers.length > 0)
{
for (int i = 0; i < headers.length; i++)
{
String[] nameValue = headers[i].split(":");
myURLConnection.setRequestProperty (nameValue[0], nameValue[1]);
}
}
//myURLConnection.setRequestProperty ("Authorization", basicAuth);
//String userCredentials = "username:password";
//String basicAuth = "Basic " + new String(new Base64().encode(userCredentials.getBytes()));
//myURLConnection.setRequestProperty ("Authorization", basicAuth);
//myURLConnection.setRequestMethod("POST");
//myURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//myURLConnection.setRequestProperty("Content-Length", "" + postData.getBytes().length);
//myURLConnection.setRequestProperty("Content-Language", "en-US");
//myURLConnection.setUseCaches(false);
//myURLConnection.setDoInput(true);
//myURLConnection.setDoOutput(true);
FeedMessage feed;
if (isTextFormat == true)
{
InputStream inputStream = myURLConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(inputStream);
FeedMessage.Builder myProtoBuilder = FeedMessage.newBuilder();
TextFormat.merge(reader, myProtoBuilder);
feed = myProtoBuilder.build();
}
else {
feed = FeedMessage.parseFrom(myURLConnection.getInputStream());
//feed = FeedMessage.parseFrom(url.openStream());
}
long headerTimestamp = feed.getHeader().getTimestamp();
for (FeedEntity entity : feed.getEntityList())
{
if (entity.hasVehicle())
{
getVehiclesAndSendGeoEvents(entity, headerTimestamp);
}
if (entity.hasAlert())
{
getAlertsAndSendGeoEvents(entity, headerTimestamp);
}
if (entity.hasTripUpdate())
{
getTripUpdatesAndSendGeoEvents(entity, headerTimestamp);
}
} // for
}
catch (IOException e)
{
LOGGER.error(e.getMessage());
}
}