Writes the contents of {@link #EXAMPLE_NAMES} into a file in the job input directory in HDFS.

@param conf     the Hadoop config
@param inputDir the HDFS input directory where we'll write a file
@throws IOException if something goes wrong
979187
public static void writeInput(Configuration conf, Path inputDir) throws IOException {
        FileSystem fs = FileSystem.get(conf);

        if (fs.exists(inputDir)) {
            throw new IOException(String.format("Input directory '%s' exists - please remove and rerun this example", inputDir));
        }

        OutputStreamWriter writer = new OutputStreamWriter(fs.create(new Path(inputDir, "input.txt")));
        for (String name : EXAMPLE_NAMES) {
            writer.write(name);
        }
        IOUtils.closeStream(writer);
    }
676970
public void write(final Writer outputWriter) throws IOException {
    try (final DataInputStream keyStream = entry.getKeyStream();
         final DataInputStream valueStream = entry.getValueStream();) {
      outputWriter.write("Container: ");
      outputWriter.write(keyStream.readUTF());
      outputWriter.write("\n");
      this.writeFiles(valueStream, outputWriter);
    }
  }
1111417
@Override
	public void writeEntry(String entryName, InputStream inputStream) throws IOException {
		JarArchiveEntry entry = new JarArchiveEntry(entryName);
		writeEntry(entry, new InputStreamEntryWriter(inputStream, true));
	}
316009
public static void writeStringToFile(String path, String toWrite, SparkContext sc) throws IOException {
        writeStringToFile(path, toWrite, sc.hadoopConfiguration());
    }
350424
public void writeFile(File inputFile, String jarPath) throws IOException {

		// Get an input stream on the file.
		FileInputStream fis = new FileInputStream(inputFile);
		try {
			// create the zip entry
			JarEntry entry = new JarEntry(jarPath);
			entry.setTime(inputFile.lastModified());
			writeEntry(fis, entry);

		} finally {
			// close the file stream used to read the file
			fis.close();
		}
	}
1000485
protected void writeHeader()
		throws ConfigurationException, IOException
	{

		if (this.output != null) {
			close();
		}

		this.counter++;

		String filePath = PATH_OUTPUT_SQL_FILES + this.outputName +"_"+counter;

		this.output = OutputFactory.getOutputStream(filePath);

		this.dataArchive = new File(filePath);

		this.output.flush();
	}
749518
public static void main(String[] args) throws IOException {
    Collection<? extends PropertyKey> defaultKeys = PropertyKey.defaultKeys();
    defaultKeys.removeIf(key -> key.isHidden());
    String homeDir = new InstancedConfiguration(ConfigurationUtils.defaults())
        .get(PropertyKey.HOME);
    // generate CSV files
    String filePath = PathUtils.concatPath(homeDir, CSV_FILE_DIR);
    writeCSVFile(defaultKeys, filePath);
    // generate YML files
    filePath = PathUtils.concatPath(homeDir, YML_FILE_DIR);
    writeYMLFile(defaultKeys, filePath);
  }
176423
public static void writeConfigFile(OutputStream outputStream, File searchDir) throws SQLException, IOException {
		writeConfigFile(outputStream, searchDir, false);
	}
688352
public static void copyBytes(InputStream in, OutputStream out, Configuration conf)
    throws IOException {
    copyBytes(in, out, conf.getInt("io.file.buffer.size", 4096), true);
  }
112482
public static void copyToHDFS(String localFile, String hdfsFile) throws IOException {

    String hadoopConfPath; 

    if (Environment.getProperty("hadoop.conf.path") == null)
      hadoopConfPath = "../../../conf";
    else
      hadoopConfPath = Environment.getProperty("hadoop.conf.path");

    // Read the configuration for the Hadoop environment
    Configuration hadoopConf = new Configuration();
    hadoopConf.addResource(new Path(hadoopConfPath + "/hadoop-default.xml"));
    hadoopConf.addResource(new Path(hadoopConfPath + "/hadoop-site.xml"));

    // System.out.println(hadoopConf.get("hadoop.tmp.dir"));
    // System.out.println(hadoopConf.get("fs.default.name"));
    FileSystem fs = FileSystem.get(hadoopConf);

    // HadoopDFS deals with Path
    Path inFile = new Path("file://" + localFile);
    Path outFile = new Path(hadoopConf.get("fs.default.name") + hdfsFile);

     // Read from and write to new file
    Environment.logInfo("Uploading to HDFS (file " + outFile + ") ...");
    fs.copyFromLocalFile(false, inFile, outFile);
  }
452102
public static void dumpStoreDefsToFile(String outputDirName,
                                           String fileName,
                                           List<StoreDefinition> storeDefs) {

        if(outputDirName != null) {
            File outputDir = new File(outputDirName);
            if(!outputDir.exists()) {
                Utils.mkdirs(outputDir);
            }

            try {
                FileUtils.writeStringToFile(new File(outputDirName, fileName),
                                            new StoreDefinitionsMapper().writeStoreList(storeDefs));
            } catch(IOException e) {
                logger.error("IOException during dumpStoreDefsToFile: " + e);
            }
        }
    }
963940
function write(conf) {
  var contents = process.pid + EOL
    , file = conf.get(ConfigKey.PIDFILE);
  // can be the empty string
  if(file) {
    try {
      fs.writeFileSync(file, contents);
      log.notice('wrote pid %s to %s', process.pid, file);
    }catch(e) {
      log.warning('failed to write pid file (%s): %s', file, e.message);
    }
  }
}
871238
public void writeConfiguration(final YarnClusterSubmissionFromCS yarnClusterSubmissionFromCS,
                                 final JobFolder jobFolderOnDFS) throws IOException {
    final File yarnAppParametersFile = new File(yarnClusterSubmissionFromCS.getDriverFolder(),
        fileNames.getYarnBootstrapAppParamFilePath());

    final File yarnJobParametersFile = new File(yarnClusterSubmissionFromCS.getDriverFolder(),
        fileNames.getYarnBootstrapJobParamFilePath());

    try (final FileOutputStream appFileOutputStream = new FileOutputStream(yarnAppParametersFile)) {
      try (final FileOutputStream jobFileOutputStream = new FileOutputStream(yarnJobParametersFile)) {
        // this is mainly a test hook.
        writeAvroYarnAppSubmissionParametersToOutputStream(yarnClusterSubmissionFromCS, appFileOutputStream);
        writeAvroYarnJobSubmissionParametersToOutputStream(
            yarnClusterSubmissionFromCS, jobFolderOnDFS.getPath().toString(), jobFileOutputStream);
      }
    }
  }
1236567
protected void writeFile(String basename, T content,
			Function2<? super File, ? super String, ? extends File> outputDirectoryFilter) {
		// Create the file.
		// Encode
		final byte[] bytes = content.toString().getBytes(Charset.forName(getCodeConfig().getEncoding()));
		writeFile(basename, bytes, outputDirectoryFilter);
	}
710967
public void initialize(FileSystem fileSystem, HdfsStoreConfig config, long initializeTime)
            throws IOException, ParseException
    {
        this.fileSystem = fileSystem;
        this.config = config;

        if (this.config.getOutputUri().endsWith("/") == false)
        {
            this.outputDirUri = this.config.getOutputUri() + "/";
        }
        else
        {
            this.outputDirUri = this.config.getOutputUri();
        }

        // ファイル切替間隔が不正の場合誤動作を誘発するため、
        // バリデーションをかけて不正な場合はログ出力を行ってデフォルト値を設定する。
        initializeIntervalConf(this.config.getFileSwitchIntarval(),
                this.config.getFileSwitchIntervalUnit());

        // ファイル切替インターバル（単位）をベースに時刻部分のフォーマットを取得。
        this.dateFormat = new SimpleDateFormat(TimeUnitUtil.getDatePattern(this.switchTimeUnit));

        // ファイル名称初期化用の時刻を生成する。
        long initialBaseTime = TimeIntervalFormatUtil.generateInitialBaseTime(initializeTime,
                this.switchTimeInterval, this.switchTimeUnit);

        this.currentOutputUri = generateOutputFileBase(this.outputDirUri,
                this.config.getFileNameHeader(), this.config.getFileNameBody(), this.dateFormat,
                initialBaseTime);

        this.nextSwitchTime = initialBaseTime
                + this.switchTimeUnit.toMillis(this.switchTimeInterval);

        updateWriter();

        logger.info("HDFSOutputSwitcher initialized.");
    }
1050998
private static void fillInMissingMapOutputs(FileSystem fs, 
                                              TaskAttemptID taskId,
                                              int numMaps,
                                              JobConf conf) throws IOException {
    Class<? extends WritableComparable> keyClass
        = conf.getMapOutputKeyClass().asSubclass(WritableComparable.class);
    Class<? extends Writable> valueClass
        = conf.getMapOutputValueClass().asSubclass(Writable.class);
    MapOutputFile namer = new MapOutputFile(taskId.getJobID());
    namer.setConf(conf);
    for(int i=0; i<numMaps; i++) {
      Path f = namer.getInputFile(i, taskId);
      if (!fs.exists(f)) {
        LOG.info("Create missing input: " + f);
        SequenceFile.Writer out =
          SequenceFile.createWriter(fs, conf, f, keyClass, valueClass);
        out.close();
      }
    }    
  }
1142764
public static void writeStringToFile(String path, String toWrite, Configuration hadoopConfig) throws IOException {
        FileSystem fileSystem = FileSystem.get(hadoopConfig);
        try (BufferedOutputStream bos = new BufferedOutputStream(fileSystem.create(new Path(path)))) {
            bos.write(toWrite.getBytes("UTF-8"));
        }
    }