ExternalSort { public static File sortAndSave(List<String> tmplist, Comparator<String> cmp, Charset cs, File tmpdirectory, boolean distinct, boolean usegzip) throws IOException { return sortAndSave(tmplist, cmp, cs, tmpdirectory, distinct, usegzip, identity()); }  static void sort(File input, File output); static long estimateBestSizeOfBlocks(File filetobesorted,
            int maxtmpfiles, long maxMemory); static List<File> sortInBatch(File file); static List<File> sortInBatch(File file, Comparator<String> cmp); static List<File> sortInBatch(File file, Comparator<String> cmp,
            boolean distinct); static List<File> sortInBatch(File file, Comparator<String> cmp,
                                         int maxtmpfiles, long maxMemory, Charset cs, File tmpdirectory,
                                         boolean distinct, int numHeader, boolean usegzip); static List<File> sortInBatch(File file, Comparator<T> cmp,
                                             int maxtmpfiles, long maxMemory, Charset cs, File tmpdirectory,
                                             boolean distinct, int numHeader, boolean usegzip,
                                             Function<T, String> typeToString, Function<String, T> stringToType); static List<File> sortInBatch(BufferedReader fbr, long actualFileSize, Comparator<T> cmp,
                                             int maxtmpfiles, long maxMemory, Charset cs, File tmpdirectory,
                                             boolean distinct, int numHeader, boolean usegzip,
                                             Function<T, String> typeToString, Function<String, T> stringToType); static List<File> sortInBatch(File file, Comparator<String> cmp,
            int maxtmpfiles, long maxMemory, Charset cs, File tmpdirectory, boolean distinct); static File sortAndSave(List<String> tmplist,
                                   Comparator<String> cmp, Charset cs, File tmpdirectory,
                                   boolean distinct, boolean usegzip); static File sortAndSave(List<T> tmplist,
                                   Comparator<T> cmp, Charset cs, File tmpdirectory,
                                   boolean distinct, boolean usegzip, Function<T, String> typeToString); static File sortAndSave(List<String> tmplist,
            Comparator<String> cmp, Charset cs, File tmpdirectory); static int mergeSortedFiles(List<File> files, File outputfile); static int mergeSortedFiles(List<File> files, File outputfile,
            final Comparator<String> cmp); static int mergeSortedFiles(List<File> files, File outputfile,
            final Comparator<String> cmp, boolean distinct); static int mergeSortedFiles(List<File> files, File outputfile,
                                           final Comparator<String> cmp, Charset cs, boolean distinct,
                                           boolean append, boolean usegzip); static int mergeSortedFiles(List<File> files, File outputfile,
                                           final Comparator<T> cmp, Charset cs, boolean distinct,
                                           boolean append, boolean usegzip, Function<T, String> typeToString,
                                           Function<String, T> stringToType); static int mergeSortedFiles(List<File> files,
                                           BufferedWriter fbw, final Comparator<T> cmp, Charset cs, boolean distinct,
                                           boolean usegzip, Function<T, String> typeToString,
                                           Function<String, T> stringToType); static int merge(BufferedWriter fbw, final Comparator<T> cmp, boolean distinct,
                            List<BinaryFileBuffer<T>> buffers, Function<T, String> typeToString); static int mergeSortedFiles(List<File> files, File outputfile,
            final Comparator<String> cmp, Charset cs, boolean distinct); static int mergeSortedFiles(List<File> files, File outputfile,
            final Comparator<String> cmp, Charset cs); static void displayUsage(); static void main(String[] args); static Comparator<String> defaultcomparator; }
@Test public void testSortAndSave() throws Exception { File f; String line; List<String> result; BufferedReader bf; List<String> sample = Arrays.asList(SAMPLE); Comparator<String> cmp = new Comparator<String>() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }; f = ExternalSort.sortAndSave(sample, cmp, Charset.defaultCharset(), null, false, false); assertNotNull(f); assertTrue(f.exists()); assertTrue(f.length() > 0); bf = new BufferedReader(new FileReader(f)); result = new ArrayList<String>(); while ((line = bf.readLine()) != null) { result.add(line); } bf.close(); assertArrayEquals(Arrays.toString(result.toArray()), EXPECTED_SORT_RESULTS, result.toArray()); }