コード例 #1
0
 public TaskTransfer(Config config, Model model, File fsrc, File ftarget, FileFilter fileFilter) {
   this.model = model;
   this.config = config;
   this.tables = model.getTables();
   this.fsrc = fsrc.getAbsolutePath();
   this.ftarget = ftarget.getAbsolutePath();
   this.packagepath = model.getPackageName().replace(".", File.separatorChar + "");
   this.tasks = new TaskLoader(fsrc, ftarget, fileFilter).loadTask();
   this.putTask(tasks);
 }
コード例 #2
0
  public String doTask() throws IOException, TemplateException {
    Task task = tasks.get(itask++);
    String path = task.getFile().getAbsolutePath();
    path = path.replace(fsrc, ftarget);
    path = path.replace("${packageName}", packagepath);
    File outfile = new File(path);

    StringBuilder log = new StringBuilder(path + "\r\n");
    if (task.getFile().getName().endsWith(".ftl")) {
      Template template = getTemplate(task.getFile());
      for (Table table : tables) {
        String outpath =
            outfile
                .getAbsolutePath()
                .replace(".ftl", "")
                .replace("${className}", table.getClassName());
        log.append("  =>>");
        log.append(outpath);
        log.append("\r\n");
        Writer out = getFileWriter(new File(outpath));
        model.bindTable(table);
        template.process(model, out);
        out.close();
      }
    } else if (FileUtil.isTextFile(task.getFile())) {
      log.append("  =>>");
      log.append(outfile.getAbsolutePath());
      log.append("\r\n");
      Template template = getTemplate(task.getFile());
      Writer out = getFileWriter(outfile);
      template.process(model, out);
      out.close();
    } else {
      log.append("  =>>");
      log.append(outfile.getAbsolutePath());
      log.append("\r\n");
      FileInputStream inputStream = new FileInputStream(task.getFile());
      FileOutputStream outputStream = new FileOutputStream(outfile);
      byte[] bytes = new byte[inputStream.available()];
      inputStream.read(bytes);
      outputStream.write(bytes);
      outputStream.close();
      inputStream.close();
      System.gc();
    }
    return log.toString();
  }