Dump remote content in file system
@param data Remote content data
@param fragmentKey Remote content key
@param cachePath Temp FS cache directory
@param callback Method to call when file is written
174346
function (data, fragmentKey, cachePath, callback) {
    debug('  write content in file system');
    var basePath =  path.dirname(fragmentKey);
    if (basePath){
      mkdirp.sync(cachePath + '/' + basePath);
    }
    fs.writeFile(cachePath + '/' + fragmentKey, data, function (err) {
      if (err) {
        callback(err);
      } else {
        callback(null, data);
      }
    });
  }
521790
protected void writeContent(String requestedPath, HttpServletRequest request, HttpServletResponse response)
			throws IOException, ResourceNotFoundException {

		// Send gzipped resource if user agent supports it.
		int idx = requestedPath.indexOf(BundleRenderer.GZIP_PATH_PREFIX);
		if (idx != -1) {

			requestedPath = JawrConstant.URL_SEPARATOR
					+ requestedPath.substring(idx + BundleRenderer.GZIP_PATH_PREFIX.length(), requestedPath.length());
			if (isValidRequestedPath(requestedPath)) {
				response.setHeader(CONTENT_ENCODING, GZIP);
				bundlesHandler.streamBundleTo(requestedPath, response.getOutputStream());
			} else {
				throw new ResourceNotFoundException(requestedPath);
			}

		} else {

			// In debug mode, we take in account the image generated from a
			// StreamGenerator like classpath Image generator
			// The following code will rewrite the URL path for the generated
			// images,
			// because in debug mode, we are retrieving the CSS resources
			// directly from the webapp
			// and if the CSS contains generated images, we should rewrite the
			// URL.
			BinaryResourcesHandler imgRsHandler = (BinaryResourcesHandler) servletContext
					.getAttribute(JawrConstant.BINARY_CONTEXT_ATTRIBUTE);
			if (imgRsHandler != null && this.jawrConfig.isDebugModeOn() && resourceType.equals(JawrConstant.CSS_TYPE)) {

				handleGeneratedCssInDebugMode(requestedPath, request, response, imgRsHandler);
			} else {

				if (isValidRequestedPath(requestedPath)) {
					Writer out = response.getWriter();
					bundlesHandler.writeBundleTo(requestedPath, out);
				} else {
					throw new ResourceNotFoundException(requestedPath);
				}
			}
		}
	}
251124
public static void dumpBlockData(int headerSize, int blockSize, byte[] data)
   {
      if (data != null)
      {
         System.out.println(ByteArrayHelper.hexdump(data, 0, headerSize, false));
         int index = headerSize;
         while (index < data.length)
         {
            System.out.println(ByteArrayHelper.hexdump(data, index, blockSize, false));
            index += blockSize;
         }
      }
   }
23437
public static File writeFileToTempDirectory(final byte[] data, final String fileName) {
		try {
			File file = createTempDirectory();
			File out = new File(file, fileName);
			out.deleteOnExit();
			file.deleteOnExit();
			return writeDataToFile(data, out);
		} catch (IOException e) {
			JKExceptionUtil.handle(e);
			return null;
		}
	}
