### Question:
CopyDirectoryToLocal { public static void copy(Path from, File to) throws IOException { copy(from.getFileSystem(new Configuration()), from, to); }  static void main(String[] args); static void copy(Path from, File to); static void copy(FileSystem fs, Path from, File to);  }### Answer:
@Test public void testCopy() throws IOException { final List<String> dirs = Lists.newArrayList(); final List<String> rawDirs = Lists.newArrayList(); Random rand = new Random(); byte[] bytes = new byte[1000]; for (int i = 0; i < 5; ++i) { dirs.add(UUID.randomUUID().toString()); rawDirs.add(dirs.get(dirs.size() - 1)); File dir = new File(preFrom, dirs.get(dirs.size() - 1)); dir.mkdir(); for (int j = 0; j < 5; ++j) { OutputStream os = new FileOutputStream(new File(dir, Integer.toString(j))); rand.nextBytes(bytes); os.write(bytes); os.close(); } } for (int i = 0; i < 5; ++i) { dirs.add(UUID.randomUUID().toString()); rawDirs.add(dirs.get(dirs.size() - 1) + ".sqar"); File dir = new File(preFrom, rawDirs.get(rawDirs.size() - 1)); dir.mkdir(); for (int j = 0; j < 5; ++j) { OutputStream os = new FileOutputStream(new File(dir, Integer.toString(j))); rand.nextBytes(bytes); os.write(bytes); os.close(); } } for (File file : new File(preFrom).listFiles()) { CopyFromLocal.copy(fs, file, new Path(from, file.getName()), false); } CopyDirectoryToLocal.copy(fs, new Path(from), new File(to)); for (int i = 0; i < dirs.size(); ++i) { File d1 = new File(preFrom, rawDirs.get(i)); File d2 = new File(to, dirs.get(i)); for (int j = 0; j < 5; ++j) { assertTrue(Files.equal(new File(d1, Integer.toString(j)), new File(d2, Integer.toString(j)))); } } }