Writes out all the rows to a new file without fragmentation.
17386
public void defrag() {

        if (cacheReadonly) {
            return;
        }

        if (fileFreePosition == INITIAL_FREE_POS) {
            return;
        }

        database.logger.appLog.logContext(SimpleLog.LOG_NORMAL, "start");

        try {
            boolean wasNio = dataFile.wasNio();

            cache.saveAll();

            DataFileDefrag dfd = new DataFileDefrag(database, this, fileName);

            dfd.process();
            close(false);
            deleteFile(wasNio);
            renameDataFile(wasNio);
            backupFile();
            database.getProperties().setProperty(
                HsqlDatabaseProperties.hsqldb_cache_version,
                HsqlDatabaseProperties.THIS_CACHE_VERSION);
            database.getProperties().save();
            cache.clear();

            cache = new Cache(this);

            open(cacheReadonly);
            dfd.updateTableIndexRoots();
            dfd.updateTransactionRowIDs();
        } catch (Throwable e) {
            database.logger.appLog.logContext(e, null);

            if (e instanceof HsqlException) {
                throw (HsqlException) e;
            } else {
                throw new HsqlException(
                    e, Error.getMessage(ErrorCode.GENERAL_IO_ERROR),
                    ErrorCode.GENERAL_IO_ERROR);
            }
        }

        database.logger.appLog.logContext(SimpleLog.LOG_NORMAL, "end");
    }
666891
public void write(Map<?, ?> row) throws IOException {
      if (row != null) {
         if (header.isEmpty()) {
            List<?> entries = row.values().stream().map(o -> Convert.convert(o, String.class)).collect(
               Collectors.toList());
            writer.write(formatter.format(entries));
            writer.write(SystemInfo.LINE_SEPARATOR);
         } else {
            writer.write(
               formatter.format(
                  Stream.concat(
                     header.stream()
                           .map(
                              h -> row.containsKey(h) ? Convert.convert(row.get(h), String.class) : StringUtils.EMPTY),
                     row.keySet().stream()
                        .map(k -> Convert.convert(k, String.class))
                        .filter(h -> !header.contains(h))
                        .map(h -> Convert.convert(row.get(h), String.class))
                               )
                        .collect(Collectors.toList())
                               )
                        );
            writer.write(SystemInfo.LINE_SEPARATOR);
         }

      }

   }
1041750
public void writeAll(java.util.List<String[]> allLines) throws IOException {

        openWriter();
        csvWriter.writeAll(allLines);
    }
1285418
def write_to_files_rec(instances, tokenizer, max_seq_length,
                       max_predictions_per_seq, output_files):
    """"""
    writers = []
    for output_file in output_files:
        writers.append(
            mx.recordio.MXIndexedRecordIO(
                os.path.splitext(output_file)[0] + '.idx', output_file, 'w'))

    writer_index = 0
    total_written = 0
    for (inst_index, instance) in enumerate(instances):
        features = transform(instance, tokenizer, max_seq_length, max_predictions_per_seq)
        example = features

        writers[writer_index].write_idx(inst_index, json.dumps(example).encode('UTF-8'))
        writer_index = (writer_index + 1) % len(writers)
        total_written += 1

    for writer in writers:
        writer.close()

    logging.info('Wrote %d total instances', total_written)
549670
def save(self, path):
        
        writer = csv.writer(open(path, 'w', newline=''), delimiter=' ')
        rows = list(self.items())
        rows.sort(key=lambda x: x[0])
        writer.writerows(rows)
53419
def write_text_files(args, infilenames, outfilename):
    
    if not outfilename.endswith('.txt'):
        outfilename = outfilename + '.txt'
    outfilename = overwrite_file_check(args, outfilename)

    all_text = []  # Text must be aggregated if writing to a single output file
    for i, infilename in enumerate(infilenames):
        parsed_text = get_parsed_text(args, infilename)
        if parsed_text:
            if args['multiple']:
                if not args['quiet']:
                    print('Attempting to write to {0}.'.format(outfilename))
                write_file(parsed_text, outfilename)
            elif args['single']:
                all_text += parsed_text
                # Newline added between multiple files being aggregated
                if len(infilenames) > 1 and i < len(infilenames) - 1:
                    all_text.append('\n')

    # Write all text to a single output file
    if args['single'] and all_text:
        if not args['quiet']:
            print('Attempting to write {0} page(s) to {1}.'
                  .format(len(infilenames), outfilename))
        write_file(all_text, outfilename)
81109
def write(self, data, end="\n", flush=True):
        
        if not self.nostdout:
            self.stdout.write(data+end)
        if self.file is not None:
            self.file.write(data+end)
        if flush:
            self.flush()
