Prepares the file manager and starts writing outcomes.xml
176515
public function on_gradebook_grade_outcomes_start() {

        $syscontextid  = $this->converter->get_contextid(CONTEXT_SYSTEM);
        $this->fileman = $this->converter->get_file_manager($syscontextid, 'grade', 'outcome');

        $this->open_xml_writer('outcomes.xml');
        $this->xmlwriter->begin_tag('outcomes_definition');
    }
721080
public function onAfterWrite()
    {
        $changed = $this->owner->getChangedFields(true, 2);

        if (!$this->owner instanceof Folder && !$this->owner->CurrentVersionID) {
            $this->createVersion();
        }

        if (array_key_exists('Filename', $changed)) {
            if ($changed['Filename']['before'] == null) {
                return;
            }

            $oldDirname = '/' . trim(dirname($changed['Filename']['before']), '/');
            $newDirname = '/' . trim(dirname($changed['Filename']['after']), '/');

            if ($oldDirname == $newDirname) {
                return;
            }

            // First move the _versions directory across.
            $versionsDir = FileVersion::VERSION_FOLDER . '/' . $this->owner->ID;
            $oldVersions = BASE_PATH . $oldDirname . '/' . $versionsDir;
            $newVersions = BASE_PATH . $newDirname . '/' . $versionsDir;

            if (is_dir($oldVersions)) {
                if (!is_dir($newVersions)) {
                    mkdir($newVersions, Config::inst()->get('Filesystem', 'folder_create_mask'), true);
                }

                if (!is_dir($newVersions)) {
                    rename($oldVersions, $newVersions);
                }
            }

            // Then update individual version records to point to the new
            // location.
            foreach ($this->owner->Versions() as $version) {
                if (strpos($version->Filename, $oldDirname) === 0) {
                    $version->Filename = $newDirname . substr($version->Filename, strlen($oldDirname));
                    $version->write();
                }
            }
        }
    }
889916
@Override
    public void writeXML(@WillClose XMLOutput xmlOutput) throws IOException {
        assert project != null;
        try {
            writePrologue(xmlOutput);
            if (withMessages) {
                computeBugHashes();
                getProjectStats().computeFileStats(this);
                String commonBase = null;
                for (String s : project.getSourceDirList()) {
                    if (commonBase == null) {
                        commonBase = s;
                    } else {
                        commonBase = commonBase.substring(0, commonPrefix(commonBase, s));
                    }

                }
                if (commonBase != null && commonBase.length() > 0) {
                    if (commonBase.indexOf("/./") > 0) {
                        commonBase = commonBase.substring(0, commonBase.indexOf("/."));
                    }
                    File base = new File(commonBase);
                    if (base.exists() && base.isDirectory() && base.canRead()) {
                        SourceLineAnnotation.generateRelativeSource(base, project);
                    }
                }
            }
            if (earlyStats && !minimalXML) {
                getProjectStats().writeXML(xmlOutput, withMessages);
            }

            // Write BugInstances
            for (BugInstance bugInstance : getCollection()) {
                if (!applySuppressions || !project.getSuppressionFilter().match(bugInstance)) {
                    bugInstance.writeXML(xmlOutput, this, withMessages);
                }
            }

            writeEpilogue(xmlOutput);

        } finally {
            xmlOutput.finish();
            SourceLineAnnotation.clearGenerateRelativeSource();
        }
    }
1120027
private void setupFile() {
        if (!new File(directory).exists() && !new File(directory).mkdirs()) {
            try {
                throw new IOException("Unable to create output directory");
            } catch (IOException e) {
                log.info(e);
            }
        }
        if (!file.exists()) {
            try {
                if (!file.createNewFile()) {
                    throw new IOException("Unable to create output file");
                }
            } catch (IOException e) {
                log.error(e);
            }
        }
    }
1075071
public XML write(){
		try { FilesManager.write(xmlJmapper, xmlPath);
		} catch (IOException e) {JmapperLog.error(e);}
		return this;
	}
1087228
protected function prepareProjectData(): void
  {
    parent::prepareProjectData();

    // Get file list form the project by fileset ID.
    $sources               = $this->getProject()->getReference($this->sourcesFilesetId);
    $this->sourceFileNames = $sources->getDirectoryScanner($this->getProject())->getIncludedFiles();
    $suc                   = ksort($this->sourceFileNames);
    if ($suc===false) $this->logError("ksort failed.");
  }
721067
void writeStartDocument(final Writer output) throws SAXException {
        try {
            output.write(XML_HEAD);
        } catch (IOException e) {
            throw new SAXException(e);
        }
    }
