private Writer initWriter(File file,Charset encoding,boolean append) throws IOException {
  boolean fileExistedAlready=file.exists();
  OutputStream stream=null;
  Writer writer=null;
  try {
    stream=new FileOutputStream(file.getAbsolutePath(),append);
    writer=new OutputStreamWriter(stream,Charsets.toCharset(encoding));
  }
 catch (  IOException ex) {
    IOUtils.closeQuietly(writer);
    IOUtils.closeQuietly(stream);
    FileUtils.deleteQuietly(lockFile);
    if (fileExistedAlready == false) {
      FileUtils.deleteQuietly(file);
    }
    throw ex;
  }
catch (  RuntimeException ex) {
    IOUtils.closeQuietly(writer);
    IOUtils.closeQuietly(stream);
    FileUtils.deleteQuietly(lockFile);
    if (fileExistedAlready == false) {
      FileUtils.deleteQuietly(file);
    }
    throw ex;
  }
  return writer;
}

private Writer initWriter ( File file , Charset encoding , boolean append ) throws IOException { boolean fileExistedAlready = file . exists ( ) ; OutputStream stream = null ; Writer writer = null ; try { stream = new FileOutputStream ( file . getAbsolutePath ( ) , append ) ; writer = new OutputStreamWriter ( stream , Charsets . toCharset ( encoding ) ) ; } catch ( IOException ex ) { IOUtils . closeQuietly ( writer ) ; IOUtils . closeQuietly ( stream ) ; FileUtils . deleteQuietly ( lockFile ) ; if ( fileExistedAlready == false ) { FileUtils . deleteQuietly ( file ) ; } throw ex ; } catch ( RuntimeException ex ) { IOUtils . closeQuietly ( writer ) ; IOUtils . closeQuietly ( stream ) ; FileUtils . deleteQuietly ( lockFile ) ; if ( fileExistedAlready == false ) { FileUtils . deleteQuietly ( file ) ; } throw ex ; } return writer ; }
initialise the wrapped file writer . ensure that a cleanup occurs if the writer creation fails .
