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


Java Descriptors.DescriptorValidationException方法代碼示例

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


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

示例1: decodeProtobuf

import com.google.protobuf.Descriptors; //導入方法依賴的package包/類
/**
 * Handle all the logic leading to the decoding of a Protobuf-encoded binary given a schema file path.
 * @param schema  Schema used to decode the binary data
 * @param messageType   Type of Protobuf Message
 * @param encodedData   Encoded data source
 * @return  A JSON representation of the data, contained in a Java String
 * @throws InvalidProtocolBufferException   Thrown when an error occurs during the encoding of the decoded data into JSON
 * @throws Descriptors.DescriptorValidationException    Thrown when the schema is invalid
 * @throws UnknownMessageTypeException  Thrown when the given message type is not contained in the schema
 * @throws MessageDecodingException Thrown when an error occurs during the binary decoding
 * @throws SchemaLoadingException   Thrown when an error occurs while reading the schema file
 */
public static String decodeProtobuf(DynamicSchema schema, String messageType, InputStream encodedData) throws InvalidProtocolBufferException, Descriptors.DescriptorValidationException, UnknownMessageTypeException, MessageDecodingException, SchemaLoadingException {
    Descriptors.Descriptor descriptor;
    DynamicMessage message;

    descriptor = schema.getMessageDescriptor(messageType);

    if (descriptor == null) {
        throw new UnknownMessageTypeException(messageType);
    }

    try {
        message = DynamicMessage.parseFrom(descriptor, encodedData);
    } catch (IOException e) {
        throw new MessageDecodingException(e);
    }

    return JSONMapper.toJSON(message);
}
 
開發者ID:whiver,項目名稱:nifi-protobuf-processor,代碼行數:31,代碼來源:ProtobufService.java

示例2: ProtobufDataParser

