FileUtil { public static boolean copyMerge(FileSystem srcFS, Path srcDir, FileSystem dstFS, Path dstFile, boolean deleteSource, Configuration conf, String addString) throws IOException { dstFile = checkDest(srcDir.getName(), dstFS, dstFile, false); if (!srcFS.getFileStatus(srcDir).isDirectory()) return false; OutputStream out = dstFS.create(dstFile); try { FileStatus contents[] = srcFS.listStatus(srcDir); Arrays.sort(contents); for (int i = 0; i < contents.length; i++) { if (contents[i].isFile()) { InputStream in = srcFS.open(contents[i].getPath()); try { IOUtils.copyBytes(in, out, conf, false); if (addString!=null) out.write(addString.getBytes("UTF-8")); } finally { in.close(); } } } } finally { out.close(); } if (deleteSource) { return srcFS.delete(srcDir, true); } else { return true; } }  static Path[] stat2Paths(FileStatus[] stats); static Path[] stat2Paths(FileStatus[] stats, Path path); static boolean fullyDelete(final File dir); static boolean fullyDelete(final File dir, boolean tryGrantPermissions); static String readLink(File f); static boolean fullyDeleteContents(final File dir); static boolean fullyDeleteContents(final File dir, final boolean tryGrantPermissions); @Deprecated static void fullyDelete(FileSystem fs, Path dir); static boolean copy(FileSystem srcFS, Path src, 
                             FileSystem dstFS, Path dst, 
                             boolean deleteSource,
                             Configuration conf); static boolean copy(FileSystem srcFS, Path[] srcs, 
                             FileSystem dstFS, Path dst,
                             boolean deleteSource, 
                             boolean overwrite, Configuration conf); static boolean copy(FileSystem srcFS, Path src, 
                             FileSystem dstFS, Path dst, 
                             boolean deleteSource,
                             boolean overwrite,
                             Configuration conf); static boolean copy(FileSystem srcFS, FileStatus srcStatus,
                             FileSystem dstFS, Path dst,
                             boolean deleteSource,
                             boolean overwrite,
                             Configuration conf); static boolean copyMerge(FileSystem srcFS, Path srcDir, 
                                  FileSystem dstFS, Path dstFile, 
                                  boolean deleteSource,
                                  Configuration conf, String addString); static boolean copy(File src,
                             FileSystem dstFS, Path dst,
                             boolean deleteSource,
                             Configuration conf); static boolean copy(FileSystem srcFS, Path src, 
                             File dst, boolean deleteSource,
                             Configuration conf); static String makeShellPath(String filename); static String makeShellPath(File file); static String makeShellPath(File file, boolean makeCanonicalPath); static long getDU(File dir); static void unZip(File inFile, File unzipDir); static void unTar(File inFile, File untarDir); static int symLink(String target, String linkname); static int chmod(String filename, String perm
                          ); static int chmod(String filename, String perm, boolean recursive); static void setOwner(File file, String username,
      String groupname); static boolean setReadable(File f, boolean readable); static boolean setWritable(File f, boolean writable); static boolean setExecutable(File f, boolean executable); static boolean canRead(File f); static boolean canWrite(File f); static boolean canExecute(File f); static void setPermission(File f, FsPermission permission
                                   ); static final File createLocalTempFile(final File basefile,
                                               final String prefix,
                                               final boolean isDeleteOnExit); static void replaceFile(File src, File target); static File[] listFiles(File dir); static String[] list(File dir); static String[] createJarWithClassPath(String inputClassPath, Path pwd,
      Map<String, String> callerEnv); static String[] createJarWithClassPath(String inputClassPath, Path pwd,
      Path targetDir,
      Map<String, String> callerEnv); static final int SYMLINK_NO_PRIVILEGE; }
@Test (timeout = 30000) public void testCopyMergeSingleDirectory() throws IOException { setupDirs(); boolean copyMergeResult = copyMerge("partitioned", "tmp/merged"); Assert.assertTrue("Expected successful copyMerge result.", copyMergeResult); File merged = new File(TEST_DIR, "tmp/merged"); Assert.assertTrue("File tmp/merged must exist after copyMerge.", merged.exists()); BufferedReader rdr = new BufferedReader(new FileReader(merged)); try { Assert.assertEquals("Line 1 of merged file must contain \"foo\".", "foo", rdr.readLine()); Assert.assertEquals("Line 2 of merged file must contain \"bar\".", "bar", rdr.readLine()); Assert.assertNull("Expected end of file reading merged file.", rdr.readLine()); } finally { rdr.close(); } }