LocalFileSystem extends FileSystem<LocalResourceId> { @Override protected void copy(List<LocalResourceId> srcResourceIds, List<LocalResourceId> destResourceIds) throws IOException { checkArgument( srcResourceIds.size() == destResourceIds.size(), "Number of source files %s must equal number of destination files %s", srcResourceIds.size(), destResourceIds.size()); int numFiles = srcResourceIds.size(); for (int i = 0; i < numFiles; i++) { LocalResourceId src = srcResourceIds.get(i); LocalResourceId dst = destResourceIds.get(i); LOG.debug("Copying {} to {}", src, dst); File parent = dst.getCurrentDirectory().getPath().toFile(); if (!parent.exists()) { checkArgument( parent.mkdirs() || parent.exists(), "Unable to make output directory %s in order to copy into file %s", parent, dst.getPath()); } Files.copy( src.getPath(), dst.getPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); } } LocalFileSystem();   }
@Test public void testCopyWithExistingSrcFile() throws Exception { Path srcPath1 = temporaryFolder.newFile().toPath(); Path srcPath2 = temporaryFolder.newFile().toPath(); Path destPath1 = temporaryFolder.getRoot().toPath().resolve("nonexistentdir").resolve("dest1"); Path destPath2 = srcPath2.resolveSibling("dest2"); createFileWithContent(srcPath1, "content1"); createFileWithContent(srcPath2, "content2"); localFileSystem.copy( toLocalResourceIds(ImmutableList.of(srcPath1, srcPath2), false ), toLocalResourceIds(ImmutableList.of(destPath1, destPath2), false )); assertContents( ImmutableList.of(destPath1, destPath2), ImmutableList.of("content1", "content2")); }