// Path: src/main/java/com/alexholmes/hadooputils/io/FileUtils.java
// public final class FileUtils {
// 
//     /**
//      * Private ctor to prevent instantiation.
//      */
//     private FileUtils() {
//     }
// 
//     /**
//      * Read the contents of the supplied file into a list.
//      *
//      * @param fs a Hadoop file system
//      * @param p  the file path
//      * @return array of lines in the file
//      * @throws java.io.IOException if something goes wrong
//      */
//     public static List<String> readLines(final FileSystem fs, final Path p)
//             throws IOException {
//         InputStream stream = fs.open(p);
//         try {
//             return IOUtils.readLines(stream);
//         } finally {
//             stream.close();
//         }
//     }
// 
//     /**
//      * Writes the array list into a file as newline-separated lines.
//      *
//      * @param fs a Hadoop file system
//      * @param p  the file path
//      * @return array of lines to write to the file
//      * @throws java.io.IOException if something goes wrong
//      */
//     public static void writeLines(Collection<?> lines, final FileSystem fs, final Path p)
//             throws IOException {
//         OutputStream stream = fs.create(p);
//         try {
//             IOUtils.writeLines(lines, IOUtils.LINE_SEPARATOR, stream);
//         } finally {
//             stream.close();
//         }
//     }
// }


import static org.junit.Assert.assertEquals;
import com.alexholmes.hadooputils.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathFilter;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

        IOUtils.writeLines(inputs, String.format("%n"), stream);

        stream.close();

        return this;
    }

    /**
     * Called after the MapReduce job has completed, to verify that the outputs
     * generated by the MapReduce job align with the expected outputs that were
     * set with calls to {@link #addExpectedOutput(String)} and
     * {@link #addExpectedOutput(String...)}.
     *
     * @return a reference to this object
     * @throws IOException if something goes wrong
     */
    public TextIOJobBuilder verifyResults() throws IOException {

        FileStatus[] outputFiles = fs.listStatus(outputPath, new PathFilter() {
            @Override
            public boolean accept(final Path path) {
                return path.getName().startsWith("part");
            }
        });

        System.out.println("Output files: " + StringUtils.join(outputFiles));

        int i = 0;
        for (FileStatus file : outputFiles) {
// Path: src/main/java/com/alexholmes/hadooputils/io/FileUtils.java
// public final class FileUtils {
// 
//     /**
//      * Private ctor to prevent instantiation.
//      */
//     private FileUtils() {
//     }
// 
//     /**
//      * Read the contents of the supplied file into a list.
//      *
//      * @param fs a Hadoop file system
//      * @param p  the file path
//      * @return array of lines in the file
//      * @throws java.io.IOException if something goes wrong
//      */
//     public static List<String> readLines(final FileSystem fs, final Path p)
//             throws IOException {
//         InputStream stream = fs.open(p);
//         try {
//             return IOUtils.readLines(stream);
//         } finally {
//             stream.close();
//         }
//     }
// 
//     /**
//      * Writes the array list into a file as newline-separated lines.
//      *
//      * @param fs a Hadoop file system
//      * @param p  the file path
//      * @return array of lines to write to the file
//      * @throws java.io.IOException if something goes wrong
//      */
//     public static void writeLines(Collection<?> lines, final FileSystem fs, final Path p)
//             throws IOException {
//         OutputStream stream = fs.create(p);
//         try {
//             IOUtils.writeLines(lines, IOUtils.LINE_SEPARATOR, stream);
//         } finally {
//             stream.close();
//         }
//     }
// }


// Path: src/main/java/com/alexholmes/hadooputils/test/TextIOJobBuilder.java
import static org.junit.Assert.assertEquals;
import com.alexholmes.hadooputils.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathFilter;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


        IOUtils.writeLines(inputs, String.format("%n"), stream);

        stream.close();

        return this;
    }

    /**
     * Called after the MapReduce job has completed, to verify that the outputs
     * generated by the MapReduce job align with the expected outputs that were
     * set with calls to {@link #addExpectedOutput(String)} and
     * {@link #addExpectedOutput(String...)}.
     *
     * @return a reference to this object
     * @throws IOException if something goes wrong
     */
    public TextIOJobBuilder verifyResults() throws IOException {

        FileStatus[] outputFiles = fs.listStatus(outputPath, new PathFilter() {
            @Override
            public boolean accept(final Path path) {
                return path.getName().startsWith("part");
            }
        });

        System.out.println("Output files: " + StringUtils.join(outputFiles));

        int i = 0;
        for (FileStatus file : outputFiles) {
            List<String> actualLines = FileUtils.readLines(fs, file.getPath());