import com.google.protobuf.Descriptors; //導入方法依賴的package包/類
public ProtobufDataParser(
    ProtoConfigurableEntity.Context context,
    String messageId,
    Descriptors.Descriptor descriptor,
    Map<String, Set<Descriptors.FieldDescriptor>> messageTypeToExtensionMap,
    ExtensionRegistry extensionRegistry,
    InputStream inputStream,
    String readerOffset,
    int maxObjectLength,
    boolean isDelimited
) throws IOException, Descriptors.DescriptorValidationException, DataParserException {
  this.context = context;
  this.inputStream = new OverrunInputStream(inputStream, maxObjectLength, true);
  this.messageId = messageId;
  this.messageTypeToExtensionMap = messageTypeToExtensionMap;
  this.extensionRegistry = extensionRegistry;
  this.descriptor = descriptor;
  this.builder = DynamicMessage.newBuilder(descriptor);
  this.isDelimited = isDelimited;

  // skip to the required location
  if (readerOffset != null && !readerOffset.isEmpty() && !readerOffset.equals("0")) {
    int offset = Integer.parseInt(readerOffset);
    this.inputStream.skip(offset);
  }
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:27,代碼來源:ProtobufDataParser.java

示例3: getParser

import com.google.protobuf.Descriptors; //導入方法依賴的package包/類
@Override
public DataParser getParser(String id, InputStream is, String offset) throws DataParserException {
  try {
    return new ProtobufDataParser(
        getSettings().getContext(),
        id,
        descriptor,
        messageTypeToExtensionMap,
        extensionRegistry,
        is,
        offset,
        getSettings().getOverRunLimit(),
        isDelimited
    );
  } catch (IOException | Descriptors.DescriptorValidationException e) {
    throw new DataParserException(Errors.DATA_PARSER_01, e.toString(), e);
  }
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:19,代碼來源:ProtobufDataParserFactory.java

示例4: test

import com.google.protobuf.Descriptors; //導入方法依賴的package包/類
@Test
public void test () throws IOException, Descriptors.DescriptorValidationException
{
    Configuration conf = new Configuration();
    System.setProperty("hadoop.home.dir", "/");
    FileSystem fileSystem = FileSystem.get(URI.create("hdfs://presto00:9000"), conf);
    Path hdfsDirPath = new Path("/rainbow2/orc_new_compress");
    System.out.println(fileSystem.isFile(hdfsDirPath));
    FileStatus[] fileStatuses = fileSystem.listStatus(hdfsDirPath);
    System.out.println(fileStatuses.length);
    for (FileStatus status : fileStatuses)
    {
        status.getPath();
        System.out.println(status.getPath() + ", " + status.getLen());
    }

    Reader reader = OrcFile.createReader(fileStatuses[0].getPath(),
            OrcFile.readerOptions(conf));
    System.out.println("file length:" + reader.getFileTail().getFileLength());
    List<String> columnNames = new ArrayList<>();
    columnNames.add("samplepercent");
    System.out.println(reader.getRawDataSizeOfColumns(columnNames));
    System.out.println(reader.getFileTail().getFooter().getTypes(0).getFieldNames(0));
    System.out.println(reader.getTypes().get(0).getSerializedSize());

    List<Reader> readers = new ArrayList<>();
    for (FileStatus fileStatus : fileStatuses)
    {
        Reader reader1 = OrcFile.createReader(fileStatus.getPath(),
                OrcFile.readerOptions(conf));
        readers.add(reader1);
        System.out.println("content size: " + reader1.getContentLength() + ", raw size: "
        + reader1.getRawDataSize());
    }

    for (String columnName : reader.getSchema().getFieldNames())
    {
        System.out.println(columnName);
    }
}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:41,代碼來源:TestOrcMetadata.java

示例5: provideProtoTypeProvider

import com.google.protobuf.Descriptors; //導入方法依賴的package包/類
/**
 * Register the proto descriptors bundled with the application JAR so that
 * the SoyTypeRegistry can map proto names in Soy code to protobuf
 * definitions.
 */
@Provides
@Singleton
public SoyProtoTypeProvider provideProtoTypeProvider()
throws IOException, Descriptors.DescriptorValidationException {
  SoyProtoTypeProvider.Builder b = new SoyProtoTypeProvider.Builder();
  URL pdUrl = getClass().getResource(PROTO_DESCRIPTORS_RESOURCE_PATH);
  if (pdUrl != null) {
    ByteSource descriptorBytes = Resources.asByteSource(pdUrl);
    b.addFileDescriptorSetFromByteSource(descriptorBytes);
  }
  return b.build();
}
 
開發者ID:mikesamuel,項目名稱:closure-maven-plugin,代碼行數:18,代碼來源:ClosureModule.java

示例6: getAllFileDescriptors

import com.google.protobuf.Descriptors; //導入方法依賴的package包/類
/**
 * Loads a Protobuf file descriptor set into an ubermap of file descriptors.
 *
 * @param set               FileDescriptorSet
 * @param dependenciesMap   FileDescriptor dependency map
 * @param fileDescriptorMap The populated map of FileDescriptors
 * @throws StageException
 */
public static void getAllFileDescriptors(
    DescriptorProtos.FileDescriptorSet set,
    Map<String, Set<Descriptors.FileDescriptor>> dependenciesMap,
    Map<String, Descriptors.FileDescriptor> fileDescriptorMap
) throws StageException {
  List<DescriptorProtos.FileDescriptorProto> fileList = set.getFileList();
  try {
    for (DescriptorProtos.FileDescriptorProto fdp : fileList) {
      if (!fileDescriptorMap.containsKey(fdp.getName())) {
        Set<Descriptors.FileDescriptor> dependencies = dependenciesMap.get(fdp.getName());
        if (dependencies == null) {
          dependencies = new LinkedHashSet<>();
          dependenciesMap.put(fdp.getName(), dependencies);
          dependencies.addAll(getDependencies(dependenciesMap, fileDescriptorMap, fdp, set));
        }
        Descriptors.FileDescriptor fileDescriptor = Descriptors.FileDescriptor.buildFrom(
            fdp,
            dependencies.toArray(new Descriptors.FileDescriptor[dependencies.size()])
        );
        fileDescriptorMap.put(fdp.getName(), fileDescriptor);
      }
    }
  } catch (Descriptors.DescriptorValidationException e) {
    throw new StageException(Errors.PROTOBUF_07, e.getDescription(), e);
  }
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:35,代碼來源:ProtobufTypeUtil.java

示例7: getDependencies

import com.google.protobuf.Descriptors; //導入方法依賴的package包/類
private static Set<Descriptors.FileDescriptor> getDependencies(
    Map<String, Set<Descriptors.FileDescriptor>> dependenciesMap,
    Map<String, Descriptors.FileDescriptor> fileDescriptorMap,
    DescriptorProtos.FileDescriptorProto file,
    DescriptorProtos.FileDescriptorSet set
) throws StageException {
  Set<Descriptors.FileDescriptor> result = new LinkedHashSet<>();
  for (String name : file.getDependencyList()) {
    DescriptorProtos.FileDescriptorProto fileDescriptorProto = null;
    for (DescriptorProtos.FileDescriptorProto fdp : set.getFileList()) {
      if (name.equals(fdp.getName())) {
        fileDescriptorProto = fdp;
        break;
      }
    }
    if (fileDescriptorProto == null) {
      // could not find the message type from all the proto files contained in the descriptor file
      throw new StageException(Errors.PROTOBUF_01, file.getName());
    }
    Descriptors.FileDescriptor fileDescriptor;
    if (fileDescriptorMap.containsKey(fileDescriptorProto.getName())) {
      fileDescriptor = fileDescriptorMap.get(fileDescriptorProto.getName());
    } else {
      Set<Descriptors.FileDescriptor> deps = new LinkedHashSet<>();
      if (dependenciesMap.containsKey(name)) {
        deps.addAll(dependenciesMap.get(name));
      } else {
        deps.addAll(getDependencies(dependenciesMap, fileDescriptorMap, fileDescriptorProto, set));
      }
      try {
        fileDescriptor = Descriptors.FileDescriptor.buildFrom(
            fileDescriptorProto,
            deps.toArray(new Descriptors.FileDescriptor[deps.size()])
        );
      } catch (Descriptors.DescriptorValidationException e) {
        throw new StageException(Errors.PROTOBUF_07, e.getDescription(), e);
      }
    }
    result.add(fileDescriptor);
  }
  return result;
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:43,代碼來源:ProtobufTypeUtil.java

示例8: encodeProtobuf

import com.google.protobuf.Descriptors; //導入方法依賴的package包/類
/**
 * Handle all the logic leading to the encoding of a Protobuf-encoded binary given a schema file path and a JSON
 * data file.
 * @param pathToSchema  Path to the .desc schema file on disk
 * @param messageType   Type of Protobuf Message
 * @param jsonData      Data to encode, structured in a JSON format
 * @param binaryOutput  The stream where to output the encoded data
 * @throws Descriptors.DescriptorValidationException    Thrown when the schema is invalid
 * @throws IOException  Thrown when an errors occurs while parsing the JSON data
 * @throws MessageEncodingException Thrown when an error occurs during the binary encoding
 * @throws UnknownMessageTypeException  Thrown when the given message type is not contained in the schema
 * @throws SchemaLoadingException   Thrown when an error occurs while reading the schema file
 */
public static void encodeProtobuf(String pathToSchema, String messageType, InputStream jsonData, OutputStream binaryOutput) throws Descriptors.DescriptorValidationException, IOException, MessageEncodingException, UnknownMessageTypeException, SchemaLoadingException {
    DynamicSchema schema;

    try {
        FileInputStream schemaFile = new FileInputStream(pathToSchema);
        schema = DynamicSchema.parseFrom(schemaFile);
    } catch (IOException e) {
        throw new SchemaLoadingException(e);
    }

    encodeProtobuf(schema, messageType, jsonData, binaryOutput);
}
 
開發者ID:whiver,項目名稱:nifi-protobuf-processor,代碼行數:26,代碼來源:ProtobufService.java


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