/**
  * create file
  *
  * @param string|Charcoal_String $contents
  * @param Charcoal_File $dir
  * @param string|Charcoal_String $file_name
  *
  * @return Charcoal_File
  */
 public function create($contents, $dir = null, $file_name = null)
 {
     if ($file_name === null) {
         $tmp_filename = Charcoal_System::hash() . '.tmp';
     }
     if ($dir === null) {
         $dir = Charcoal_ResourceLocator::getFile($this->getSandbox()->getEnvironment(), "%TMP_DIR%");
     }
     $tmp_file = new Charcoal_File($file_name, $dir);
     if ($tmp_file->isDirectory()) {
         _throw(new Charcoal_FileSystemComponentException('specified path is directory.'));
     }
     if ($tmp_file->exists()) {
         _throw(new Charcoal_FileSystemComponentException('specified file is already exists.'));
     }
     if ($this->overwrite) {
         if ($tmp_file->exists() && !$tmp_file->canWrite()) {
             _throw(new Charcoal_FileSystemComponentException('specified file is not writeable.'));
         }
     }
     try {
         // create file
         $tmp_file->makeFile($this->mode, $contents, TRUE);
         $this->file = $tmp_file;
         return $tmp_file;
     } catch (Exception $e) {
         _catch($e);
         _throw(new Charcoal_TempFileComponentException(s('creating file failed.'), $e));
     }
     return null;
 }