Package org.apache.avro.compiler.specific

Examples of org.apache.avro.compiler.specific.SpecificCompiler


    }
  }

  @Test
  public void testSettingOutputCharacterEncoding() throws Exception {
    SpecificCompiler compiler = createCompiler();
    // Generated file in default encoding
    compiler.compileToDestination(this.src, this.outputDir);
    byte[] fileInDefaultEncoding = new byte[(int) this.outputFile.length()];
    new FileInputStream(this.outputFile).read(fileInDefaultEncoding);
    this.outputFile.delete();
    // Generate file in another encoding (make sure it has different number of bytes per character)
    String differentEncoding = Charset.defaultCharset().equals(Charset.forName("UTF-16")) ? "UTF-32" : "UTF-16";
    compiler.setOutputCharacterEncoding(differentEncoding);
    compiler.compileToDestination(this.src, this.outputDir);
    byte[] fileInDifferentEncoding = new byte[(int) this.outputFile.length()];
    new FileInputStream(this.outputFile).read(fileInDifferentEncoding);
    // Compare as bytes
    assertThat("Generated file should contain different bytes after setting non-default encoding",
      fileInDefaultEncoding, not(equalTo(fileInDifferentEncoding)));
View Full Code Here


    String schemaSrcPath = "src/test/resources/simple_record.avsc";
    String velocityTemplateDir = "src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/";
    File src = new File(schemaSrcPath);
    Schema.Parser parser = new Schema.Parser();
    Schema schema = parser.parse(src);
    SpecificCompiler compiler = new SpecificCompiler(schema);
    compiler.setTemplateDir(velocityTemplateDir);
    compiler.setStringType(StringType.CharSequence);
    File outputDir = AvroTestUtil.tempDirectory(getClass(), "specific-output");
    compiler.compileToDestination(src, outputDir);
    assertTrue(new File(outputDir, "SimpleRecord.java").exists());
  }
View Full Code Here

    Idl parser = new Idl(new File(sourceDirectory, filename));
    try {
      Protocol p = parser.CompilationUnit();
      String json = p.toString(true);
      Protocol protocol = Protocol.parse(json);
      SpecificCompiler compiler = new SpecificCompiler(protocol);
      compiler.compileToDestination(null, outputDirectory);
    } catch (ParseException e) {
      throw new IOException(e);
    }
  }
View Full Code Here

      schema = new Schema.Parser().parse(src);
    } else {
      schema = schemaParser.parse(src);
    }
   
    SpecificCompiler compiler = new SpecificCompiler(schema);
    compiler.setTemplateDir(templateDirectory);
    compiler.setStringType(StringType.valueOf(stringType));
    compiler.setFieldVisibility(getFieldVisibility());
    compiler.setCreateSetters(createSetters);
    compiler.compileToDestination(src, outputDirectory);
  }
View Full Code Here

 
  @Override
  protected void doCompile(String filename, File sourceDirectory, File outputDirectory) throws IOException {
    File src = new File(sourceDirectory, filename);
    Protocol protocol = Protocol.parse(src);
    SpecificCompiler compiler = new SpecificCompiler(protocol);
    compiler.setTemplateDir(templateDirectory);
    compiler.setStringType(StringType.valueOf(stringType));
    compiler.setFieldVisibility(getFieldVisibility());
    compiler.setCreateSetters(createSetters);
    compiler.compileToDestination(src, outputDirectory);
  }
View Full Code Here

      }

      Protocol p = parser.CompilationUnit();
      String json = p.toString(true);
      Protocol protocol = Protocol.parse(json);
      SpecificCompiler compiler = new SpecificCompiler(protocol);
      compiler.setStringType(GenericData.StringType.valueOf(stringType));
      compiler.setTemplateDir(templateDirectory);
      compiler.setFieldVisibility(getFieldVisibility());
      compiler.setCreateSetters(createSetters);
      compiler.compileToDestination(null, outputDirectory);
    } catch (ParseException e) {
      throw new IOException(e);
    } catch (DependencyResolutionRequiredException drre) {
      throw new IOException(drre);
    }
View Full Code Here

    Idl parser = new Idl(new File(sourceDirectory, filename));
    try {
      Protocol p = parser.CompilationUnit();
      String json = p.toString(true);
      Protocol protocol = Protocol.parse(json);
      SpecificCompiler compiler = new SpecificCompiler(protocol);
      compiler.compileToDestination(null, outputDirectory);
    } catch (ParseException e) {
      throw new IOException(e);
    }
  }
View Full Code Here

    String schemaSrcPath = "src/test/resources/simple_record.avsc";
    String velocityTemplateDir = "src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/";
    File src = new File(schemaSrcPath);
    Schema.Parser parser = new Schema.Parser();
    Schema schema = parser.parse(src);
    SpecificCompiler compiler = new SpecificCompiler(schema);
    compiler.setTemplateDir(velocityTemplateDir);
    compiler.setStringType(StringType.CharSequence);
    File outputDir = File.createTempFile("avro-tmp", "");
    outputDir.delete();
    outputDir.mkdir();
    compiler.compileToDestination(src, outputDir);
    new File(outputDir, "SimpleRecord.java").delete();
  }
View Full Code Here

      schema = new Schema.Parser().parse(src);
    } else {
      schema = schemaParser.parse(src);
    }
   
    SpecificCompiler compiler = new SpecificCompiler(schema);
    compiler.setTemplateDir(templateDirectory);
    compiler.setStringType(StringType.valueOf(stringType));
    compiler.setFieldVisibility(getFieldVisibility());
    compiler.setCreateSetters(createSetters);
    compiler.compileToDestination(src, outputDirectory);
  }
View Full Code Here

      }

      Protocol p = parser.CompilationUnit();
      String json = p.toString(true);
      Protocol protocol = Protocol.parse(json);
      SpecificCompiler compiler = new SpecificCompiler(protocol);
      compiler.setStringType(GenericData.StringType.valueOf(stringType));
      compiler.setTemplateDir(templateDirectory);
      compiler.setFieldVisibility(getFieldVisibility());
      compiler.setCreateSetters(createSetters);
      compiler.compileToDestination(null, outputDirectory);
    } catch (ParseException e) {
      throw new IOException(e);
    } catch (DependencyResolutionRequiredException drre) {
      throw new IOException(drre);
    }
View Full Code Here

TOP

Related Classes of org.apache.avro.compiler.specific.SpecificCompiler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.