### Question:
IOUtils { public static void copy(InputStream in, OutputStream out) throws IOException { byte[] ab = new byte[4096]; int read; while ((read = in.read(ab)) > 0) { out.write(ab, 0, read); } } private  IOUtils(); static TemporaryPath tempFile(String prefix, String suffix); static Path createTempFile(String prefix, String suffix); static Path createTempDir(Path dir, String prefix); static TemporaryPath tempDir(String prefix); static Path createTempDir(String prefix); static boolean matches(Path p, String... filters); static void zipFile(ZipArchiveOutputStream zip, Path src, String name); static void zip(ZipArchiveOutputStream zip, Path srcDir, String... filters); static void zip(ZipArchiveOutputStream zip, String dstPrefix, Path srcDir, String... filters); static void unzip(InputStream in, Path targetDir, CopyOption... options); static void unzip(Path in, Path targetDir, CopyOption... options); static void unzip(Path in, Path targetDir, boolean skipExisting, CopyOption... options); static void unzip(Path in, Path targetDir, boolean skipExisting, FileVisitor visitor, CopyOption... options); static void copy(InputStream in, OutputStream out); static void copy(Path src, Path dst); static void copy(Path src, Path dst, CopyOption... options); static void copy(Path src, Path dst, String ignorePattern, CopyOption... options); static void copy(Path src, Path dst, String skipContents, FileVisitor visitor, CopyOption... options); static void copy(Path src, Path dst, List<String> skipContents, FileVisitor visitor, CopyOption... options); static List<String> grep(String pattern, byte[] ab); static List<String> grep(String pattern, InputStream in); static boolean deleteRecursively(Path p); static byte[] toByteArray(InputStream src); static void delete(File f); static final String TMP_DIR_KEY; static final Path TMP_DIR; }### Answer:
@Test public void testCopy() throws Exception { Path src = Files.createTempDirectory("test"); Path dst = Files.createTempDirectory("test"); Path nestedDir = src.resolve("a/b"); Files.createDirectories(nestedDir); Path srcFile = nestedDir.resolve("c.txt"); Files.createFile(srcFile); IOUtils.copy(src, dst); assertTrue(Files.exists(dst.resolve("a/b/c.txt"))); }
@Test public void testSymlinks() throws Exception { Path src = Files.createTempDirectory("test"); Path aFile = src.resolve("a"); Files.write(aFile, "hello".getBytes(), StandardOpenOption.CREATE); Path xDir = src.resolve("x"); Files.createDirectories(xDir); Path bLink = xDir.resolve("b"); Files.createSymbolicLink(bLink, aFile); Path dst = Files.createTempDirectory("test"); IOUtils.copy(src, dst); assertTrue(Files.isSymbolicLink(dst.resolve("x").resolve("b"))); assertTrue(Files.isRegularFile(dst.resolve("x").resolve("b"))); }
@Test public void testExternalSymlinks() throws Exception { Path src = Files.createTempDirectory("test"); Path link = src.resolve("a"); Path target = Paths.get("../../../etc/passwd"); Files.createSymbolicLink(link, target); Path dst = Files.createTempDirectory("test"); try { IOUtils.copy(src, dst); fail("should fail"); } catch (IOException e) { } }