Splits all pages from the input TIFF file to one file per page in the
output directory.

@param inputFile
@param outputDirectory
@return generated files
@throws IOException
193161
public static List<File> split(File inputFile, File outputDirectory) throws IOException {
        ImageInputStream input = null;
        List<File> outputFiles = new ArrayList<>();
        try {
            input = ImageIO.createImageInputStream(inputFile);
            List<TIFFPage> pages = getPages(input);
            int pageNo = 1;
            for (TIFFPage tiffPage : pages) {
                ArrayList<TIFFPage> outputPages = new ArrayList<TIFFPage>(1);
                ImageOutputStream outputStream = null;
                try {
                    File outputFile = new File(outputDirectory, String.format("%04d", pageNo) + ".tif");
                    outputStream = ImageIO.createImageOutputStream(outputFile);
                    outputPages.clear();
                    outputPages.add(tiffPage);
                    writePages(outputStream, outputPages);
                    outputFiles.add(outputFile);
                }
                finally {
                    if (outputStream != null) {
                        outputStream.flush();
                        outputStream.close();
                    }
                }
                ++pageNo;
            }
        }
        finally {
            if (input != null) {
                input.close();
            }
        }
        return outputFiles;
    }
48830
List<File> getRecursiveThriftFiles(MavenProject project, String outputDirectory, List<File> files) throws IOException {
    HashFunction hashFun = Hashing.md5();
    File dir = new File(new File(project.getFile().getParent(), "target"), outputDirectory);
    if (dir.exists()) {
      URI baseDir = getFileURI(dir);
      for (File f : findThriftFilesInDirectory(dir)) {
        URI fileURI = getFileURI(f);
        String relPath = baseDir.relativize(fileURI).getPath();
        File destFolder = getResourcesOutputDirectory();
        destFolder.mkdirs();
        File destFile = new File(destFolder, relPath);
        if (!destFile.exists() || (destFile.isFile() && !Files.hash(f, hashFun).equals(Files.hash(destFile, hashFun)))) {
          getLog().info(format("copying %s to %s", f.getCanonicalPath(), destFile.getCanonicalPath()));
          copyFile(f, destFile);
        }
        files.add(destFile);
      }
    }
    Map<String, MavenProject> refs = project.getProjectReferences();
    for (String name : refs.keySet()) {
      getRecursiveThriftFiles(refs.get(name), outputDirectory, files);
    }
    return files;
  }
559666
public static void deleteGeneratedFiles( Application app, File outputDirectory ) {

		File target = new File( outputDirectory, app.getName());
		Utils.deleteFilesRecursivelyAndQuietly( target );
	}
628003
public static void readRAMFiles(DataInput in, RAMDirectory dir)
      throws IOException {
    int numFiles = in.readInt();

    for (int i = 0; i < numFiles; i++) {
      String name = Text.readString(in);
      long length = in.readLong();

      if (length > 0) {
        // can we avoid the extra copy?
        IndexOutput output = null;
        try {
          output = dir.createOutput(name);

          int position = 0;
          byte[] buffer = new byte[BUFFER_SIZE];

          while (position < length) {
            int len =
                position + BUFFER_SIZE <= length ? BUFFER_SIZE
                    : (int) (length - position);
            in.readFully(buffer, 0, len);
            output.writeBytes(buffer, 0, len);
            position += len;
          }
        } finally {
          if (output != null) {
            output.close();
          }
        }
      }
    }
  }
330196
public static void createFileBatchesLocal(File inputDirectory, boolean recursive, File outputDirectory, int batchSize) throws IOException {
        createFileBatchesLocal(inputDirectory, null, recursive, outputDirectory, batchSize);
    }
1268876
private void createDirAndFile(Path path) throws IOException {
			// create dir and file first if dir/file not exist
			File file = new File(path.toAbsolutePath().toString());
			File dir = file.getParentFile();
			if (dir != null && !dir.exists()) {
				dir.mkdirs();
			}
			if (!file.exists()) {
				file.createNewFile();
			}
	}
1144630
public static File getImageFile(File inputFile) throws IOException {
        File imageFile = inputFile;
        if (inputFile.getName().toLowerCase().endsWith(".pdf")) {
            imageFile = PdfUtilities.convertPdf2Tiff(inputFile);
        }
        return imageFile;
    }
