public function createFile($file_path, $contents, $overwrite = TRUE, $mode = 0777)
 {
     Charcoal_ParamTrait::validateString(1, $file_path);
     Charcoal_ParamTrait::validateString(2, $contents);
     Charcoal_ParamTrait::validateBoolean(3, $overwrite);
     Charcoal_ParamTrait::validateInteger(4, $mode);
     $obj = new Charcoal_File($file_path, $this->_base_dir_obj);
     if ($overwrite) {
         if ($obj->exists() && !$obj->canWrite()) {
             _throw(new Charcoal_FileSystemComponentException('specified file is not writeable.'));
         }
     } elseif ($obj->exists()) {
         _throw(new Charcoal_FileSystemComponentException('specified file is already exists.'));
     }
     try {
         // create file with parent directory
         $obj->makeFile($mode, $contents, TRUE);
         return $obj;
     } catch (Exception $e) {
         _catch($e);
         _throw(new Charcoal_FileSystemComponentException(s('creating file failed.'), $e));
     }
 }
 /**
  * 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;
 }