本文整理汇总了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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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;
}
示例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);
}