:param f: either filename or open file object to write to.
                  if it is an open buffer, you have to make sure to close
                  it properly.
        :param protocol: pickling protocol to use, python-pickle for details.
420336
def pickle(self, f, protocol=-1):
        
        try: #Py2
            import cPickle as pickle
            if isinstance(f, basestring):
                with open(f, 'wb') as f:
                    pickle.dump(self, f, protocol)
            else:
                pickle.dump(self, f, protocol)
        except ImportError: #python3
            import pickle
            if isinstance(f, str):
                with open(f, 'wb') as f:
                    pickle.dump(self, f, protocol)
            else:
                pickle.dump(self, f, protocol)
997488
public static boolean writeBytesToFile(byte[] bytes, File f) {
        try {
            FileOutputStream fout = new FileOutputStream(f);
            fout.write(bytes);
            fout.close();
        } catch (Exception e) {
            System.out.println("Error writing byte[] to file: "
                    + e.getMessage());
            return false;
        }
        return true;
    }
830377
def _open(self, file, mode_int, closefd):
        """"""
        if isinstance(file, (_unicode, bytes)):
            if _os.path.isfile(file):
                if 'x' in self.mode:
                    raise OSError("File exists: {0!r}".format(self.name))
                elif set(self.mode).issuperset('w+'):
                    # truncate the file, because SFM_RDWR doesn't:
                    _os.close(_os.open(file, _os.O_WRONLY | _os.O_TRUNC))
            openfunction = _snd.sf_open
            if isinstance(file, _unicode):
                if _sys.platform == 'win32':
                    openfunction = _snd.sf_wchar_open
                else:
                    file = file.encode(_sys.getfilesystemencoding())
            file_ptr = openfunction(file, mode_int, self._info)
        elif isinstance(file, int):
            file_ptr = _snd.sf_open_fd(file, mode_int, self._info, closefd)
        elif _has_virtual_io_attrs(file, mode_int):
            file_ptr = _snd.sf_open_virtual(self._init_virtual_io(file),
                                            mode_int, self._info, _ffi.NULL)
        else:
            raise TypeError("Invalid file: {0!r}".format(self.name))
        _error_check(_snd.sf_error(file_ptr),
                     "Error opening {0!r}: ".format(self.name))
        if mode_int == _snd.SFM_WRITE:
            # Due to a bug in libsndfile version <= 1.0.25, frames != 0
            # when opening a named pipe in SFM_WRITE mode.
            # See http://github.com/erikd/libsndfile/issues/77.
            self._info.frames = 0
            # This is not necessary for "normal" files (because
            # frames == 0 in this case), but it doesn't hurt, either.
        return file_ptr
540934
def _write(self, session, openFile, replaceParamFile):
        
        # Retrieve Connection objects and write to file
        connections = self.connections
        self._writeConnections(connections=connections,
                               fileObject=openFile)

        # Retrieve SuperJunction objects and write to file
        sjuncs = self.superJunctions
        self._writeSuperJunctions(superJunctions=sjuncs,
                                  fileObject=openFile)

        # Retrieve SuperLink objects and write to file
        slinks = self.superLinks
        self._writeSuperLinks(superLinks=slinks,
                              fileObject=openFile)
845372
def write(self, filename = ""):
        
        file_data = str(self)
        if filename:
            try:
                self.__write(filename, file_data)
            except IOError:
                raise IOError("File could not be opened for write operations.")
        else:
            return file_data
249
def save(self, filename):
        

        with open(filename, 'wb') as savefile:
            pickle.dump(self.__dict__,
                        savefile,
                        protocol=pickle.HIGHEST_PROTOCOL)
944528
def write_file(path, data, mode='w'):  # type: (str, str, str) -> None
    
    with open(path, mode) as f:
        f.write(data)
1102860
function OpenFileCB (err, fd) {
        if (err) {
            response.setHeader('Content-Type','text/html');
            response.writeHead(404, err.toString("utf8"));
            response.write("Hoops:" +  err );
            response.end();
            return;
        }
        fs.fstat(fd, function(err,stats){
            // get file size and allocate buffer to read it
            var buffer = new Buffer (stats.size);
            fs.read (fd, buffer,0,buffer.length,0,ReadFileCB);
        });
    }
280940
def dump(self, f):
        
        self.validate()
        with _open_file_obj(f, "w") as f:
            parser = self._get_parser()
            self.serialize(parser)
            self.build_file(parser, f)
364656
def save(self, filename, format=None, **kwargs):
        
        if format is None:
            # try to derive protocol from file extension
            format = format_from_extension(filename)
        with file(filename, 'wb') as fp:
            self.save_to_file_object(fp, format, **kwargs)
1338546
def tofile(self, filename, format = 'ascii'):
        
        if not common.is_string(filename):
            raise TypeError('argument filename must be string but got %s'%(type(filename)))
        if format not in ['ascii','binary']:
            raise TypeError('argument format must be ascii | binary')
        filename = filename.strip()
        if not filename:
            raise ValueError('filename must be non-empty string')
        if filename[-4:]!='.vtk':
            filename += '.vtk'
        f = open(filename,'wb')
        f.write(self.to_string(format))
        f.close()
42909
def save_params_to_file(self, fname: str):
        
        if self.aux_params is not None:
            utils.save_params(self.params.copy(), fname, self.aux_params.copy())
        else:
            utils.save_params(self.params.copy(), fname)
        logging.info('Saved params to "%s"', fname)
569392
def _write_file(self, filename, data):
        

        if self.__compression:
            f = gzip.GzipFile(filename, "wb")
        else:
            f = open(filename, "wb")
        pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
        f.close()
296949
def write(self, byte):
        
        if self.is_closed_flag:
            raise Exception("Unable to write - already closed!")
        self.written += len(byte)
        self.file.write(byte)
494852
def dumps(cls, obj, protocol=0):
        
        cls.save_option_state = True
        val = pickle.dumps(obj, protocol=protocol)
        cls.save_option_state = False
        return val
865741
def write(self, filename, type_='obo'):  #FIXME this is bugged
        
        if os.path.exists(filename):
            name, ext = filename.rsplit('.',1)
            try:
                prefix, num = name.rsplit('_',1)
                n = int(num)
                n += 1
                filename = prefix + '_' + str(n) + '.' + ext
            except ValueError:
                filename = name + '_1.' + ext
            print('file exists, renaming to %s' % filename)
            self.write(filename, type_)

        else:
            with open(filename, 'wt', encoding='utf-8') as f:
                if type_ == 'obo':
                    f.write(str(self))  # FIXME this is incredibly slow for big files :/
                elif type_ == 'ttl':
                    f.write(self.__ttl__())
                else:
                    raise TypeError('No exporter for file type %s!' % type_)
539432
def _decode_buffer(f):
	
	strlen = int(_readuntil(f, _TYPE_SEP))
	buf = f.read(strlen)
	if not len(buf) == strlen:
		raise ValueError(
			'string expected to be {} bytes long but the file ended after {} bytes'
			.format(strlen, len(buf)))
	try:
		return buf.decode()
	except UnicodeDecodeError:
		return buf