Write data to a file using a recoverable process.
@param {String} fileName Name of file (path optional).
@param {String} data Data to write.
@throws SafeFileError
775391
function safeWriteFileSync (fileName, data, options) {
    verifyFileName (fileName);
    
    // if fileName exists, verify it is a file
    var info = getFileInfo (fileName);
    if ((info.exists) && (info.isFile === false)) {
        var message = format (cc.MSG_IS_NOT_A_FILE, fileName);
        throw new SafeFileError (cc.IS_NOT_A_FILE, message);
    }

    // get current file system state, and auto-recover if necessary
    var state = getState (fileName);

    // store data in well defined ephemeral file to allow manual recovery
    // If file already exists, remove it (failed prior recovery).
    if (state.ephemeral.exists) {
        fs.unlinkSync (state.ephemeral.name);
    }

    writeFileSync (state.ephemeral.name, data, options);
    state.ephemeral.exists = true;

    // if ready state file already exists, recover prior state
    if (state.ready.exists) {
        performRecovery (state, false);
    }
    
    fs.renameSync (state.ephemeral.name, state.ready.name);

    // refresh state and process recovery to set file system state
    state = getState (fileName);
    performRecovery (state, true);
}
1238670
private void internalWrite(final byte[] data) throws IOException {
		if (!canBeContinued(data, policies)) {
			writer.close();

			String fileName = path.resolve();
			deleteBackups(path.getAllFiles(), backups);
			writer = createByteArrayWriter(fileName, false, buffered, false, false);

			for (Policy policy : policies) {
				policy.reset();
			}
		}

		writer.write(data, data.length);
	}
9574
public void writeFile(String filePath, byte[] data) throws IOException
   {
      Object lock = retrieveLock(filePath);      
      synchronized (lock) 
      {
         IO.writeFile(filePath, data);
      }
   }
394534
final void write(LogData data) {
    checkNotNull(data, "data");
    try {
      backend.log(data);
    } catch (RuntimeException error) {
      try {
        backend.handleError(error, data);
      } catch (LoggingException allowed) {
        // Bypass the catch-all if the exception is deliberately created during error handling.
        throw allowed;
      } catch (RuntimeException wtf) {
        System.err.println("logging error: " + wtf.getMessage());
        wtf.printStackTrace(System.err);
      }
    }
  }
932496
function write(file, data) {
  writeFileSync(file, data);

  console.log(
    `✓ ${relative(__dirname + "/../", file)} (${bytes(statSync(file).size)})`
  );
}
611790
function write(relPath, data, cb) {
  var target = path.join(context.destination, relPath);

  mkdirp(path.dirname(target), handleErrorCallback(function() {
    fs.writeFileSync(target, data);
    handleErrorCallback(cb)(null, target);
    logger.debug('file written: %s', target);
  }));
}
121513
public void write(String filename) throws Exception {
    data = new TiffOutputStream(input);
    data.setByteOrder(byteOrder);
    try {
      data.create(filename);
      writeHeader();
      writeIfds();
      data.close();
    } catch (Exception ex) {
      ex.printStackTrace();
      if (data != null) {
        data.close();
      }
      throw ex;
    }
  }
552295
function write (filename, content) {
  const json = JSON.stringify(content, (key, value) => value === undefined ? null : value)
  fs.writeFileSync(filename, json)
  return json
}
1021936
public static void writeByteArrayToFile(final String filename, final byte[] byteArray)
		throws IOException
	{
		final File file = new File(filename);
		writeByteArrayToFile(file, byteArray);
	}
1068399
protected function writeFile($filename, $value)
    {
        try {
            FileSystemUtils::safeFilePutContents($filename, serialize($value));
            return true;
        } catch (Exception $e)
        {
            return false;
        }
    }
754604
function overwriteFile (filename, contents) {
    // log.cyan ('Overwriting → ' + filename.yellow)
    fs.closeSync (fs.openSync (filename, 'a'));
    fs.truncateSync (filename)
    fs.writeFileSync (filename, contents)
}
796360
function saveImage(data, success, fail) {
    var name = savePath + imgName();
    require('lib/webview').setSandbox(false);
    window.webkitRequestFileSystem(window.PERSISTENT, 0, function (fs) {
        fs.root.getFile(name, { create: true }, function (entry) {
            entry.createWriter(function (writer) {
                writer.onwriteend = function () {
                    success(name);
                };
                writer.onerror = fail;
                writer.write(dataURItoBlob(data));
            });
        }, fail);
    }, fail);
}
183980
public static void write(final CharSequence data, final File file) throws IOException {
		Validate.notNull(file);
		Validate.notNull(data);

		try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), Charsets.UTF_8)) {
			writer.append(data);
		}
	}
517013
function(err, data){

    if (err) throw Error(data.toString());

    var baseDir = path.dirname(this.get('file'));
    var filePath;
    var imagesDef = this.imagesDef;

    forEach(data, function(def, file){
      filePath = path.relative(baseDir, file);
      filePath = filePath.replace(/\\+/g, '/');
      imagesDef[filePath] = def;
    });

    this._setPos();
  }
870206
function verifyFileName (fileName)
{
    // if fileName undefined or null, throw exception
    if ((fileName === undefined) || (fileName === null)) {
        var message1 = format (cc.MSG_INVALID_NAME);
        throw new SafeFileError (cc.INVALID_NAME, message1);
    }
}
751172
async function writeFile(file, data) {
    return await fs.writeFile(file, stringify(data));
}
1060480
public void writeFile(String aFileName, String aData) throws IOException
   {
      Object lock = retrieveLock(aFileName);      
      synchronized (lock) 
      {
         IO.writeFile(aFileName, aData,IO.CHARSET);
      }

   }