org.apache.avro.io.parsing.ResolvingGrammarGenerator Java Examples

The following examples show how to use org.apache.avro.io.parsing.ResolvingGrammarGenerator. 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: Avro14Adapter.java    From avro-util with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Avro14Adapter() throws Exception {
  super(
      GenericData.EnumSymbol.class.getConstructor(String.class),
      GenericData.Fixed.class.getConstructor(byte[].class)
  );
  _binaryEncoderCtr = BinaryEncoder.class.getConstructor(OutputStream.class);
  Class<?> compilerClass = Class.forName("org.apache.avro.specific.SpecificCompiler");
  _specificCompilerCtr = compilerClass.getConstructor(Schema.class);
  _compilerEnqueueMethod = compilerClass.getDeclaredMethod("enqueue", Schema.class);
  _compilerEnqueueMethod.setAccessible(true); //its normally private
  _compilerCompileMethod = compilerClass.getDeclaredMethod("compile");
  _compilerCompileMethod.setAccessible(true); //package-protected
  Class<?> outputFileClass = Class.forName("org.apache.avro.specific.SpecificCompiler$OutputFile");
  _outputFilePathField = outputFileClass.getDeclaredField("path");
  _outputFilePathField.setAccessible(true);
  _outputFileContentsField = outputFileClass.getDeclaredField("contents");
  _outputFileContentsField.setAccessible(true);
  _schemaParseMethod = Schema.class.getDeclaredMethod("parse", String.class);
  _encodeJsonNode = ResolvingGrammarGenerator.class.getDeclaredMethod("encode", Encoder.class, Schema.class, JsonNode.class);
  _encodeJsonNode.setAccessible(true); //package-private
}
 
Example #2
Source File: SchemaValidationUtil.java    From kite with Apache License 2.0 5 votes vote down vote up
public static boolean canRead(Schema writtenWith, Schema readUsing) {
  try {
    return !hasErrors(new ResolvingGrammarGenerator().generate(
        writtenWith, readUsing));
  } catch (IOException e) {
    return false;
  }
}