Java Code Examples for com.google.protobuf.TextFormat#Parser

The following examples show how to use com.google.protobuf.TextFormat#Parser . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TFTrainer.java    From OpenLabeler with Apache License 2.0 6 votes vote down vote up
private Pipeline.TrainEvalPipelineConfig parse(Path path) {
    try {
        String text = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
        Pipeline.TrainEvalPipelineConfig.Builder builder = Pipeline.TrainEvalPipelineConfig.newBuilder();
        TextFormat.Parser parser = TextFormat.Parser.newBuilder().build();

        // Skip unknown fields
        Field f = parser.getClass().getDeclaredField("allowUnknownFields");
        f.setAccessible(true);
        f.set(parser, true);

        parser.merge(text, builder);
        return builder.build();
    }
    catch (Exception ex) {
        LOG.log(Level.SEVERE, "Unable to parse pipeline", ex);
    }
    return null;
}
 
Example 2
Source File: IntellijAspectTestFixtureBuilder.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static TargetIdeInfo readAspectFile(File file) throws IOException {
  try (InputStream inputStream = new FileInputStream(file)) {
    TargetIdeInfo.Builder builder = TargetIdeInfo.newBuilder();
    TextFormat.Parser parser = TextFormat.Parser.newBuilder().build();
    parser.merge(new InputStreamReader(inputStream, UTF_8), builder);
    return builder.build();
  }
}
 
Example 3
Source File: FastBuildAspectTestFixtureBuilder.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static FastBuildBlazeData parseData(File file) throws IOException {
  try (InputStream inputStream = new FileInputStream(file)) {
    FastBuildBlazeData.Builder builder = FastBuildBlazeData.newBuilder();
    TextFormat.Parser parser = TextFormat.Parser.newBuilder().build();
    parser.merge(new InputStreamReader(inputStream, UTF_8), builder);
    return builder.build();
  }
}