1250749
public void copyFrom(String remotePath, String localPath) throws Exception {
        FileOutputStream fos = null;
        String rfile = remotePath;
        String lfile = localPath;

        // If localPath is a directory, create it if it does not exist
        String prefix = null;
        File local = new File(lfile);
        if (!local.exists()) {
            local.mkdir();
            prefix = lfile + File.separator;
        } else {
            if (local.isDirectory()) {
                prefix = lfile + File.separator;
            }
        }

        // exec 'scp -f rfile' remotely
        String command = "scp -f " + remotePath;
        Channel channel = this.session.openChannel("exec");
        ((ChannelExec) channel).setCommand(command);

        // get I/O streams for remote scp
        OutputStream out = channel.getOutputStream();
        InputStream in = channel.getInputStream();

        channel.connect();

        byte[] buf = new byte[1024];

        // send '\0'
        buf[0] = 0;
        out.write(buf, 0, 1);
        out.flush();

        while (true) {
            int c = checkAck(in);
            if (c != 'C') {
                break;
            }

            // read '0644 '
            in.read(buf, 0, 5);

            long filesize = 0L;
            while (true) {
                if (in.read(buf, 0, 1) < 0) {
                    // error
                    break;
                }
                if (buf[0] == ' ') {
                    break;
                }
                filesize = filesize * 10L + (long) (buf[0] - '0');
            }

            String file = null;
            for (int i = 0;; i++) {
                in.read(buf, i, 1);
                if (buf[i] == (byte) 0x0a) {
                    file = new String(buf, 0, i);
                    break;
                }
            }

            // send '\0'
            buf[0] = 0;
            out.write(buf, 0, 1);
            out.flush();

            // read a content of lfile
            fos = new FileOutputStream(prefix == null ? lfile : prefix + file);
            int foo;
            while (true) {
                if (buf.length < filesize) {
                    foo = buf.length;
                } else {
                    foo = (int) filesize;
                }
                foo = in.read(buf, 0, foo);
                if (foo < 0) {
                    // error
                    break;
                }
                fos.write(buf, 0, foo);
                filesize -= foo;
                if (filesize == 0L) {
                    break;
                }
            }
            fos.close();
            fos = null;

            if (checkAck(in) != 0) {
                throw new RuntimeException("Read error on inputstream");
            }

            // send '\0'
            buf[0] = 0;
            out.write(buf, 0, 1);
            out.flush();
        }
        channel.disconnect();
    }
934644
@Given("^I inbound copy '(.+?)' through a ssh connection to '(.+?)'$")
    public void copyFromRemoteFile(String remotePath, String localPath) throws Exception {
        commonspec.getRemoteSSHConnection().copyFrom(remotePath, localPath);
    }
465284
def remote_write(self, data):
        
        data = unicode2bytes(data)
        if self.remaining is not None:
            if len(data) > self.remaining:
                data = data[:self.remaining]
            self.fp.write(data)
            self.remaining = self.remaining - len(data)
        else:
            self.fp.write(data)
118570
public void get(String remoteFileName,
                    DataSink sink,
                    MarkerListener mListener)
        throws IOException, ClientException, ServerException {
        checkTransferParamsGet();

        localServer.store(sink);
        controlChannel.write(new Command("RETR", remoteFileName));

        transferRunSingleThread(localServer.getControlChannel(), mListener);
    }
900911
@Nonnull
    private static File writeDataToTempFileOrDie(@Nonnull final OutputStreamCallback callback,
                                                 @Nonnull final File targetFile,
                                                 @Nonnull final Logger log) throws IOException {
        Preconditions.checkNotNull(callback, "callback argument is required!");
        Preconditions.checkNotNull(log, "log argument is required!");
        Preconditions.checkNotNull(targetFile, "targetFile argument is required!");

        FileOutputStream fileOut = null;
        FileChannel fileChannel = null;
        try {
            final String targetFinalName = targetFile.getName();
            final File targetDirectory = targetFile.getParentFile();

            // open temporary file
            final File tmpFile = File.createTempFile(targetFinalName, ".tmp", targetDirectory);

            fileOut = new FileOutputStream(tmpFile);
            fileChannel = fileOut.getChannel();

            // make sure to use an output stream that flows THROUGH the FileChannel, so that FileChannel.force(true)
            // can do what it's supposed to

            // write the data AND flush it
            callback.writeAndFlushData(Channels.newOutputStream(fileChannel));

            return tmpFile;
        } finally {
            try {
                // fsync to disk (both data AND length)
                if (fileChannel != null) {
                    fileChannel.force(true);
                }
            } finally {
                // close the open file (if during an EXC,
                if (fileOut != null) {
                    fileOut.close();
                }
            }
        }
    }
245675
public static final void fileDump(String fileName, byte[] data)
   {
      try
      {
         FileOutputStream os = new FileOutputStream(fileName);
         os.write(data);
         os.close();
      }

      catch (IOException ex)
      {
         ex.printStackTrace();
      }
   }
206529
def write(file_name, file_contents, data)
      fname = cache_file_name(file_name, file_contents)
      @previous_entry = fname
      File.open(fname, "wb") {|file| Marshal::dump(data, file) }
    end