56870
public function export()
    {
        $headers = $this->fileHeaders();
        $rows = $this->rows();

        $writer = Writer::createFromFileObject(new SplTempFileObject());
        $writer->setNewline("\r\n");
        $writer->setOutputBOM(Writer::BOM_UTF8);
        $writer->insertOne($headers);

        foreach ($rows as $r) {
            $writer->insertOne($r);
        }

        $writer->output($this->filename());
    }
452558
def write_formatted_blank_to_area(row_first, row_last, col_first, col_last, format)
      (row_first .. row_last).each do |row|
        (col_first .. col_last).each do |col|
          next if row == row_first && col == col_first
          write_blank(row, col, format)
        end
      end
    end
1166857
def fastaAlignmentWrite(columnAlignment, names, seqNo, fastaFile,
                        filter=lambda x : True):
    
    fastaFile = open(fastaFile, 'w')
    columnAlignment = [ i for i in columnAlignment if filter(i) ]
    for seq in xrange(0, seqNo):
        fastaFile.write(">%s\n" % names[seq])
        for column in columnAlignment:
            fastaFile.write(column[seq])
        fastaFile.write("\n")
    fastaFile.close()
404670
private boolean createEmptyHeader( String filePath, int rows ) {

        try {
            RandomAccessFile theCreatedFile = new RandomAccessFile(filePath, "rw");

            rowaddresses = new long[rows + 1];
            // the size of a long
            theCreatedFile.write(4);
            // write the addresses of the row begins. Since we don't know how
            // much
            // they will be compressed, they will be filled after the
            // compression
            for( int i = 0; i < rows + 1; i++ ) {
                theCreatedFile.writeInt(0);
            }
            pointerInFilePosition = theCreatedFile.getFilePointer();
            rowaddresses[0] = pointerInFilePosition;

            theCreatedFile.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

        return true;
    }
1082287
private void writeToFile(MemoryCommitResult mcr) {
        // Rename the current file so it may be used as a backup during the next read
        if (mFile.exists()) {
            if (!mcr.changesMade) {
                // If the file already exists, but no changes were
                // made to the underlying map, it's wasteful to
                // re-write the file.  Return as if we wrote it
                // out.
                mcr.setDiskWriteResult(true);
                return;
            }
            if (!mBackupFile.exists()) {
                if (!mFile.renameTo(mBackupFile)) {
                    System.out.println( "Couldn't rename file " + mFile
                            + " to backup file " + mBackupFile);
                    mcr.setDiskWriteResult(false);
                    return;
                }
            } else {
                mFile.delete();
            }
        }

        // Attempt to write the file, delete the backup and return true as atomically as
        // possible.  If any exception occurs, delete the new file; next time we will restore
        // from the backup.
        try {
            FileOutputStream str = createFileOutputStream(mFile);
            if (str == null) {
                mcr.setDiskWriteResult(false);
                return;
            }
            XmlUtils.writeMapXml(mcr.mapToWriteToDisk, str);
            FileUtils.sync(str);
            str.close();
            setFilePermissionsFromMode(mFile.getPath(), mMode, 0);
            if (mFile.canRead()) {
                synchronized (this) {
                    mStatTimestamp = mFile.lastModified();
                    mStatSize = mFile.length();
                }
            }
            // Writing was successful, delete the backup file if there is one.
            mBackupFile.delete();
            mcr.setDiskWriteResult(true);
            return;
        } catch (IOException e) {
            System.out.println("writeToFile: Got exception:" + e);
        }
        // Clean up an unsuccessfully written file
        if (mFile.exists()) {
            if (!mFile.delete()) {
                System.out.println("Couldn't clean up partially-written file " + mFile);
            }
        }
        mcr.setDiskWriteResult(false);
    }
127663
def write_chunks(out, chunks):
    """"""

    out.write(signature)
    for chunk in chunks:
        write_chunk(out, *chunk)
588369
def simple_write(filename, group, times, features,
                 properties=None, item='item', mode='a'):
    """"""
    write(filename, group, [item], [times], [features], mode=mode,
          properties=[properties] if properties is not None else None)
1291589
def write(dump)
      with_flock(File::LOCK_EX) do
        @fd.write(dump)
        # Flush to make sure the file is really updated
        @fd.flush
      end
      @pos = @fd.pos if @pos && @fd.pos == @pos + dump.bytesize
    end
1061379
def save_all
      reports = to_h
      reports.each do |file, report|
        File.write(file, report)
      end

      reports.keys
    end
125500
def xlsw_write_row(ws, row_idx, row, fmt=None):
    
    for col_idx in range(len(row)):
        ws.write(row_idx, col_idx, row[col_idx], fmt)
    row_idx += 1
    return row_idx