@Override public long copy(final Path source, final OutputStream out) throws IOException, SecurityException { return Files.copy(source, out); }
@Override public long copy(final InputStream in, final Path target, final CopyOption... options) throws IOException, FileAlreadyExistsException, DirectoryNotEmptyException, UnsupportedOperationException, SecurityException { return Files.copy(in, target, options); }
@Override public Path copy(final Path source, final Path target, final CopyOption... options) throws UnsupportedOperationException, FileAlreadyExistsException, DirectoryNotEmptyException, IOException, SecurityException { return Files.copy(source, target, options); }
@Override public FileVisitResult preVisitDirectory(final org.uberfire.java.nio.file.Path src, final BasicFileAttributes attrs) { final org.uberfire.java.nio.file.Path tgt = target.resolve(source.relativize(src)); try { Files.copy(src, tgt, StandardCopyOption.REPLACE_EXISTING); // } catch (FileAlreadyExistsException x) { } catch (Exception x) { x.printStackTrace(); //Swallow } return FileVisitResult.CONTINUE; }
@Test public void copyPath2OutInvalidOption() { assertThatThrownBy(() -> Files.copy(null, null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'source' should be not null!"); }
@Test public void copyNull3() { assertThatThrownBy(() -> Files.copy((Path) null, (Path) null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'source' should be not null!"); }
@Test public void copyNull2() { assertThatThrownBy(() -> Files.copy((Path) null, Paths.get("/temp"))) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'source' should be not null!"); }
@Test public void copyNull1() { assertThatThrownBy(() -> Files.copy(newTempDir(), (Path) null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'target' should be not null!"); }
@Test public void copyPath2OutNull2() { assertThatThrownBy(() -> Files.copy(Files.createTempFile("foo", "bar"), null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'out' should be not null!"); }
@Test public void copyIn2PathNull1() { assertThatThrownBy(() -> Files.copy((InputStream) null, newTempDir().resolve("my_new_file.txt"), REPLACE_EXISTING)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'in' should be not null!"); }
@Test public void copyIn2PathNull2() { assertThatThrownBy(() -> Files.copy(Files.newInputStream(Files.createTempFile("foo", "bar")), null, REPLACE_EXISTING)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'target' should be not null!"); }
@Test public void copyPath2OutNull1() { assertThatThrownBy(() -> { try (OutputStream os = Files.newOutputStream(newTempDir().resolve("my_new_file.txt"))) { Files.copy(null, os); } }) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'source' should be not null!"); }
@Test public void copyIn2PathNull4() { assertThatThrownBy(() -> Files.copy(Files.newInputStream(Files.createTempFile("foo", "bar")), newTempDir().resolve("my_new_file.txt"), new CopyOption[]{null})) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'opt' should be not null!"); }
@Test public void copyDirDirectoryNotEmptyException() { final Path source = newTempDir(); final Path dest = newDirToClean(); Files.createTempFile(source, "foo", "bar"); assertThatThrownBy(() -> Files.copy(source, dest)) .isInstanceOf(DirectoryNotEmptyException.class); }
@Test public void copyIn2PathNull3() { assertThatThrownBy(() -> Files.copy(Files.newInputStream(Files.createTempFile("foo", "bar")), newTempDir().resolve("my_new_file.txt"), null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'options' should be not null!"); }
@Test public void copyIn2PathInvalidOption() { assertThatThrownBy(() -> Files.copy(Files.newInputStream(Files.createTempFile("foo", "bar")), newTempDir().resolve("my_new_file.txt"), NOFOLLOW_LINKS)) .isInstanceOf(UnsupportedOperationException.class) .hasMessage("NOFOLLOW_LINKS not supported"); }
@After public void tearDown() { Files.delete(path); Files.copy(pathCopy, path); Files.delete(pathCopy); }
@Test public void copyPath2OutNotExists() { assertThatThrownBy(() -> { try (OutputStream os = Files.newOutputStream(newTempDir().resolve("my_new_file.txt"))) { Files.copy(newTempDir().resolve("myfile.txt"), os); } }).isInstanceOf(NoSuchFileException.class); }
@Test public void copyFile() throws IOException { final Path dir = newTempDir(); final Path source = dir.resolve("temp.txt"); final Path dest = dir.resolve("result.txt"); try (final OutputStream stream = Files.newOutputStream(source)) { stream.write('a'); } Files.copy(source, dest); assertThat(dest.toFile()).exists(); assertThat(source.toFile()).exists(); assertThat(dest.toFile().length()).isEqualTo(source.toFile().length()); }
@Test public void copyDir() { final Path source = newTempDir(); final Path dest = newDirToClean(); assertThat(source.toFile()).exists(); assertThat(dest.toFile()).doesNotExist(); Files.copy(source, dest); assertThat(dest.toFile()).exists(); assertThat(source.toFile()).exists(); }