Write the in-memory configuration to a file or stream.
971647
function write(file, cb) {
  if(file === undefined) file = this._file;

  if(file === DEFAULT_FILE) {
    return this.emit(
      'error', new Error('cannot write to default configuration'));
  }

  var sync = typeof cb !== 'function'
    , stream
    , save
    , encoder = new Encoder(this.options)
    , lines = this._lines
    , size = 32
    , i = 0
    , len = (lines.length / size);


  if(!file || typeof file !== 'string' && !(file instanceof Writable)){
    return this.emit('error',
      new Error('cannot write configuration, path or stream expected'));
  }

  if(typeof file === 'string') {
    file = resolve(file);
    save = file + Constants.SAVE;
  }

  if(sync && file && typeof file === 'string') {
    try {
      fs.writeFileSync(save, encoder.parse(this._lines));
      fs.renameSync(save, file);
    }catch(e) {
      /* istanbul ignore next: hard to mock a rename(2) error */
      return this.emit('error', e);
    }
    return encoder;
  }

  if(file instanceof Writable) {
    stream = file;
  }else{
    stream = fs.createWriteStream(save, this.options.read)
  }

  this.once('write', cb);

  function onFinish() {

    function onRename(err) {
      encoder.removeAllListeners('error');
      stream.removeAllListeners('error');
      /* istanbul ignore next: hard to mock a rename(2) error */
      if(err) return this.emit('error', err);
      this.emit('write', this);
    }

    onRename = onRename.bind(this);

    if(save) {
      fs.rename(save, file, onRename);
    }else{
      onRename();
    }

  }

  var onError = this.onError.bind(this);
  encoder.on('error', onError);
  stream.on('error', onError);

  stream.on('finish', onFinish.bind(this));
  encoder.pipe(stream);

  if((lines.length % size) !== 0) len++;

  // not a very large config
  if(lines.length < size) {
    encoder.end(lines);
    return encoder;
  }

  // split the work for larger config files
  function writeLines() {
    var chunk = lines.slice(i * size, (i * size) + size);

    // all done
    if(!chunk.length) {
      return encoder.end();
    }

    // ensure we get correct line break between
    // line chunks, the encoder joins lines on EOL
    // this means that the last line in the chunk array
    // does not have an EOL, we need to ensure it does
    if(i > 0) {
      chunk.unshift('');
    }

    // write out the line chunk
    encoder.write(chunk);
    setImmediate(writeLines);
    i++;
  }

  writeLines();
  return encoder;
}
325476
def _write_cache(self, lines, append=False):
        """"""
        mode = 'at' if append else 'wt'
        with open(self.filepath, mode, encoding='utf8') as fh:
            fh.writelines(line + '\n' for line in lines)
666903
def write_config_file(self, f, comments):
        
        if comments:
            f.write("#####################################\n")
            f.write("# Section : ")
            f.write("#".join(self.get_representation()) + "\n")
            f.write("#####################################\n")
        f.write("[" + self._name + "]\n")
        if self._desc and comments:
            f.write("# Description : ")
            for i in self._desc.split('\n'):
                f.write("# ")
                f.write(i)
                f.write("\n")
            f.write("\n")
1157532
def write(self, config_dir=None, config_name=None, codec=None):
        
        # get name of config directory
        if not config_dir:
            config_dir = self._meta_config_dir
            if not config_dir:
                raise IOError("config_dir not set")

        # get name of config file
        if not config_name:
            config_name = self._defaults.get('config_name', None)
        if not config_name:
            raise KeyError('config_name not set')

        if codec:
            codec = munge.get_codec(codec)()
        else:
            codec = munge.get_codec(self._defaults['codec'])()

        config_dir = os.path.expanduser(config_dir)
        if not os.path.exists(config_dir):
            os.mkdir(config_dir)

        codec.dumpu(self.data, os.path.join(config_dir, 'config.' + codec.extension))
602108
def write_to_file(self, f):
        """"""
        for section, values in self._values.iteritems():
            try:
                section_name, subsection_name = section
            except ValueError:
                (section_name, ) = section
                subsection_name = None
            if subsection_name is None:
                f.write("[%s]\n" % section_name)
            else:
                f.write("[%s \"%s\"]\n" % (section_name, subsection_name))
            for key, value in values.iteritems():
                f.write("%s = %s\n" % (key, _escape_value(value)))
