/**
  * Set contents of a file object.
  *
  * @param AbstractFile $file
  * @param string $contents
  *
  * @throws \Exception|\RuntimeException
  * @throws Exception\InsufficientFileWritePermissionsException
  * @throws Exception\InsufficientUserPermissionsException
  * @return int The number of bytes written to the file
  */
 public function setFileContents(AbstractFile $file, $contents)
 {
     // Check if user is allowed to edit
     $this->assureFileWritePermissions($file);
     // Call driver method to update the file and update file index entry afterwards
     $result = $this->driver->setFileContents($file->getIdentifier(), $contents);
     $this->getIndexer()->updateIndexEntry($file);
     $this->emitPostFileSetContentsSignal($file, $contents);
     return $result;
 }