HadoopFileSystem extends FileSystem<HadoopResourceId> { @Override protected void copy(List<HadoopResourceId> srcResourceIds, List<HadoopResourceId> destResourceIds) throws IOException { for (int i = 0; i < srcResourceIds.size(); ++i) { final org.apache.hadoop.fs.FileSystem fs = srcResourceIds.get(i).toPath().getFileSystem(configuration); final boolean success = FileUtil.copy( fs, srcResourceIds.get(i).toPath(), fs, destResourceIds.get(i).toPath(), false, true, fs.getConf()); if (!success) { throw new IOException( String.format( "Unable to copy resource %s to %s. No further information provided by underlying filesystem.", srcResourceIds.get(i).toPath(), destResourceIds.get(i).toPath())); } } } HadoopFileSystem(String scheme, Configuration configuration);   }
@Test public void testCopy() throws Exception { create("testFileA", "testDataA".getBytes(StandardCharsets.UTF_8)); create("testFileB", "testDataB".getBytes(StandardCharsets.UTF_8)); fileSystem.copy( ImmutableList.of(testPath("testFileA"), testPath("testFileB")), ImmutableList.of(testPath("copyTestFileA"), testPath("copyTestFileB"))); assertArrayEquals("testDataA".getBytes(StandardCharsets.UTF_8), read("testFileA", 0)); assertArrayEquals("testDataB".getBytes(StandardCharsets.UTF_8), read("testFileB", 0)); assertArrayEquals("testDataA".getBytes(StandardCharsets.UTF_8), read("copyTestFileA", 0)); assertArrayEquals("testDataB".getBytes(StandardCharsets.UTF_8), read("copyTestFileB", 0)); }
@Test(expected = FileNotFoundException.class) public void testCopySourceMissing() throws Exception { fileSystem.copy( ImmutableList.of(testPath("missingFile")), ImmutableList.of(testPath("copyTestFile"))); }