1001943
public static void copy( File fileOrDirectory, File toDir )
  {
    File copy = new File( toDir, fileOrDirectory.getName() );
    if( fileOrDirectory.isDirectory() )
    {
      //noinspection ResultOfMethodCallIgnored
      copy.mkdir();
      for( File child : fileOrDirectory.listFiles() )
      {
        copy( child, copy );
      }
    }
    else
    {
      //noinspection ResultOfMethodCallIgnored
      try( InputStream is = new BufferedInputStream( new FileInputStream( fileOrDirectory ) );
           OutputStream os = new BufferedOutputStream( new FileOutputStream( copy ) ) )
      {
        StreamUtil.copy( is, os );
      }
      catch( Exception e )
      {
        throw new RuntimeException( e );
      }
    }
  }
666266
public static void splitPdf(String inputPdfFile, String outputPdfFile, String firstPage, String lastPage) {
        if (firstPage.trim().isEmpty()) {
            firstPage = "0";
        }
        if (lastPage.trim().isEmpty()) {
            lastPage = "0";
        }

        splitPdf(new File(inputPdfFile), new File(outputPdfFile), Integer.parseInt(firstPage), Integer.parseInt(lastPage));
    }
425959
public static void splitFile(String filePath, long[] splitPoints, String storageFolder) throws IOException {
        splitFile(new File(filePath), splitPoints, storageFolder);
    }
17919
private File validateOutputDirectory(File outputDirectory) {
        // Create output directory
        if (!outputDirectory.mkdir() && !outputDirectory.exists()) {
            throw new ArchiveExportException("Unable to create archive output directory - " + outputDirectory);
        }
        if (outputDirectory.isFile()) {
            throw new IllegalArgumentException("Unable to export exploded directory to "
                + outputDirectory.getAbsolutePath() + ", it points to a existing file");
        }

        return outputDirectory;
    }
497042
static File getOutputDirectory(MavenProject rootModule) {
        String directoryName = rootModule.getBuild().getDirectory() + "/" + OUTPUT_DIRECTORY;
        File directory = new File(directoryName);
        directory.mkdirs();
        return directory;
    }
797518
public void genCode(String language, File outputDirectory)
            throws IOException {
        if ("c++".equals(language)) {
            CppGenerator gen = new CppGenerator(mName, mInclFiles, mRecords,
                    outputDirectory);
            gen.genCode();
        } else if ("java".equals(language)) {
            JavaGenerator gen = new JavaGenerator(mName, mInclFiles, mRecords,
                    outputDirectory);
            gen.genCode();
        } else if ("c".equals(language)) {
            CGenerator gen = new CGenerator(mName, mInclFiles, mRecords,
                    outputDirectory);
            gen.genCode();
        } else {
            throw new IOException("Cannnot recognize language:" + language);
        }
    }
525587
private static void doCopyFile(File srcFile, File destFile) throws IOException
   {
      if (destFile.exists() && destFile.isDirectory())
      {
         throw new IOException("Destination '" + destFile + "' exists but is a directory");
      }

      FileInputStream fis = null;
      FileOutputStream fos = null;
      FileChannel input = null;
      FileChannel output = null;
      try
      {
         fis = new FileInputStream(srcFile);
         fos = new FileOutputStream(destFile);
         input = fis.getChannel();
         output = fos.getChannel();
         long size = input.size();
         long pos = 0;
         long count = 0;
         while (pos < size)
         {
            count = (size - pos) > FIFTY_MB ? FIFTY_MB : (size - pos);
            pos += output.transferFrom(input, pos, count);
         }
      }
      finally
      {
         Streams.closeQuietly(output);
         Streams.closeQuietly(fos);
         Streams.closeQuietly(input);
         Streams.closeQuietly(fis);
      }

      if (srcFile.length() != destFile.length())
      {
         throw new IOException("Failed to copy full contents from '" +
                  srcFile + "' to '" + destFile + "'");
      }
   }
192968
public static Set<Path> getPaths(InputFormat<?, ?> inputFormat, Path location) throws IOException {
    JobConf jobConf = new JobConf(getHadoopConfiguration());

    Set<Path> paths = Sets.newHashSet();

    FileInputFormat.addInputPaths(jobConf, location.toString());
    InputSplit[] splits = inputFormat.getSplits(jobConf, 1000);
    for (InputSplit split : splits) {
      if (!(split instanceof FileSplit)) {
        throw new IOException("Not a file split. Found " + split.getClass().getName());
      }
      FileSplit fileSplit = (FileSplit) split;
      paths.add(fileSplit.getPath());
    }

    return paths;
  }
575064
public static void extractZipArchive( File zipFile, File targetDirectory )
	throws IOException {

		extractZipArchive( zipFile, targetDirectory, null, null );
	}
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);
        }
    }