488004
public void startDocument() {
    if (encoding != null) {
      write(writer, "<?xml version=\"1.0\" encoding=\"");
      write(writer, encoding);
      write(writer, "\" standalone=\"yes\"?>" + NL);
    }
    level = 0;
  }
892855
def write_xml(xml)
      fname = "#{@appliance_name}.xml"
      File.open("#{@dir.tmp}/#{fname}", 'w'){|f| f.write(xml)}
      register_deliverable(:xml => fname)
    end
906621
private void processFile(String fileName)
      throws ValidationException, ParserConfigurationException, SAXException, IOException,
          SchedulerException, ClassNotFoundException, ParseException, XPathException {

    prepForProcessing();

    logger.info("Parsing XML file: " + fileName);
    InputSource is = new InputSource(getInputStream(fileName));
    // is.setSystemId(systemId);

    process(is);

    maybeThrowValidationException();
  }
661825
def generate_output_file(zip_out, contents)
      # output entries to zip file
      created_dirs = []
      contents.each do |entry_name, content|
        create_dirs_in_zipfile(created_dirs, File.dirname(entry_name), zip_out)
        zip_out.put_next_entry(entry_name)
        #
        # convert Nokogiri XML to string
        if content.instance_of? Nokogiri::XML::Document
          content = content.to_xml(indent: 0, save_with: 0)
        end
        #
        zip_out.write(content)
      end
    end
93250
def write(self):
        
        if not os.path.isdir(self._dirs['source_dir']):
            os.mkdir(self._dirs['source_dir'])

        fout = codecs.open(self._dirs['source_filename'], 'w', encoding="utf-8", errors="xmlcharrefreplace")
        fout.write(self._config_to_text())
        if self._content:
            fout.write('\n')
            fout.write(self._content)
            fout.write('\n')
        fout.close()
171393
@Override
  protected void prepare(int flags) throws IOException {
    SysUtil.mkdirOrThrow(soDirectory);
    File lockFileName = new File(soDirectory, LOCK_FILE_NAME);
    FileLocker lock = FileLocker.lock(lockFileName);
    try {
      Log.v(TAG, "locked dso store " + soDirectory);
      if (refreshLocked(lock, flags, getDepsBlock())) {
        lock = null; // Lock transferred to syncer thread
      } else {
        Log.i(TAG, "dso store is up-to-date: " + soDirectory);
      }
    } finally {
      if (lock != null) {
        Log.v(TAG, "releasing dso store lock for " + soDirectory);
        lock.close();
      } else {
        Log.v(TAG, "not releasing dso store lock for "
            + soDirectory + " (syncer thread started)");
      }
    }
  }
648760
def _write_rough_result_xml_to_file(self, xml, filename):
        """"""
        # Write content to temp file first
        error = xml.get('error', None)
        xml.set('error', 'incomplete') # Mark result file as incomplete
        temp_filename = filename + ".tmp"
        with open(temp_filename, 'wb') as file:
            ET.ElementTree(xml).write(file, encoding='utf-8', xml_declaration=True)
        os.rename(temp_filename, filename)
        if error is not None:
            xml.set('error', error)
        else:
            del xml.attrib['error']
536630
public function prepare()
    {
        $this->taskFileSystemStack()
             ->mkdir($this->properties['dist.dir'])
             ->mkdir($this->properties['target.dir'])
             ->mkdir(sprintf('%s/reports', $this->properties['target.dir']))
             ->run();
    }
72831
def write(self, session, directory, name, maskMap):
        

        # Assemble Path to file
        name_split = name.split('.')
        name = name_split[0]

        # Default extension
        extension = ''

        if len(name_split) >= 2:
            extension = name_split[-1]

        # Run name preprocessor method if present
        try:
            name = self._namePreprocessor(name)
        except:
            'DO NOTHING'

        if extension == '':
            filename = '{0}.{1}'.format(name, self.fileExtension)
        else:
            filename = '{0}.{1}'.format(name, extension)

        filePath = os.path.join(directory, filename)

        with open(filePath, 'w') as openFile:
            # Write Lines
            self._write(session=session,
                        openFile=openFile,
                        maskMap=maskMap)
1017605
private void writeCompletionFile() {
        File completionFile = getCompletionFile();
        try {
            if (completionFile.createNewFile()) {
                log.info("successfully created completion marker file: {}",
                         completionFile.getAbsolutePath());
            } else {
                log.warn("completion marker file unexpectably exists already " +
                         "- something may be amiss: {}",
                         completionFile.getAbsolutePath());

            }
        } catch (IOException e) {
            log.error("Unable to create the completion file {}: {}",
                      completionFile.getAbsolutePath(),
                      e.getMessage());
        }
    }