Saving data into a file (This method is used for huge files)

@param string $data The data to be written into the file
@param string $file The file to be used
191877
public function saveFile($data, $file)
    {
        $openfile = @fopen($file, "wb") or die("saveFile: Error opening file '{$file}'.");
        @fwrite($openfile, $data) or die("saveFile: Error writing data into file '{$file}'.");
        @fclose($openfile);
    }
387177
public function writeToPluginFile($file, $data)
    {
        $this->writeToFile(
            $this->config['plugins'] . Utils::unleadslashit($file),
            $data
        );
    }
831104
public static function write($file, $data, $lock = false) {
		return file_put_contents($file, $data, $lock ? LOCK_EX : 0);
	}
837896
public function write(string $data) : void
    {
        $this->buffer .= $data;

        if (strlen($this->buffer) >= $this->size) {
            $this->flush();
        }
    }
225253
private function writeFile($path, $data)
    {
        if (false === @file_put_contents($path, $data)) {
            throw new DumperException(sprintf('Unable to write file "%s"', $path));
        }
    }
1217064
private function write( string $file, $data, $append ): bool
	{
		if( function_exists('error_clear_last') )
		{
			error_clear_last();
		}

		// check directory exists or create empty directory for file
		$path = dirname($file);
		if( ! is_dir($path) )
		{
			try
			{
				if( ! @ mkdir($path, 0755, true) ) throw new WriteException("Cannot create the '{$path}' directory");
			}
			catch( \ErrorException $e )
			{
				return $this->getError($e);
			}
		}

		// check directory is writable
		if( ! is_writable($path) )
		{
			return $this->getError(new WriteFileException($file));
		}

		// detect write mode
		// ignore append flag if file is not exists
		$mode = "wa+";
		if( $append )
		{
			if( file_exists( $file ) )
			{
				$mode = "w";
			}
			else
			{
				$append = false;
			}
		}

		try {
			$handle = @ fopen( $file, $mode );
			if( ! $handle )
			{
				throw new WriteFileException($file,"Cannot open the '{$file}' file for write");
			}

			$callable = $data instanceof \Closure;
			if( flock( $handle, LOCK_EX ) )
			{
				if( $callable )
				{
					do
					{
						$content = $data( $append );
						if( ! is_string($content) || strlen($content) < 1 )
						{
							break;
						}
						if( fwrite( $handle, $content ) === false )
						{
							throw new WriteFileException($file);
						}
					}
					while(true);
				}
				else if( fwrite( $handle, $data ) === false )
				{
					throw new WriteFileException($file);
				}

				fflush( $handle );
				flock(  $handle, LOCK_UN );
			}
			else
			{
				throw new WriteFileException($file);
			}
		}
		catch( \ErrorException $e )
		{
			if( isset($handle) && ! $append && file_exists($file) )
			{
				@ unlink($file);
			}
			return $this->getError($e);
		}
		finally
		{
			if( isset($handle) )
			{
				fclose($handle);
			}
		}

		if( $this instanceof Loggable )
		{
			$this->addLogDebug("The '{$file}' file is successfully " . ($append ? "updated" : "created"));
		}

		return true;
	}
424834
public static void saveData(Map<String, List<double[]>> data, File file) throws IOException {

    BufferedWriter bw = new BufferedWriter(new FileWriter(file));

    for (Entry<String, List<double[]>> classEntry : data.entrySet()) {
      String classLabel = classEntry.getKey();
      for (double[] arr : classEntry.getValue()) {
        String arrStr = Arrays.toString(arr).replaceAll("[\\]\\[\\s]+", "");
        bw.write(classLabel + "," + arrStr + CR);
      }
    }

    bw.close();
  }
76227
public static function saveJson($path, $file, array $data)
    {
        $fp = fopen(self::cleanPath($path) . self::DS . $file . '.json', 'w');
        fwrite($fp, json_encode($data));

        return fclose($fp);
    }
728665
protected function saveToFile(string $data, string $file):bool{

		if(!\is_writable(\dirname($file))){
			throw new QRCodeOutputException('Could not write data to cache file: '.$file);
		}

		return (bool)\file_put_contents($file, $data);
	}
167334
public static function append(string $file = '', string $data = ''): bool
    {
        return static::write($file, $data, true);
    }
787377
public static function put(string $file, $data, bool $lock = false)
	{
		return file_put_contents($file, $data, $lock ? LOCK_EX : 0);
	}
1338192
public void save(File file) throws IOException {
        try (FileOutputStream out = new FileOutputStream(file)) {
            save(out);
        }
    }
1296539
public function save(array $data, $key)
    {
        $file = $this->getFilename($key);

        $saved = $this->get($key)->merge($data);

        if (! is_dir(dirname($file))) {
            mkdir(dirname($file), 0777, true);
        }
        file_put_contents($file, json_encode($saved->all()));
    }
1123467
public void save(File file) throws IOException {
        try (FileOutputStream fout = new FileOutputStream(file)) {
            save(fout);
        }
    }
787555
public static function save(string $filename, string $data): bool
    {
        return \file_put_contents($filename, $data) !== false;
    }
180452
protected function save($data)
    {
        $currentStep = $this->getCurrentStep();
        if (is_array($data)) {
            foreach ($data as $field => $value) {
                if (in_array($field, $this->config()->get('ignored_fields'))) {
                    unset($data[$field]);
                }
            }
            $currentStep->saveData($data);
        }
        return;
    }
712899
public function init($file, array $data = null)
    {
        if ($data === null) {
            $data = $this->setJsonDefaults([]);
        }
        $this->app['filesystem']->write($file, Json::dump($data, Json::HUMAN));
    }