Reads <code>infile</code> and encodes it to <code>outfile</code>.

@param infile
Input file
@param aFile
Output file
@throws IOException
if there is an error
@since 2.2
343590
public static void encodeFileToFile (@Nonnull final String infile, @Nonnull final File aFile) throws IOException
  {
    final String encoded = encodeFromFile (infile);
    try (final OutputStream out = FileHelper.getBufferedOutputStream (aFile))
    {
      // Strict, 7-bit output.
      out.write (encoded.getBytes (PREFERRED_ENCODING));
    }
  }
1151068
public String process(File infile){		
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					new FileInputStream(infile), "UTF-8"));
			
			String line, data = "";
			while((line = reader.readLine()) != null){
				data += line + "\n";				
			}
			reader.close();
			
			String ret =  process(data);
			return ret;
		}
		catch (Exception e){
			System.out.println(e.getMessage());
			e.printStackTrace();
			return "";
		}
	}
954142
public static void decodeFileToFile(String infile, String outfile) throws IOException {
		byte[] decoded = Base64.decodeFromFile(infile);
		java.io.OutputStream out = null;
		try{
			out = new java.io.BufferedOutputStream(new FileOutputStream(outfile));
			out.write(decoded);
		} catch (IOException e) {
			throw e; // Catch and release to execute finally{}
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (Exception ex) {
			}
		}
	}
803210
public void toBinFile(final OutputStream out) throws IOException {
		final Charset cs = Charset.forName("UTF-8");
		final String header = String.format("%d %d\n", vocab.size(), layerSize);
		out.write(header.getBytes(cs));

		final double[] vector = new double[layerSize];
		final ByteBuffer buffer = ByteBuffer.allocate(4 * layerSize);
		buffer.order(ByteOrder.LITTLE_ENDIAN);	// The C version uses this byte order.
		for(int i = 0; i < vocab.size(); ++i) {
			out.write(String.format("%s ", vocab.get(i)).getBytes(cs));

			vectors.position(i * layerSize);
			vectors.get(vector);
			buffer.clear();
			for(int j = 0; j < layerSize; ++j)
				buffer.putFloat((float)vector[j]);
			out.write(buffer.array());

			out.write('\n');
		}

		out.flush();
	}

	/**
	 * @return {@link Word2VecModel} from the lines of the file in the text output format of the
	 * Word2Vec C open source project.
	 */
	@VisibleForTesting
	static Word2VecModel fromTextFile(String filename, List<String> lines) throws IOException {
		List<String> vocab = Lists.newArrayList();
		List<Double> vectors = Lists.newArrayList();
		int vocabSize = Integer.parseInt(lines.get(0).split(" ")[0]);
		int layerSize = Integer.parseInt(lines.get(0).split(" ")[1]);

		Preconditions.checkArgument(
				vocabSize == lines.size() - 1,
				"For file '%s', vocab size is %s, but there are %s word vectors in the file",
				filename,
				vocabSize,
				lines.size() - 1
		);

		for (int n = 1; n < lines.size(); n++) {
			String[] values = lines.get(n).split(" ");
			vocab.add(values[0]);

			// Sanity check
			Preconditions.checkArgument(
					layerSize == values.length - 1,
					"For file '%s', on line %s, layer size is %s, but found %s values in the word vector",
					filename,
					n,
					layerSize,
					values.length - 1
			);

			for (int d = 1; d < values.length; d++) {
				vectors.add(Double.parseDouble(values[d]));
			}
		}

		Word2VecModelThrift thrift = new Word2VecModelThrift()
				.setLayerSize(layerSize)
				.setVocab(vocab)
				.setVectors(vectors);
		return fromThrift(thrift);
	}

	/** @return {@link Word2VecTrainerBuilder} for training a model */
	public static Word2VecTrainerBuilder trainer() {
		return new Word2VecTrainerBuilder();
	}
}
547082
public static FileUtils.FileCopyResult gunzip(InputStream in, File outFile) throws IOException
  {
    try (GZIPInputStream gzipInputStream = gzipInputStream(in)) {
      NativeIO.chunkedCopy(gzipInputStream, outFile);
      return new FileUtils.FileCopyResult(outFile);
    }
  }
265258
public static void compress(File imageFile, File outFile, float quality) throws IORuntimeException {
		Img.from(imageFile).setQuality(quality).write(outFile);
	}
928710
public static void writeStringInto( String s, File outputFile ) throws IOException {
		InputStream in = new ByteArrayInputStream( s.getBytes( StandardCharsets.UTF_8 ));
		copyStream( in, outputFile );
	}
731831
protected function resolveOutputExtension(File $inFile, $outputPath = false)
    {
        $outDef = $this->getOutputDefinition();
        if ($outDef->getRequiredExtension()) {
            return $outDef->getRequiredExtension();
        }

        if ($outDef->getInheritInputExtension()) {
            return $inFile->getExtension();
        }

        if ($outputPath && $outDef->getInheritOutputPathExtension()) {
            $exp = explode(".", $outputPath);
            if (count($exp) > 1) {
                return end($exp);
            }
        }

        return $this->getOutputExtension();
    }
