package com.github.sparkcaller;

import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Properties;

public class Utils {
    /*
    Get all the files in the folder 'pathToFolder' ending with 'fileExtension', and return them as an ArrayList.
    */
    public static ArrayList<File> getFilesInFolder(String pathToFolder, String fileExtension) {
        File folder = new File(pathToFolder);
        File[] listOfFiles = folder.listFiles();

        if (listOfFiles != null) {
            ArrayList<File> bamFiles = new ArrayList<File>();

            for (File file : listOfFiles) {
                if (file.isFile() && file.getName().endsWith(fileExtension)) {
                    bamFiles.add(file);
                }
            }
            return bamFiles;
        }

        System.err.println(String.format("The folder: %s is either empty or was not found!", folder.getName()));
        return null;
    }

    public static String removeExtenstion(String filepath, String ext) {
        return filepath.substring(0, filepath.length() - (ext.length()+1));
    }

    public static Properties loadConfigFile(String configFilepath) {
        Properties prop = new Properties();
        InputStream input = null;

        try {
            input = new FileInputStream(configFilepath);
            prop.load(input);
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return prop;
    }

    public static File moveToDir(File fileToCopy, String targetPath) throws IOException {
        File outputFile = new File(targetPath, fileToCopy.getName());
        FileUtils.moveFile(fileToCopy, outputFile);

        return outputFile;
    }

    public static ArrayList<String> possibleStringToArgs(String maybeString) {
        if (maybeString == null) {
            return null;
        }

        String[] args = maybeString.split("\\s+");
        return new ArrayList<>(Arrays.asList(args));
    }
}

@@ -141,16 +141,37 @@
 op.fs.*;
+%0Aimport scala.Tuple2;
 %0A%0Aimport
@@ -235,16 +235,39 @@
 Arrays;%0A
+import java.util.List;%0A
 import j
@@ -1832,32 +1832,463 @@
 rn prop;%0A    %7D%0A%0A
+    public static List%3CTuple2%3CString, File%3E%3E moveFilesToDir(List%3CTuple2%3CString, File%3E%3E files, String outputFolder) throws IOException %7B%0A        List%3CTuple2%3CString, File%3E%3E outputFiles = new ArrayList%3C%3E();%0A        for (Tuple2%3CString, File%3E tuple : files) %7B%0A            File newFile = Utils.moveToDir(tuple._2, outputFolder);%0A            outputFiles.add(new Tuple2%3C%3E(tuple._1, newFile));%0A        %7D%0A%0A        return outputFiles;%0A    %7D%0A%0A
     public stati

Add a utility function for moving a list of files to a folder.