use of org.spf4j.io.SetFilesReadOnlyVisitor in project spf4j by zolyfarkas.
the class GenericRecordBuilder method generateClasses.
private void generateClasses(final GenericData.StringType st, final Schema... schemas) {
String[] namespaces = new String[schemas.length];
for (int i = 0; i < schemas.length; i++) {
String namespace = schemas[i].getNamespace();
if (namespace == null) {
namespace = "";
}
namespaces[i] = namespace;
}
String commonPrefix = org.spf4j.base.Strings.commonPrefix(namespaces);
if (commonPrefix.endsWith(".")) {
commonPrefix = commonPrefix.substring(0, commonPrefix.length() - 1);
}
Protocol proto = new Protocol("generated", commonPrefix);
proto.setTypes(Arrays.asList(schemas));
SpecificCompiler sc = new SpecificCompiler(proto);
sc.setStringType(st);
// use a custom template that does not contain the builder (janino can't compile builder).
sc.setTemplateDir("org/spf4j/avro/");
sc.setFieldVisibility(SpecificCompiler.FieldVisibility.PRIVATE);
try {
sc.compileToDestination(null, tmpDir);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
try {
Files.walkFileTree(tmpDir.toPath(), new SetFilesReadOnlyVisitor());
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
Aggregations