955983
def write_config(configfile, content):
    
    with open(configfile, 'w+') as ymlfile:
        yaml.dump(
            content,
            ymlfile,
            default_flow_style=False,
        )
593682
public static void write(InputStream in, File file) {
        write(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
    }
1235704
@Benchmark
	@BenchmarkMode(Mode.AverageTime)
	public void byteBufferFileOutputStream(final Configuration configuration) throws IOException {
		ByteBuffer buffer = ByteBuffer.allocate(BUFFER_CAPACITY);

		try (OutputStream stream = new FileOutputStream(configuration.file)) {
			for (long i = 0; i < LINES; ++i) {
				if (buffer.remaining() < DATA.length) {
					stream.write(buffer.array(), 0, buffer.position());
					buffer.rewind();
				}

				if (buffer.remaining() < DATA.length) {
					stream.write(DATA);
				} else {
					buffer.put(DATA);
				}
			}

			if (buffer.position() > 0) {
				stream.write(buffer.array(), 0, buffer.position());
			}
		}
	}
1007403
def makefile(self, sock, mode='r', bufsize=DEFAULT_BUFFER_SIZE):
        """"""
        cls = StreamReader if 'r' in mode else StreamWriter
        return cls(sock, mode, bufsize)
851367
public static void writeConfigFile(File configFile, Class<?>[] classes, boolean sortClasses)
			throws SQLException, IOException {
		System.out.println("Writing configurations to " + configFile.getAbsolutePath());
		writeConfigFile(new FileOutputStream(configFile), classes, sortClasses);
	}
950513
private void writeConf() throws IOException {
    for (int i = 0; i < mNumMasters; i++) {
      File confDir = new File(mWorkDir, "conf-master" + i);
      writeConfToFile(confDir, mMasterProperties.getOrDefault(i, new HashMap<>()));
    }
    for (int i = 0; i < mNumWorkers; i++) {
      File confDir = new File(mWorkDir, "conf-worker" + i);
      writeConfToFile(confDir, mWorkerProperties.getOrDefault(i, new HashMap<>()));
    }
  }
644945
def _write_cache_to_file(self):
        """"""
        with(open(self._cache_file_name, 'w')) as fp:
            fp.write(simplejson.dumps(self._cache))
998453
private static <T> void writeConfig(BufferedWriter writer, DatabaseTableConfig<T> config) throws IOException,
			SQLException {
		writer.append(CONFIG_FILE_START_MARKER);
		writer.newLine();
		if (config.getDataClass() != null) {
			writer.append(FIELD_NAME_DATA_CLASS).append('=').append(config.getDataClass().getName());
			writer.newLine();
		}
		if (config.getTableName() != null) {
			writer.append(FIELD_NAME_TABLE_NAME).append('=').append(config.getTableName());
			writer.newLine();
		}
		writer.append(CONFIG_FILE_FIELDS_START);
		writer.newLine();
		if (config.getFieldConfigs() != null) {
			for (DatabaseFieldConfig field : config.getFieldConfigs()) {
				DatabaseFieldConfigLoader.write(writer, field, config.getTableName());
			}
		}
		writer.append(CONFIG_FILE_FIELDS_END);
		writer.newLine();
		writer.append(CONFIG_FILE_END_MARKER);
		writer.newLine();
	}
445115
public static void write(InputStream in, Path path, StandardCopyOption op) {
        try {
            Files.copy(in, path, op);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
654536
def write_config_file(path, config):
    """"""
    contents = json.dumps(config, indent=4, separators=(',', ': ')) + '\n'
    try:
        with open(path, 'w') as f:
            f.write(contents)
        return True
    except IOError as ex:
        if ex != errno.ENOENT:
            raise
    return False
977170
def write_config(self):
        
        template = util.render_template(
            self._get_config_template(), config_options=self.config_options)
        util.write_file(self.config_file, template)
400440
public static void write(InputStream in, Path path) {
        write(in, path, StandardCopyOption.REPLACE_EXISTING);
    }