private static void saveTemplate(File parentDir,FileTemplateBase template,final String lineSeparator) throws IOException {
  final File templateFile=new File(parentDir,encodeFileName(template.getName(),template.getExtension()));
  FileOutputStream fileOutputStream;
  try {
    fileOutputStream=new FileOutputStream(templateFile);
  }
 catch (  FileNotFoundException e) {
    FileUtil.delete(templateFile);
    fileOutputStream=new FileOutputStream(templateFile);
  }
  OutputStreamWriter outputStreamWriter=new OutputStreamWriter(fileOutputStream,CharsetToolkit.UTF8_CHARSET);
  String content=template.getText();
  if (!lineSeparator.equals("\n")) {
    content=StringUtil.convertLineSeparators(content,lineSeparator);
  }
  outputStreamWriter.write(content);
  outputStreamWriter.close();
  fileOutputStream.close();
}

private static void saveTemplate ( File parentDir , FileTemplateBase template , final String lineSeparator ) throws IOException { final File templateFile = new File ( parentDir , encodeFileName ( template . getName ( ) , template . getExtension ( ) ) ) ; FileOutputStream fileOutputStream ; try { fileOutputStream = new FileOutputStream ( templateFile ) ; } catch ( FileNotFoundException e ) { FileUtil . delete ( templateFile ) ; fileOutputStream = new FileOutputStream ( templateFile ) ; } OutputStreamWriter outputStreamWriter = new OutputStreamWriter ( fileOutputStream , CharsetToolkit . UTF8_CHARSET ) ; String content = template . getText ( ) ; if ( ! lineSeparator . equals ( "\n" ) ) { content = StringUtil . convertLineSeparators ( content , lineSeparator ) ; } outputStreamWriter . write ( content ) ; outputStreamWriter . close ( ) ; fileOutputStream . close ( ) ; }
save template to file . if template is new , it is saved to specified directory . otherwise it is saved to file from which it was read . if template was not modified , it is not saved . todo : review saving algorithm
