private static void write(ContextFactory factory, SourceFile file) { try { RuntimeModel model = factory.create(file.getInputPath()).getModel(); String source = generator.generate(file, model); Files.createDirectories(file.getOutputPath().getParent()); Files.write( file.getOutputPath(), source.getBytes(Charset.forName("UTF-8")), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } catch (Throwable t) { throw new CodeGeneratorException(t); } }