/* Write out the contents of a file stream to the "disk file". Because
localStorage doesn't support appending, we have to dump the entire
buffer out.
199155
function gli_stream_flush_file(str) {
    if (str.streaming)
        GlkOte.log('### gli_stream_flush_file called for streaming file!');
    if (!(str.timer_id === null)) {
        clearTimeout(str.timer_id);
    }
    str.timer_id = null;
    Dialog.file_write(str.ref, str.buf);
}
563500
protected long writeOutput(OutputStream out, ValueData value) throws IOException
   {
      if (value.isByteArray())
      {
         byte[] buff = value.getAsByteArray();
         out.write(buff);

         return buff.length;
      }
      else
      {
         InputStream in;
         if (value instanceof StreamPersistedValueData)
         {

            StreamPersistedValueData streamed = (StreamPersistedValueData)value;
            if (streamed.isPersisted())
            {
               // already persisted in another Value, copy it to this Value
               in = streamed.getAsStream();
            }
            else
            {
               in = streamed.getStream();
               if (in == null)
               {
                  in = new FileInputStream(streamed.getTempFile());
               }
            }
         }
         else
         {
            in = value.getAsStream();
         }

         try
         {
            return copy(in, out);
         }
         finally
         {
            in.close();
         }
      }
   }
907261
function writeFile(output, filePath, content) {
    var rootFolder = output.getRoot();
    filePath = path.join(rootFolder, filePath);

    return fs.ensureFile(filePath)
    .then(function() {
        return fs.writeFile(filePath, content);
    })
    .thenResolve(output);
}
499021
public void write(byte []buf, int offset, int length, boolean isEnd)
    throws IOException
  {
    System.out.write(buf, offset, length);
    System.out.flush();
  }
248770
def write_file(self, blob, dest):
        '''
        
        '''
        with salt.utils.files.fopen(dest, 'wb+') as fp_:
            blob.stream_data(fp_)
272693
function writeToDisk(output, data, callback) {
  fs.mkdirp(path.dirname("" + output), function (err) {
    if (err) {
      if (callback) {
        callback(err);
      }
      return console.log(err);
    }
    fs.writeFile("" + output, data, function (err) {
      if (err) {
        if (callback) {
          callback(err);
        }
        return console.log(err);
      } else {
        if (callback) {
          callback();
        }
      }
    });
  });
}
63329
function write(filepath, contents) {
  return new Promise((resolve, reject)=>{
    fs.writeFile(filepath, contents, (err, response)=>{
      if (err) return reject(err);
      return resolve(response);
    })
  });
}
1332201
function(/**string*/ outDir, /**string*/ fileName, /**string*/ content) {
		var out = new Packages.java.io.PrintWriter(
			new Packages.java.io.OutputStreamWriter(
				new Packages.java.io.FileOutputStream(outDir+SYS.slash+fileName),
				IO.encoding
			)
		);
		out.write(content);
		out.flush();
		out.close();
	}
1305093
function writeFile(callback) {
        var s = JSON.stringify(images);

        fs.writeFile('imageData.json', s, function (err) {
          if (err) return console.log(err);
          else
            { 
            console.log("success");
            if (callback) callback.call(this, images);
            }
        });


    }
317861
private void writeFileByte(byte[] content, File file) throws IOException {

        FileOutputStream fOut = null;
        DataOutputStream dOut = null;
        try {
            // write the content to the file in server filesystem
            fOut = new FileOutputStream(file);
            dOut = new DataOutputStream(fOut);
            dOut.write(content);
            dOut.flush();
        } catch (IOException e) {
            throw e;
        } finally {
            try {
                if (fOut != null) {
                    fOut.close();
                }
            } catch (IOException e) {
                // ignore
            }
            try {
                if (dOut != null) {
                    dOut.close();
                }
            } catch (IOException e) {
                // ignore
            }
        }
    }
600784
async function copy(src, dst, mode=null){
    // open file input stream
    const istream = await _fInputStream(src);

    // write stream content to file
    return _fOutoutStream(istream, dst, mode);
}
174348
function writeFile(filePath, contents) {
  return new Promise((resolve, reject) => {
    fs.writeFile(filePath, contents, 'utf-8', (err, file) => {
      err ? reject(err) : resolve();
    })
  });
}
152763
def write_file(self, blob, dest):
        '''
        
        '''
        with salt.utils.files.fopen(dest, 'wb+') as fp_:
            fp_.write(blob.data)
90709
function writeStreamToFs(opts, stream) {
    var baseDir = path.join(opts.cwd, opts.directory);
    var walker = walk.walk(baseDir);

    walker.on('errors', function (root, stats, next) {
        stream.emit('error', new PluginError(PLUGIN_NAME, stats.error));
        next();
    });
    walker.on('directory', function (root, stats, next) {
        next();
    });

    walker.on('file', function (root, stats, next) {
        var filePath = path.resolve(root, stats.name);

        fs.readFile(filePath, function (error, data) {
            if (error) {
                stream.emit('error', new PluginError(PLUGIN_NAME, error));
            } else {
                stream.write(new Vinyl({
                    path: path.relative(baseDir, filePath),
                    contents: data
                }));
            }

            next();
        });
    });

    walker.on('end', function () {
        stream.emit('end');
        stream.emit('finish');
    });
}
384363
function writeStreamToFile(fileMeta, stream) {
  var deferred = q.defer();
  stream.on('end', function() {
    deferred.resolve(fileMeta);
  });
  stream.on('error', function(error) {
    deferred.reject(error);
  });
  var filename = imageDir + '/' + fileMeta.uid;
  stream.pipe(fs.createWriteStream(filename));
  return deferred.promise;
}
1130770
public void write(byte[] arr, int off, int len) throws IOException {
    if (len > buf.length - pos) {
      if (buf.length != getMaxPacketLength()) {
        growBuffer(len);
      }

      //max buffer size
      if (len > buf.length - pos) {

        if (mark != -1) {
          growBuffer(len);
          if (mark != -1) {
            flushBufferStopAtMark();
          }

        } else {
          //not enough space in buffer, will stream :
          // fill buffer and flush until all data are snd
          int remainingLen = len;
          do {
            int lenToFillBuffer = Math.min(getMaxPacketLength() - pos, remainingLen);
            System.arraycopy(arr, off, buf, pos, lenToFillBuffer);
            remainingLen -= lenToFillBuffer;
            off += lenToFillBuffer;
            pos += lenToFillBuffer;
            if (remainingLen > 0) {
              flushBuffer(false);
            } else {
              break;
            }
          } while (true);
          return;
        }
      }
    }

    System.arraycopy(arr, off, buf, pos, len);
    pos += len;
  }
1320589
function write(description, options, callback) {
  var file = vfile(description)

  // Weird, right? Otherwise `fs` doesn’t accept it.
  if (!callback && typeof options === 'function') {
    callback = options
    options = undefined
  }

  if (!callback) {
    return new Promise(executor)
  }

  executor(resolve, callback)

  function resolve(result) {
    callback(null, result)
  }

  function executor(resolve, reject) {
    var fp

    try {
      fp = path.resolve(file.cwd, file.path)
    } catch (error) {
      return reject(error)
    }

    fs.writeFile(fp, file.contents || '', options, done)

    function done(error) {
      if (error) {
        reject(error)
      } else {
        resolve()
      }
    }
  }
}