1247933
@Override
	protected void writeContent(String requestedPath, HttpServletRequest request, HttpServletResponse response)
			throws IOException, ResourceNotFoundException {

		String resourceName = requestedPath;
		if (!jawrConfig.getGeneratorRegistry().isGeneratedBinaryResource(resourceName)
				&& !resourceName.startsWith(URL_SEPARATOR)) {
			resourceName = URL_SEPARATOR + resourceName;
		}

		try (InputStream is = rsReaderHandler.getResourceAsStream(resourceName);
				OutputStream os = response.getOutputStream()) {
			IOUtils.copy(is, os);
		} catch (EOFException eofex) {
			LOGGER.debug("Browser cut off response", eofex);
		} catch (IOException e) {
			if (ClientAbortExceptionResolver.isClientAbortException(e)) {
				LOGGER.debug("Browser cut off response", e);
			} else {
				throw e;
			}
		}
	}
886966
function cacheSubmissionFile(params, fileToStreamTo, cb) {
  //If the files are remote, use the mbaas client
  logger.debug("cacheFiles: cacheSubmissionFile submission", {params: params, fileToStreamTo: fileToStreamTo});
  if (params.options.filesAreRemote) {
    return downloadFileFromMbaas(params, fileToStreamTo, cb);
  }

  //File is in the local database, load it there
  getSubmissionFile(params.connections, params.options, {
    _id: params.fileId
  }, function(err, fileDetails) {
    if (err) {
      logger.error("cacheFiles: cacheSubmissionFile getSubmissionFile", {error: err});
      return cb(err);
    }

    fileDetails.stream.on('error', function(err) {
      logger.error("cacheFiles: cacheSubmissionFile Error Streaming File With Id: " + params.fileId);
      return cb(err);
    });

    fileDetails.stream.on('end', function() {
      logger.debug("cacheFiles: cacheSubmissionFile Stream Complete For File With Id: " + params.fileId);
      return cb(undefined, fileDetails);
    });

    //Streaming The File
    fileDetails.stream.pipe(fileToStreamTo);
    fileDetails.stream.resume();
  });
}
1172458
def write_to_remote(self, filepath_from, filepath_to, mtime_dt=None):
        """"""

        self.__log.debug("Writing L[%s] -> R[%s]." % (filepath_from, 
                                                      filepath_to))

        with open(filepath_from, 'rb') as file_from:
            with SftpFile(self, filepath_to, 'w') as sf_to:
                while 1:
                    part = file_from.read(MAX_MIRROR_WRITE_CHUNK_SIZE)
                    sf_to.write(part)

                    if len(part) < MAX_MIRROR_WRITE_CHUNK_SIZE:
                        break

        if mtime_dt is None:
            mtime_dt = datetime.now()

        self.utimes_dt(filepath_to, mtime_dt, mtime_dt)
373068
def dump(self, as_json=True, commit_batch_size=100):
        
        connection = sqlite3.connect(self.destination)
        format_ = 'json' if as_json else 'xml'
        if not self._db_exists(connection):
            connection.execute(
                "CREATE TABLE grants (data text, format text)")

        # This will call the RemoteOAIRELoader.iter_grants and fetch
        # records from remote location.
        grants_iterator = self.loader.iter_grants(as_json=as_json)
        for idx, grant_data in enumerate(grants_iterator, 1):
            if as_json:
                grant_data = json.dumps(grant_data, indent=2)
            connection.execute(
                "INSERT INTO grants VALUES (?, ?)", (grant_data, format_))

            # Commit to database every N records
            if idx % commit_batch_size == 0:
                connection.commit()
        connection.commit()
        connection.close()
505515
function (fragmentKey, cachePath, skipCache, callback) {
    if (skipCache) {
      debug('  cache is disabled so...');
      callback(false);
    } else {
      fs.exists(cachePath + '/' + fragmentKey, callback);
    }
  }
12855
public void writeToFile(StringBuffer content, String filename, String encoding) throws NoSuchPathException, IOException{
		try {
			OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(filename), encoding);
			writer.write(content.toString(), 0, content.length());
			writer.flush();
			writer.close();
		} catch (FileNotFoundException e) {
			throw new NoSuchPathException(e);
		}
	}