@Override protected void processArguments(LinkedList<PathData> args) throws IOException { if (!dst.exists) { dst.fs.create(dst.path, false).close(); } FileInputStream is = null; try (FSDataOutputStream fos = dst.fs.append(dst.path)) { if (readStdin) { if (args.size() == 0) { IOUtils.copyBytes(System.in, fos, DEFAULT_IO_LENGTH); } else { throw new IOException( "stdin (-) must be the sole input argument when present"); } } // Read in each input file and write to the target. for (PathData source : args) { is = new FileInputStream(source.toFile()); IOUtils.copyBytes(is, fos, DEFAULT_IO_LENGTH); IOUtils.closeStream(is); is = null; } } finally { if (is != null) { IOUtils.closeStream(is); } } } }
is = new FileInputStream(source.toFile()); IOUtils.copyBytes(is, fos, DEFAULT_IO_LENGTH); IOUtils.closeStream(is);
@Test (timeout = 30000) public void testToFile() throws Exception { PathData item = new PathData(".", conf); assertEquals(new File(testDir.toString()), item.toFile()); item = new PathData("d1/f1", conf); assertEquals(new File(testDir + "/d1/f1"), item.toFile()); item = new PathData(testDir + "/d1/f1", conf); assertEquals(new File(testDir + "/d1/f1"), item.toFile()); }
is = new FileInputStream(source.toFile()); IOUtils.copyBytes(is, fos, DEFAULT_IO_LENGTH); IOUtils.closeStream(is);
is = new FileInputStream(source.toFile()); IOUtils.copyBytes(is, fos, DEFAULT_IO_LENGTH); IOUtils.closeStream(is);
is = new FileInputStream(source.toFile()); IOUtils.copyBytes(is, fos, DEFAULT_IO_LENGTH); IOUtils.closeStream(is);
@Test (timeout = 30000) public void testToFile() throws Exception { PathData item = new PathData(".", conf); assertEquals(new File(testDir.toString()), item.toFile()); item = new PathData("d1/f1", conf); assertEquals(new File(testDir + "/d1/f1"), item.toFile()); item = new PathData(testDir + "/d1/f1", conf); assertEquals(new File(testDir + "/d1/f1"), item.toFile()); }
@Test (timeout = 5000) public void testToFileRawWindowsPaths() throws Exception { if (!Path.WINDOWS) { return; } // Can we handle raw Windows paths? The files need not exist for // these tests to succeed. String[] winPaths = { "n:\\", "N:\\", "N:\\foo", "N:\\foo\\bar", "N:/", "N:/foo", "N:/foo/bar" }; PathData item; for (String path : winPaths) { item = new PathData(path, conf); assertEquals(new File(path), item.toFile()); } item = new PathData("foo\\bar", conf); assertEquals(new File(testDir + "\\foo\\bar"), item.toFile()); }
@Test (timeout = 5000) public void testToFileRawWindowsPaths() throws Exception { if (!Path.WINDOWS) { return; } // Can we handle raw Windows paths? The files need not exist for // these tests to succeed. String[] winPaths = { "n:\\", "N:\\", "N:\\foo", "N:\\foo\\bar", "N:/", "N:/foo", "N:/foo/bar" }; PathData item; for (String path : winPaths) { item = new PathData(path, conf); assertEquals(new File(path), item.toFile()); } item = new PathData("foo\\bar", conf); assertEquals(new File(testDir + "\\foo\\bar"), item.toFile()); }