1229144
@SuppressWarnings("unchecked")
	public void open(File inputFile) throws IOException {
		deserializer = (Deserializer<OUT>) (readAsByteArray ? new ByteArrayDeserializer() : new TupleDeserializer());

		inputFile.getParentFile().mkdirs();

		if (inputFile.exists()) {
			inputFile.delete();
		}
		inputFile.createNewFile();
		inputRAF = new RandomAccessFile(inputFile, "rw");
		inputRAF.setLength(mappedFileSizeBytes);
		inputRAF.seek(mappedFileSizeBytes - 1);
		inputRAF.writeByte(0);
		inputRAF.seek(0);
		inputChannel = inputRAF.getChannel();
		fileBuffer = inputChannel.map(FileChannel.MapMode.READ_WRITE, 0, mappedFileSizeBytes);
	}
697147
@Nullable
  public static FileOutputStream getOutputStream (@Nonnull final File aFile, @Nonnull final EAppend eAppend)
  {
    ValueEnforcer.notNull (aFile, "File");
    ValueEnforcer.notNull (eAppend, "Append");

    if (internalCheckParentDirectoryExistanceAndAccess (aFile).isInvalid ())
      return null;

    // OK, parent is present and writable
    try
    {
      return new CountingFileOutputStream (aFile, eAppend);
    }
    catch (final FileNotFoundException ex)
    {
      if (LOGGER.isWarnEnabled ())
        LOGGER.warn ("Failed to create output stream for '" +
                     aFile +
                     "'; append: " +
                     eAppend +
                     ": " +
                     ex.getClass ().getName () +
                     " - " +
                     ex.getMessage ());
      return null;
    }
  }
1247007
public static void convert(String inFile, String outFile)
                    throws IOException, org.nd4j.linalg.exception.ND4JIllegalStateException {
        SameDiff tg = TFGraphMapper.getInstance().importGraph(new File(inFile));
        tg.asFlatFile(new File(outFile));
    }
1065311
private static boolean encodeFileToFile(String infile, String outfile)
	{
		boolean success = false;
		java.io.InputStream in = null;
		java.io.OutputStream out = null;
		try
		{
			in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.ENCODE);
			out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
			byte[] buffer = new byte[65536]; // 64K
			int read = -1;
			while ((read = in.read(buffer)) >= 0)
			{
				out.write(buffer, 0, read);
			} // end while: through file
			success = true;
		}
		catch (java.io.IOException exc)
		{
		}
		finally
		{
			try
			{
				in.close();
			}
			catch (Exception exc)
			{
			}
			try
			{
				out.close();
			}
			catch (Exception exc)
			{
			}
		} // end finally

		return success;
	}
187251
public final void fileCopy(File in, File out) throws IOException {
		assert in != null;
		assert out != null;
		getLog().debug("Copying file: " + in.toString() + " into " + out.toString()); //$NON-NLS-1$ //$NON-NLS-2$
		try (FileInputStream fis = new FileInputStream(in)) {
			try (FileChannel inChannel = fis.getChannel()) {
				try (FileOutputStream fos = new FileOutputStream(out)) {
					try (FileChannel outChannel = fos.getChannel()) {
						inChannel.transferTo(0, inChannel.size(), outChannel);
					}
				}
			}
		} finally {
			getBuildContext().refresh(out);
		}
	}
1003056
public static void unZipFiles(File zipFile, File outputFolder) throws IOException {
        InputStream is = new BufferedInputStream(new FileInputStream(zipFile));
        try {
            unZipFiles(is, outputFolder);
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
1018199
public static void unZip(File inFile, File unzipDir) throws IOException {
    Enumeration<? extends ZipEntry> entries;
    ZipFile zipFile = new ZipFile(inFile);

    try {
      entries = zipFile.entries();
      while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (!entry.isDirectory()) {
          InputStream in = zipFile.getInputStream(entry);
          try {
            File file = new File(unzipDir, entry.getName());
            if (!file.getParentFile().mkdirs()) {
              if (!file.getParentFile().isDirectory()) {
                throw new IOException("Mkdirs failed to create " +
                                      file.getParentFile().toString());
              }
            }
            OutputStream out = new FileOutputStream(file);
            try {
              byte[] buffer = new byte[8192];
              int i;
              while ((i = in.read(buffer)) != -1) {
                out.write(buffer, 0, i);
              }
            } finally {
              out.close();
            }
          } finally {
            in.close();
          }
        }
      }
    } finally {
      zipFile.close();
    }
  }
977678
public static ImageOutputStream getImageOutputStream(File outFile) throws IORuntimeException {
		try {
			return ImageIO.createImageOutputStream(outFile);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
519140
@Nonnull
  public ESuccess writeTo (@Nonnull final File aFile)
  {
    return writeTo (FileHelper.getOutputStream (aFile));
  }